diff --git a/cmake/xo_alloc2Config.cmake.in b/cmake/xo_alloc2Config.cmake.in index e226be2e..417bfe11 100644 --- a/cmake/xo_alloc2Config.cmake.in +++ b/cmake/xo_alloc2Config.cmake.in @@ -1,9 +1,10 @@ @PACKAGE_INIT@ include(CMakeFindDependencyMacro) -#find_dependency(indentlog) find_dependency(xo_arena) find_dependency(xo_facet) +find_dependency(subsys) +find_dependency(indentlog) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Share.cmake") check_required_components("@PROJECT_NAME@") diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index 2dec2979..f7af4ff2 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -4,7 +4,6 @@ set(UTEST_EXE utest.alloc2) set(UTEST_SRCS alloc2_utest_main.cpp - TestUtil.cpp objectmodel.test.cpp arena.test.cpp IAllocator_Any.test.cpp @@ -20,10 +19,12 @@ set(UTEST_SRCS if (ENABLE_TESTING) xo_add_utest_executable(${UTEST_EXE} ${UTEST_SRCS}) xo_self_dependency(${UTEST_EXE} xo_alloc2) + xo_dependency(${UTEST_EXE} xo_testutil) xo_headeronly_dependency(${UTEST_EXE} randomgen) xo_headeronly_dependency(${UTEST_EXE} indentlog) xo_headeronly_dependency(${UTEST_EXE} xo_facet) xo_external_target_dependency(${UTEST_EXE} Catch2 Catch2::Catch2) + xo_external_target_dependency(${UTEST_EXE} CLI11 CLI11::CLI11) endif() # end CMakeLists.txt diff --git a/utest/DArenaIterator.test.cpp b/utest/DArenaIterator.test.cpp index a3e95d96..00f22bbe 100644 --- a/utest/DArenaIterator.test.cpp +++ b/utest/DArenaIterator.test.cpp @@ -3,7 +3,7 @@ * @author Roland Conybeare, Dec 2025 **/ -#include "TestUtil.hpp" +#include #include #include #include diff --git a/utest/Generation.test.cpp b/utest/Generation.test.cpp index 6507e19b..dbfe3f52 100644 --- a/utest/Generation.test.cpp +++ b/utest/Generation.test.cpp @@ -3,7 +3,7 @@ * @author Roland Conybeare, May 2026 **/ -#include "TestUtil.hpp" +#include #include "Generation.hpp" #include diff --git a/utest/IAllocator_Any.test.cpp b/utest/IAllocator_Any.test.cpp index 68d510ef..020b8bca 100644 --- a/utest/IAllocator_Any.test.cpp +++ b/utest/IAllocator_Any.test.cpp @@ -3,7 +3,7 @@ * @author Roland Conybeare, May 2026 **/ -#include "TestUtil.hpp" +#include #include #include #include diff --git a/utest/ResourceVisitor.test.cpp b/utest/ResourceVisitor.test.cpp index 49c0f553..7d0df87f 100644 --- a/utest/ResourceVisitor.test.cpp +++ b/utest/ResourceVisitor.test.cpp @@ -3,7 +3,7 @@ * @author Roland Conybeare, May 2026 **/ -#include "TestUtil.hpp" +#include #include #include diff --git a/utest/Role.test.cpp b/utest/Role.test.cpp index a4c38d29..f4db9cf5 100644 --- a/utest/Role.test.cpp +++ b/utest/Role.test.cpp @@ -3,7 +3,7 @@ * @author Roland Conybeare, May 2026 **/ -#include "TestUtil.hpp" +#include #include "role.hpp" #include diff --git a/utest/TestUtil.cpp b/utest/TestUtil.cpp deleted file mode 100644 index c52a5d79..00000000 --- a/utest/TestUtil.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/** @file TestUtil.cpp - * - * @author Roland Conybeare, May 2026 - **/ - -#include "TestUtil.hpp" -#include - -namespace xo { - UtestConfig * - UtestConfig::instance() { - static UtestConfig s_instance; - - return &s_instance; - }; - - scope - Utest::ut_scope() { - return scope(XO_DEBUG(UtestConfig::instance()->debug_flag()), - xtag("name", Catch::getResultCapture().getCurrentTestName())); - } -} - -/* end TestUtil.cpp */ diff --git a/utest/TestUtil.hpp b/utest/TestUtil.hpp deleted file mode 100644 index 20253bb6..00000000 --- a/utest/TestUtil.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/** @file TestUtil.hpp - * - * @author Roland Conybeare, May 2026 - **/ - -#pragma once - -#include - -namespace xo { - - /** unit-test configuration here - * - * TODO: promote to its own library, along with UtestListener - **/ - struct UtestConfig { - bool debug_flag() const { return debug_flag_; } - - /** announce each test using catch2's listener api **/ - bool announce_flag_ = false; - /** enable debug output for all (!) tests **/ - bool debug_flag_ = false; - - static UtestConfig * instance(); - }; - - /** RAII logging for catch unit tests - * - * Use: - * TEST_CASE(name, tags, ..) - * { - * scope log = Utest::ut_scope(); - * - * ... - * log && log(xtag("foo", ...)); - * } - **/ - struct Utest { - static scope ut_scope(); - }; - -} /*namespace xo*/ - -/* end TestUtil.hpp */ diff --git a/utest/VisitReason.test.cpp b/utest/VisitReason.test.cpp index 6fccac80..2b50159d 100644 --- a/utest/VisitReason.test.cpp +++ b/utest/VisitReason.test.cpp @@ -3,7 +3,7 @@ * @author Roland Conybeare, May 2026 **/ -#include "TestUtil.hpp" +#include #include #include diff --git a/utest/alloc2_utest_main.cpp b/utest/alloc2_utest_main.cpp index d907b0d9..4ec10b7c 100644 --- a/utest/alloc2_utest_main.cpp +++ b/utest/alloc2_utest_main.cpp @@ -1,100 +1,18 @@ /* file alloc2_utest_main.cpp */ -#include "TestUtil.hpp" -#include -#include -#include +#define CATCH_CONFIG_RUNNER // before UtestListener.hpp -#define CATCH_CONFIG_RUNNER -#include +#include +#include namespace xo { - - struct UtestListener : Catch::TestEventListenerBase { - using TestEventListenerBase::TestEventListenerBase; - - // TestCasweInfo members: .name, .className, .description, .tags, lineInfo {.file, .line} - virtual void testCaseStarting(const Catch::TestCaseInfo & info) override { - using std::cerr; - using std::endl; - - // preamble - - if (UtestConfig::instance()->announce_flag_) { - cerr << "Starting unit test: " - << "[" << info.name << "]" - << " at " - << "[" << info.lineInfo.file << ":" << info.lineInfo.line << "]" - << endl; - } - } - - virtual void testCaseEnded(const Catch::TestCaseStats & stats) override { - // postamble - } - - // also sectionStarting / sectionEnded - - }; - CATCH_REGISTER_LISTENER(UtestListener); } int main(int argc, char* argv[]) { - using xo::UtestConfig; - using xo::scope; - using xo::xtag; - - using std::cout; - using std::cerr; - using std::endl; - - //cerr << xtag("cli11", CLI11_VERSION) << endl; // version 2.5.0 - - CLI::App app{"utest.alloc2: xo-alloc2 unit tests"}; - app.set_help_flag(); // disable default help impl, see below - { - app.add_flag("--debug", - UtestConfig::instance()->debug_flag_, - "enable debug logging (for all tests)"); - app.add_flag("--announce", - UtestConfig::instance()->announce_flag_, - "announce each test via UtestListener"); - } - bool help_flag = false; - { - app.add_flag("--help,-h,-?", help_flag, "print this help message and exit"); - } - - app.allow_extras(); - CLI11_PARSE(app, argc, argv); - - std::vector argv2 = {argv[0]}; - - if (help_flag) { - // actual help impl, falls through to Session below - - cout << "utest.alloc2 options" << endl; - cout << app.help() << endl; - cout << "catch2 options" << endl; - - argv2.push_back("--help"); - } else { - // keep program name - for (auto & x : app.remaining()) - argv2.push_back(x.c_str()); - - using xo::Subsystem; - Subsystem::initialize_all(); - - } - - scope log(XO_DEBUG(UtestConfig::instance()->debug_flag()), "start catch2 session"); - - // run catch2's test session / help - return Catch::Session().run(argv2.size(), argv2.data()); + return xo::UtestAppStart("utest.alloc2").run(argc, argv); } /* end alloc2_utest_main.cpp */ diff --git a/utest/arena.test.cpp b/utest/arena.test.cpp index 4f88ffd2..68433211 100644 --- a/utest/arena.test.cpp +++ b/utest/arena.test.cpp @@ -3,7 +3,7 @@ * @author Roland Conybeare, Dec 2025 **/ -#include "TestUtil.hpp" +#include #include #include #include diff --git a/utest/dp.test.cpp b/utest/dp.test.cpp index c2c91d70..842c7dc7 100644 --- a/utest/dp.test.cpp +++ b/utest/dp.test.cpp @@ -3,7 +3,7 @@ * @author Roland Conybeare, May 2026 **/ -#include "TestUtil.hpp" +#include #include "dp.hpp" #include #include diff --git a/utest/objectmodel.test.cpp b/utest/objectmodel.test.cpp index 5f08b2c8..43067b6e 100644 --- a/utest/objectmodel.test.cpp +++ b/utest/objectmodel.test.cpp @@ -79,7 +79,7 @@ * Application code will deal with ubox **/ -#include "TestUtil.hpp" +#include #include #include #include