Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
# under the License.

* text=auto eol=lf

# CLI fixtures include significant CRLF bytes inside quoted CSV fields.
cpp/test/tools/e2e/fixtures/** -text
cpp/test/tools/e2e/golden/** -text
9 changes: 9 additions & 0 deletions .github/workflows/unit-test-cpp-msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,12 @@ jobs:
-Dtsfile.dependency.source=BUNDLED \
-Dspotless.skip=true \
clean verify

- name: Upload CLI E2E failure results
if: failure()
uses: actions/upload-artifact@v7
with:
name: cli-e2e-${{ matrix.os }}-${{ strategy.job-index }}
path: cpp/target/build/test/cli-e2e-results/
if-no-files-found: ignore
retention-days: 14
9 changes: 9 additions & 0 deletions .github/workflows/unit-test-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,12 @@ jobs:
-Denable.lzma2=ON \
-Dtsfile.dependency.source=BUNDLED \
clean verify

- name: Upload CLI E2E failure results
if: failure()
uses: actions/upload-artifact@v7
with:
name: cli-e2e-${{ matrix.os }}-${{ strategy.job-index }}
path: cpp/target/build/test/cli-e2e-results/
if-no-files-found: ignore
retention-days: 14
31 changes: 31 additions & 0 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,34 @@ if(WIN32)
else()
gtest_discover_tests(TsFile_Test)
endif()

# The same file-driven CLI suite also runs against an installed executable.
# Keep test-data preparation and golden comparisons independent of libtsfile.
if (BUILD_TOOLS)
if (CMAKE_VERSION VERSION_LESS "3.12")
find_package(PythonInterp 3.9 REQUIRED)
set(TSFILE_E2E_PYTHON "${PYTHON_EXECUTABLE}")
else ()
find_package(Python3 3.9 COMPONENTS Interpreter REQUIRED)
set(TSFILE_E2E_PYTHON "${Python3_EXECUTABLE}")
endif ()
add_dependencies(TsFile_Test tsfile_cli)
add_test(NAME CliE2E
COMMAND "${TSFILE_E2E_PYTHON}"
"${CMAKE_CURRENT_SOURCE_DIR}/tools/e2e/run_cli_e2e.py"
--cli $<TARGET_FILE:tsfile_cli>
--expected-version "${TsFile_CPP_VERSION}"
--output-dir "${CMAKE_CURRENT_BINARY_DIR}/cli-e2e-results")
set_tests_properties(CliE2E PROPERTIES TIMEOUT 1800)
if (WIN32 AND TSFILE_BUILD_SHARED)
# The build-tree DLL lives in lib/<config>, separate from the CLI.
# Installed-package verification uses its own normal runtime setup.
string(REPLACE ";" "\\;" _TSFILE_E2E_SYSTEM_PATH "$ENV{PATH}")
set_tests_properties(CliE2E PROPERTIES ENVIRONMENT
"PATH=$<TARGET_FILE_DIR:tsfile>\\;${_TSFILE_E2E_SYSTEM_PATH}")
endif ()
add_test(NAME CliE2ERunnerTest
COMMAND "${TSFILE_E2E_PYTHON}" -m unittest discover
-s "${CMAKE_CURRENT_SOURCE_DIR}/tools/e2e"
-p test_runner.py)
endif ()
92 changes: 0 additions & 92 deletions cpp/test/tools/cli_args_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,72 +23,6 @@

#include <sstream>

#include "cli/run_cli.h"

TEST(RunCliTest, VersionFlagPrintsVersionAndReturnsOk) {
std::ostringstream out;
std::ostringstream err;
int code = tsfile_cli::run_cli({"--version"}, out, err);
EXPECT_EQ(code, 0);
EXPECT_NE(out.str().find("tsfile"), std::string::npos);
EXPECT_TRUE(err.str().empty());
}

TEST(RunCliTest, VersionMustAppearByItself) {
std::ostringstream out;
std::ostringstream err;
int code =
tsfile_cli::run_cli({"cat", "--version", "data.tsfile"}, out, err);
EXPECT_EQ(code, 1);
EXPECT_TRUE(out.str().empty());
EXPECT_NE(err.str().find("--version"), std::string::npos) << err.str();
}

TEST(RunCliTest, TopLevelHelpMustAppearByItself) {
std::ostringstream out;
std::ostringstream err;
int code = tsfile_cli::run_cli({"--help", "cat"}, out, err);
EXPECT_EQ(code, 1);
EXPECT_TRUE(out.str().empty());
EXPECT_NE(err.str().find("--help"), std::string::npos) << err.str();
}

TEST(RunCliTest, CommandHelpMustAppearByItself) {
std::ostringstream out;
std::ostringstream err;
int code = tsfile_cli::run_cli({"cat", "--help", "data.tsfile"}, out, err);
EXPECT_EQ(code, 1);
EXPECT_TRUE(out.str().empty());
EXPECT_NE(err.str().find("--help"), std::string::npos) << err.str();
}

TEST(RunCliTest, NoArgsPrintsUsageToErrAndReturnsUsageError) {
std::ostringstream out;
std::ostringstream err;
int code = tsfile_cli::run_cli({}, out, err);
EXPECT_EQ(code, 1);
EXPECT_NE(err.str().find("Usage"), std::string::npos);
}

TEST(RunCliTest, UnknownCommandIsUsageError) {
std::ostringstream out;
std::ostringstream err;
int code = tsfile_cli::run_cli({"frobnicate", "x.tsfile"}, out, err);
EXPECT_EQ(code, 1);
EXPECT_NE(err.str().find("Unknown command"), std::string::npos);
}

TEST(RunCliTest, LeadingOptionBeforeCommandIsClearError) {
std::ostringstream out;
std::ostringstream err;
int code =
tsfile_cli::run_cli({"-f", "ndjson", "meta", "data.tsfile"}, out, err);
EXPECT_EQ(code, 1);
EXPECT_NE(err.str().find("command must come before options"),
std::string::npos)
<< err.str();
}

TEST(ParseArgsTest, CommandAndFilePositional) {
auto p = tsfile_cli::parse_args({"ls", "data.tsfile"});
EXPECT_TRUE(p.error.empty());
Expand Down Expand Up @@ -179,29 +113,3 @@ TEST(ParseArgsTest, StdinFlagParsed) {
EXPECT_EQ(p.file, "-");
EXPECT_TRUE(p.input_set);
}

TEST(RunCliTest, SelectIsNoLongerKnownCommand) {
std::ostringstream out;
std::ostringstream err;
int code = tsfile_cli::run_cli({"select", "x.tsfile"}, out, err);
EXPECT_EQ(code, 1);
EXPECT_NE(err.str().find("Unknown command"), std::string::npos);
}

TEST(RunCliTest, SeedOnCatIsUsageError) {
std::ostringstream out;
std::ostringstream err;
int code =
tsfile_cli::run_cli({"cat", "--seed", "7", "x.tsfile"}, out, err);
EXPECT_EQ(code, 1);
EXPECT_NE(err.str().find("--seed is not supported"), std::string::npos);
}

TEST(RunCliTest, SampleIsUnknownCommand) {
std::ostringstream out;
std::ostringstream err;
int code =
tsfile_cli::run_cli({"sample", "--offset", "2", "x.tsfile"}, out, err);
EXPECT_EQ(code, 1);
EXPECT_NE(err.str().find("Unknown command"), std::string::npos);
}
Loading
Loading