Run all C++ tests from a single executable (#3582)

This commit is contained in:
Dustin J. Mitchell
2024-08-11 20:20:17 -04:00
committed by GitHub
parent 4ff63a7960
commit c719cce4f1
44 changed files with 138 additions and 94 deletions

View File

@@ -17,7 +17,7 @@ jobs:
run: cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS=--coverage run: cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS=--coverage
- name: Build project - name: Build project
run: cmake --build build --target build_tests run: cmake --build build --target test_runner --target task_executable
- name: Test project - name: Test project
run: ctest --test-dir build -j 8 --output-on-failure run: ctest --test-dir build -j 8 --output-on-failure

24
Cargo.lock generated
View File

@@ -1141,6 +1141,21 @@ dependencies = [
"sct", "sct",
] ]
[[package]]
name = "rustls"
version = "0.23.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044"
dependencies = [
"log",
"once_cell",
"ring",
"rustls-pki-types",
"rustls-webpki 0.102.6",
"subtle",
"zeroize",
]
[[package]] [[package]]
name = "rustls-pemfile" name = "rustls-pemfile"
version = "1.0.4" version = "1.0.4"
@@ -1807,6 +1822,15 @@ dependencies = [
"rustls-pki-types", "rustls-pki-types",
] ]
[[package]]
name = "winapi-util"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "windows-core" name = "windows-core"
version = "0.52.0" version = "0.52.0"

View File

@@ -52,9 +52,9 @@ cmake --build build-clang
## Run the Test Suite: ## Run the Test Suite:
For running the test suite [ctest](https://cmake.org/cmake/help/latest/manual/ctest.1.html) is used. For running the test suite [ctest](https://cmake.org/cmake/help/latest/manual/ctest.1.html) is used.
Before one can run the test suite the `task_executable` must be built. Before one can run the test suite the `task_executable` must be built.
After that also the `build_tests` target must be build, which can be done over: After that also the `test_runner` target must be build, which can be done over:
```sh ```sh
cmake --build build --target build_tests cmake --build build --target test_runner
``` ```
Again you may also use the `-j <number-of-jobs>` option for parallel builds. Again you may also use the `-j <number-of-jobs>` option for parallel builds.

View File

@@ -1,5 +1,7 @@
cmake_minimum_required (VERSION 3.22) cmake_minimum_required (VERSION 3.22)
# -- C++ tests
include_directories (${CMAKE_SOURCE_DIR} include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/commands ${CMAKE_SOURCE_DIR}/src/commands
@@ -8,56 +10,64 @@ include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/test ${CMAKE_SOURCE_DIR}/test
${TASK_INCLUDE_DIRS}) ${TASK_INCLUDE_DIRS})
set (test_SRCS # All C++ test files. Note that the portion before `.cpp` must be a valid,
col.test.cpp # unique C++ identifier.
dom.test.cpp set(test_SRCS
eval.test.cpp col_test.cpp
lexer.test.cpp dom_test.cpp
t.test.cpp eval_test.cpp
tw-2689.test.cpp lexer_test.cpp
tdb2.test.cpp t_test.cpp
tc.test.cpp tw_2689_test.cpp
util.test.cpp tdb2_test.cpp
variant_add.test.cpp tc_cpp_test.cpp
variant_and.test.cpp util_test.cpp
variant_cast.test.cpp variant_add_test.cpp
variant_divide.test.cpp variant_and_test.cpp
variant_equal.test.cpp variant_cast_test.cpp
variant_exp.test.cpp variant_divide_test.cpp
variant_gt.test.cpp variant_equal_test.cpp
variant_gte.test.cpp variant_exp_test.cpp
variant_inequal.test.cpp variant_gt_test.cpp
variant_lt.test.cpp variant_gte_test.cpp
variant_lte.test.cpp variant_inequal_test.cpp
variant_match.test.cpp variant_lt_test.cpp
variant_math.test.cpp variant_lte_test.cpp
variant_modulo.test.cpp variant_match_test.cpp
variant_multiply.test.cpp variant_math_test.cpp
variant_nomatch.test.cpp variant_modulo_test.cpp
variant_not.test.cpp variant_multiply_test.cpp
variant_or.test.cpp variant_nomatch_test.cpp
variant_partial.test.cpp variant_not_test.cpp
variant_subtract.test.cpp variant_or_test.cpp
variant_xor.test.cpp variant_partial_test.cpp
view.test.cpp variant_subtract_test.cpp
variant_xor_test.cpp
view_test.cpp
) )
add_custom_target (build_tests DEPENDS ${test_SRCS} # Build `test_runner` containing all CPP tests, linked once.
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test) create_test_sourcelist (cpp_test_SRCS cpp_tests.cpp ${test_SRCS})
add_executable(test_runner
test.cpp
${cpp_test_SRCS}
)
target_link_libraries (test_runner task commands columns libshared task commands columns libshared task commands columns libshared ${TASK_LIBRARIES})
if (DARWIN)
target_link_libraries (test_runner "-framework CoreFoundation -framework Security -framework SystemConfiguration")
endif (DARWIN)
foreach (src_FILE ${test_SRCS}) foreach (test_FILE ${test_SRCS})
add_executable (${src_FILE} ${src_FILE} test.cpp) get_filename_component (test_NAME ${test_FILE} NAME_WE)
target_link_libraries (${src_FILE} task commands columns libshared task commands columns libshared task commands columns libshared ${TASK_LIBRARIES}) # Tell the source file what its own name is
add_dependencies (${src_FILE} task_executable) set_source_files_properties(${test_FILE} PROPERTIES COMPILE_FLAGS -DTEST_NAME=${test_NAME})
if (DARWIN) add_test(NAME ${test_FILE}
target_link_libraries (${src_FILE} "-framework CoreFoundation -framework Security -framework SystemConfiguration") COMMAND test_runner ${test_NAME}
endif (DARWIN)
add_test(NAME ${src_FILE}
COMMAND ${src_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
) )
endforeach (src_FILE) endforeach (test_FILE)
# -- Python tests
add_subdirectory(basetest) add_subdirectory(basetest)
add_subdirectory(simpletap) add_subdirectory(simpletap)

View File

@@ -1,7 +1,7 @@
## Running Tests ## Running Tests
Do this to run all tests: Do this to run all tests:
```shell ```shell
cmake --build build --target build_tests cmake --build build --target test_runner --target task_executable
ctest --test-dir build ctest --test-dir build
``` ```

View File

@@ -33,7 +33,7 @@
#include <test.h> #include <test.h>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest test(12); UnitTest test(12);
// Ensure environment has no influence. // Ensure environment has no influence.

View File

@@ -26,5 +26,5 @@ RUN cmake --install build
RUN task --version RUN task --version
# Setup tests # Setup tests
RUN cmake --build build --target build_tests -j 8 RUN cmake --build build --target test_runner -j 8
CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed

View File

@@ -27,5 +27,5 @@ RUN cmake --install build
RUN task --version RUN task --version
# Setup tests # Setup tests
RUN cmake --build build --target build_tests -j 8 RUN cmake --build build --target test_runner -j 8
CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed

View File

@@ -27,5 +27,5 @@ RUN cmake --install build
RUN task --version RUN task --version
# Setup tests # Setup tests
RUN cmake --build build --target build_tests -j 8 RUN cmake --build build --target test_runner -j 8
CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed

View File

@@ -26,5 +26,5 @@ RUN cmake --install build
RUN task --version RUN task --version
# Setup tests # Setup tests
RUN cmake --build build --target build_tests -j 8 RUN cmake --build build --target test_runner -j 8
CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed

View File

@@ -26,5 +26,5 @@ RUN cmake --install build
RUN task --version RUN task --version
# Setup tests # Setup tests
RUN cmake --build build --target build_tests -j 8 RUN cmake --build build --target test_runner -j 8
CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed

View File

@@ -25,5 +25,5 @@ RUN cmake --install build
RUN task --version RUN task --version
# Setup tests # Setup tests
RUN cmake --build build --target build_tests -j 8 RUN cmake --build build --target test_runner -j 8
CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed

View File

@@ -34,5 +34,5 @@ RUN cmake --install build
RUN task --version RUN task --version
# Setup tests # Setup tests
RUN cmake --build build --target build_tests -j 8 RUN cmake --build build --target test_runner -j 8
CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed

View File

@@ -27,5 +27,5 @@ RUN cmake --install build
RUN task --version RUN task --version
# Setup tests # Setup tests
RUN cmake --build build --target build_tests -j 8 RUN cmake --build build --target test_runner -j 8
CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed CMD ctest --test-dir build -j 8 --output-on-failure --rerun-failed

View File

@@ -31,6 +31,8 @@
#include <Variant.h> #include <Variant.h>
#include <test.h> #include <test.h>
namespace {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool providerString(const std::string& path, Variant& var) { bool providerString(const std::string& path, Variant& var) {
if (path == "name") { if (path == "name") {
@@ -50,8 +52,10 @@ bool providerString(const std::string& path, Variant& var) {
return false; return false;
} }
} // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(12); UnitTest t(12);
DOM dom; DOM dom;

View File

@@ -31,6 +31,8 @@
#include <Eval.h> #include <Eval.h>
#include <test.h> #include <test.h>
namespace {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// A few hard-coded symbols. // A few hard-coded symbols.
bool get(const std::string& name, Variant& value) { bool get(const std::string& name, Variant& value) {
@@ -42,8 +44,10 @@ bool get(const std::string& name, Variant& value) {
return true; return true;
} }
} // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(52); UnitTest t(52);
Context context; Context context;
Context::setContext(&context); Context::setContext(&context);

View File

@@ -37,7 +37,7 @@
#include <vector> #include <vector>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
#ifdef PRODUCT_TASKWARRIOR #ifdef PRODUCT_TASKWARRIOR
UnitTest t(1255); UnitTest t(1255);
#else #else

View File

@@ -32,7 +32,7 @@
#include <test.h> #include <test.h>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest test(48); UnitTest test(48);
Context context; Context context;
Context::setContext(&context); Context::setContext(&context);

View File

@@ -41,7 +41,7 @@ std::string uuid2str(tc::Uuid uuid) { return static_cast<std::string>(uuid.to_st
// Tests for the basic cxxbridge functionality. This focuses on the methods with // Tests for the basic cxxbridge functionality. This focuses on the methods with
// complex cxxbridge implementations, rather than those with complex Rust // complex cxxbridge implementations, rather than those with complex Rust
// implementations but simple APIs, like sync. // implementations but simple APIs, like sync.
int main(int, char **) { int TEST_NAME(int, char **) {
UnitTest t; UnitTest t;
std::string str; std::string str;

View File

@@ -34,7 +34,7 @@
#include <iostream> #include <iostream>
Context context; namespace {
void cleardb() { void cleardb() {
// Remove any residual test files. // Remove any residual test files.
@@ -42,8 +42,10 @@ void cleardb() {
unlink("./taskchampion.sqlite3"); unlink("./taskchampion.sqlite3");
} }
} // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(12); UnitTest t(12);
Context context; Context context;
Context::setContext(&context); Context::setContext(&context);

View File

@@ -34,7 +34,7 @@
#include <test.h> #include <test.h>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest test(12); UnitTest test(12);
// Ensure environment has no influence. // Ensure environment has no influence.

View File

@@ -35,7 +35,7 @@
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(19); UnitTest t(19);
Context context; Context context;
Context::setContext(&context); Context::setContext(&context);

View File

@@ -35,7 +35,7 @@
#define EPSILON 0.001 #define EPSILON 0.001
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(80); UnitTest t(80);
Variant v0(true); Variant v0(true);

View File

@@ -33,7 +33,7 @@
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(76); UnitTest t(76);
Variant v0(true); Variant v0(true);

View File

@@ -35,7 +35,7 @@
#define EPSILON 0.001 #define EPSILON 0.001
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(81); UnitTest t(81);
time_t now = time(nullptr); time_t now = time(nullptr);

View File

@@ -35,7 +35,7 @@
#define EPSILON 0.0001 #define EPSILON 0.0001
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(44); UnitTest t(44);
Variant v0(true); Variant v0(true);

View File

@@ -33,7 +33,7 @@
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(72); UnitTest t(72);
Variant v0(true); Variant v0(true);

View File

@@ -33,7 +33,7 @@
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(38); UnitTest t(38);
Variant v0(true); Variant v0(true);

View File

@@ -33,7 +33,7 @@
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(72); UnitTest t(72);
Variant v0(true); Variant v0(true);

View File

@@ -33,7 +33,7 @@
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(72); UnitTest t(72);
Variant v0(true); Variant v0(true);

View File

@@ -33,7 +33,7 @@
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(72); UnitTest t(72);
Variant v0(true); Variant v0(true);

View File

@@ -33,7 +33,7 @@
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(72); UnitTest t(72);
Variant v0(true); Variant v0(true);

View File

@@ -33,7 +33,7 @@
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(72); UnitTest t(72);
Variant v0(true); Variant v0(true);

View File

@@ -33,12 +33,12 @@
#include <iostream> #include <iostream>
Task task;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(120); UnitTest t(120);
Task task;
Variant vs0("untrue"); // ~ true Variant vs0("untrue"); // ~ true
Variant vs1(8421); // ~ 42 Variant vs1(8421); // ~ 42
Variant vs2(3.14159); // ~ 3.14 Variant vs2(3.14159); // ~ 3.14

View File

@@ -35,7 +35,7 @@
#define EPSILON 0.001 #define EPSILON 0.001
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(1); UnitTest t(1);
Variant v0(10.0); Variant v0(10.0);

View File

@@ -35,7 +35,7 @@
#define EPSILON 0.0001 #define EPSILON 0.0001
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(40); UnitTest t(40);
Variant v0(true); Variant v0(true);

View File

@@ -35,7 +35,7 @@
#define EPSILON 0.0001 #define EPSILON 0.0001
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(54); UnitTest t(54);
Variant v0(true); Variant v0(true);

View File

@@ -33,12 +33,12 @@
#include <iostream> #include <iostream>
Task task;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(120); UnitTest t(120);
Task task;
Variant vs0("untrue"); // !~ true Variant vs0("untrue"); // !~ true
Variant vs1(8421); // !~ 42 Variant vs1(8421); // !~ 42
Variant vs2(3.14159); // !~ 3.14 Variant vs2(3.14159); // !~ 3.14

View File

@@ -33,7 +33,7 @@
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(14); UnitTest t(14);
Variant v0(true); Variant v0(true);

View File

@@ -33,7 +33,7 @@
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(76); UnitTest t(76);
Variant v0(true); Variant v0(true);

View File

@@ -33,7 +33,7 @@
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(72); UnitTest t(72);
Variant v0(true); Variant v0(true);

View File

@@ -35,7 +35,7 @@
#define EPSILON 0.001 #define EPSILON 0.001
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(55); UnitTest t(55);
Variant v0(true); Variant v0(true);

View File

@@ -33,7 +33,7 @@
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(76); UnitTest t(76);
Variant v0(true); Variant v0(true);

View File

@@ -43,7 +43,7 @@ Context context;
extern std::string configurationDefaults; extern std::string configurationDefaults;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main(int, char**) { int TEST_NAME(int, char**) {
UnitTest t(1); UnitTest t(1);
Context context; Context context;
Context::setContext(&context); Context::setContext(&context);