From e64bba7ef61c8ee623b17504198398c93758dce4 Mon Sep 17 00:00:00 2001 From: Ttibsi Date: Mon, 2 Feb 2026 08:28:57 +0000 Subject: [PATCH 1/7] register tests separate to execution --- src/main.cpp | 22 +++++++++++----------- src/tests/test_willow.h | 11 ++++++----- src/willow/willow.h | 14 ++++++++++---- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5b15020..d7a1ac6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,15 +7,15 @@ auto main() -> int { Willow::PreCommitReporter reporter = {}; - return Willow::runTests( - { - {"test_runTests", test_runTests}, - {"test_toString", test_toString}, - {"test_Test_alert", test_Test_alert}, - {"test_Test_Operator()", test_Test_Operator}, - {"PreCommitReporter::print", TestPreCommitReporter::test_print}, - {"PreCommitReporter::cleanup", TestPreCommitReporter::test_cleanup}, - {"PreCommitReporter::highlight", TestPreCommitReporter::test_highlight}, - }, - reporter); + Willow::registerTests({ + {"test_runTests", test_runTests}, + {"test_toString", test_toString}, + {"test_Test_alert", test_Test_alert}, + {"test_Test_Operator()", test_Test_Operator}, + {"PreCommitReporter::print", TestPreCommitReporter::test_print}, + {"PreCommitReporter::cleanup", TestPreCommitReporter::test_cleanup}, + {"PreCommitReporter::highlight", TestPreCommitReporter::test_highlight}, + }); + + return Willow::runTests(reporter); } diff --git a/src/tests/test_willow.h b/src/tests/test_willow.h index 5e3fdaf..306c4db 100644 --- a/src/tests/test_willow.h +++ b/src/tests/test_willow.h @@ -12,11 +12,12 @@ namespace FixtureFuncs { constexpr auto test_runTests([[maybe_unused]] Willow::Test* test) -> int { SilentReporter r = {}; - int ret = Willow::runTests( - {{"pass", FixtureFuncs::pass}, - {"fail", FixtureFuncs::fail}, - {"skip", FixtureFuncs::fail, Willow::Status::Skip}}, - r); + Willow::registerTests({ + {"pass", FixtureFuncs::pass}, + {"fail", FixtureFuncs::fail}, + {"skip", FixtureFuncs::fail, Willow::Status::Skip} + }); + int ret = Willow::runTests(r); return !(ret == 1); } diff --git a/src/willow/willow.h b/src/willow/willow.h index 787ec96..9900717 100644 --- a/src/willow/willow.h +++ b/src/willow/willow.h @@ -7,8 +7,14 @@ #include "test.h" namespace Willow { - constexpr auto runTests(std::vector tests, Reporter& reporter) -> int { - for (auto&& test : tests) { + std::vector global_tests = {}; + + constexpr auto registerTests(std::vector tests) -> void { + global_tests = tests; + } + + constexpr auto runTests(Reporter& reporter) -> int { + for (auto&& test : global_tests) { if (test.status == Status::Skip) { continue; } @@ -22,10 +28,10 @@ namespace Willow { test.status = Status::Pass; } - std::for_each(tests.begin(), tests.end(), [&reporter](Test& t) { reporter.print(t); }); + std::for_each(global_tests.begin(), global_tests.end(), [&reporter](Test& t) { reporter.print(t); }); reporter.cleanup(); - return int32_t(std::count_if(tests.begin(), tests.end(), [](Test& t) { + return int32_t(std::count_if(global_tests.begin(), global_tests.end(), [](Test& t) { return t.status == Status::Fail; })); } From 642c1f33bd6dbf0cadee92f168a0db750d0408d7 Mon Sep 17 00:00:00 2001 From: Ttibsi Date: Mon, 2 Feb 2026 09:26:51 +0000 Subject: [PATCH 2/7] Resolve crashes of all tests --- src/main.cpp | 7 ++++++- src/tests/test_willow.h | 12 +++++++----- src/willow/willow.h | 27 +++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d7a1ac6..368b637 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,12 @@ +#include + #include "tests/test_reporters.h" #include "tests/test_test.h" #include "tests/test_willow.h" #include "willow/reporters.h" #include "willow/willow.h" -auto main() -> int { +auto main(int argc, char* argv[]) -> int { Willow::PreCommitReporter reporter = {}; Willow::registerTests({ @@ -17,5 +19,8 @@ auto main() -> int { {"PreCommitReporter::highlight", TestPreCommitReporter::test_highlight}, }); + if (argc > 1) { + return Willow::runSingleTest(std::string(argv[1]), reporter); + } return Willow::runTests(reporter); } diff --git a/src/tests/test_willow.h b/src/tests/test_willow.h index 306c4db..afb3aa7 100644 --- a/src/tests/test_willow.h +++ b/src/tests/test_willow.h @@ -12,12 +12,14 @@ namespace FixtureFuncs { constexpr auto test_runTests([[maybe_unused]] Willow::Test* test) -> int { SilentReporter r = {}; - Willow::registerTests({ - {"pass", FixtureFuncs::pass}, - {"fail", FixtureFuncs::fail}, - {"skip", FixtureFuncs::fail, Willow::Status::Skip} - }); + std::vector storage = Willow::global_tests; + + Willow::registerTests( + {{"pass", FixtureFuncs::pass}, + {"fail", FixtureFuncs::fail}, + {"skip", FixtureFuncs::fail, Willow::Status::Skip}}); int ret = Willow::runTests(r); + Willow::global_tests = storage; return !(ret == 1); } diff --git a/src/willow/willow.h b/src/willow/willow.h index 9900717..cce830a 100644 --- a/src/willow/willow.h +++ b/src/willow/willow.h @@ -7,7 +7,7 @@ #include "test.h" namespace Willow { - std::vector global_tests = {}; + inline std::vector global_tests = {}; constexpr auto registerTests(std::vector tests) -> void { global_tests = tests; @@ -28,7 +28,8 @@ namespace Willow { test.status = Status::Pass; } - std::for_each(global_tests.begin(), global_tests.end(), [&reporter](Test& t) { reporter.print(t); }); + std::for_each( + global_tests.begin(), global_tests.end(), [&reporter](Test& t) { reporter.print(t); }); reporter.cleanup(); return int32_t(std::count_if(global_tests.begin(), global_tests.end(), [](Test& t) { @@ -36,6 +37,28 @@ namespace Willow { })); } + constexpr auto runSingleTest(std::string_view test_name, Reporter& reporter) -> int { + auto it = std::find_if(global_tests.begin(), global_tests.end(), [test_name](Test& t) { + return t.name == test_name; + }); + if (it == global_tests.end()) { + return 1; + } + + Test& exec = *it; + if (exec.status == Status::Skip) { + return 2; + } + + exec(); + if (exec.retcode != 0) { + exec.status = Status::Fail; + } + reporter.print(exec); + + return exec.retcode; + } + } // namespace Willow #endif // WILLOW_H From 55e6ff5df8e040db30df849e84cbe06ffd01308b Mon Sep 17 00:00:00 2001 From: Ttibsi Date: Mon, 2 Feb 2026 09:39:37 +0000 Subject: [PATCH 3/7] Select a single test to run --- src/willow/willow.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/willow/willow.h b/src/willow/willow.h index cce830a..a950fe8 100644 --- a/src/willow/willow.h +++ b/src/willow/willow.h @@ -38,7 +38,7 @@ namespace Willow { } constexpr auto runSingleTest(std::string_view test_name, Reporter& reporter) -> int { - auto it = std::find_if(global_tests.begin(), global_tests.end(), [test_name](Test& t) { + auto it = std::find_if(global_tests.begin(), global_tests.end(), [&test_name](Test& t) { return t.name == test_name; }); if (it == global_tests.end()) { @@ -51,9 +51,7 @@ namespace Willow { } exec(); - if (exec.retcode != 0) { - exec.status = Status::Fail; - } + exec.status = (exec.retcode == 0 ? Status::Pass : Status::Fail); reporter.print(exec); return exec.retcode; From db431e96f297f0a7260751cf1b8767e5a7c33140 Mon Sep 17 00:00:00 2001 From: Ttibsi Date: Mon, 2 Feb 2026 09:45:42 +0000 Subject: [PATCH 4/7] Allow for fuzzy searching --- src/willow/willow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/willow/willow.h b/src/willow/willow.h index a950fe8..1ca6f2b 100644 --- a/src/willow/willow.h +++ b/src/willow/willow.h @@ -39,7 +39,7 @@ namespace Willow { constexpr auto runSingleTest(std::string_view test_name, Reporter& reporter) -> int { auto it = std::find_if(global_tests.begin(), global_tests.end(), [&test_name](Test& t) { - return t.name == test_name; + return t.name.contains(test_name); }); if (it == global_tests.end()) { return 1; From 4eca41c2ff55087a79530f9136cafc8d1013231b Mon Sep 17 00:00:00 2001 From: Ttibsi Date: Mon, 2 Feb 2026 09:48:50 +0000 Subject: [PATCH 5/7] Update readme --- .gitignore | 1 + CHANGELOG.md | 2 ++ CMakeLists.txt | 2 -- README.md | 13 ++++++++----- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index ec9da65..10f2747 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ iris.log build/ .gdb_history .cache +core diff --git a/CHANGELOG.md b/CHANGELOG.md index 785ecc2..0dca844 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +### main/HEAD +* Add `Willow::runSingleTest()` function to select a test on the command line ### v0.0.1 - 03/11/25 * Initial repo setup diff --git a/CMakeLists.txt b/CMakeLists.txt index b47a6af..7d32bf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,6 @@ project(willow-test LANGUAGES CXX) add_subdirectory(src/willow) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - message("LOCAL BUILD ONLY") - set(CMAKE_CXX_COMPILER "/usr/bin/clang++") set(CMAKE_CXX_STANDARD 23) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/README.md b/README.md index 53922d4..01f0cd9 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A unit testing library for modern c++23 # How to use Currently, willow only supports CMake for distribution, although if you know -what you're doing, feel free to clone the repo and do what you need yourself. +what you're doing, feel free to clone the repo and build it yourself ```cmake set(CMAKE_CXX_STANDARD 23) @@ -45,13 +45,16 @@ auto main() -> int { // are available Willow::DefaultReporter reporter = {}; - // Your executable will exit with a return code displaying the number of - // failed tests - return Willow::runTests({ + // Register each function to test + Willow::registerTests({ // Each test function is given a name to display as output. you can also // mark tests for skipping {"addition test", test_add}, {"skipped test", test_add, Willow::Status::Skip}, - }, reporter); + }); + + // Your executable will exit with a return code displaying the number of + // failed tests + return Willow::runTests(reporter); } ``` From a9b8a1abb6e94a5e7fb326ada7dbe7b67415ac6b Mon Sep 17 00:00:00 2001 From: Ttibsi Date: Mon, 2 Feb 2026 11:10:52 +0000 Subject: [PATCH 6/7] Remove unneccesary include --- src/main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 368b637..13a3f1f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,3 @@ -#include - #include "tests/test_reporters.h" #include "tests/test_test.h" #include "tests/test_willow.h" From 6760a24755bf0fb8c05edb1f40302ff29dea296a Mon Sep 17 00:00:00 2001 From: Ttibsi Date: Mon, 2 Feb 2026 11:14:49 +0000 Subject: [PATCH 7/7] g++ in CI --- .github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f68e8f7..19913d1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,6 +13,8 @@ jobs: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - - run: sudo apt-get install clang-19 -y + - run: sudo apt-get install g++-14 -y - run: cmake -S . -B build && cmake --build build + env: + CXX: /usr/bin/g++-14 - run: ./build/willow_test