xo-alloc2: utest: refactor to use xo-testutil/
This commit is contained in:
parent
908c4908c5
commit
4039c29f5d
14 changed files with 17 additions and 165 deletions
|
|
@ -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@")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "TestUtil.hpp"
|
||||
#include <xo/testutil/Utest.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/alloc2/AllocIterator.hpp>
|
||||
#include <xo/alloc2/Arena.hpp>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* @author Roland Conybeare, May 2026
|
||||
**/
|
||||
|
||||
#include "TestUtil.hpp"
|
||||
#include <xo/testutil/Utest.hpp>
|
||||
#include "Generation.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* @author Roland Conybeare, May 2026
|
||||
**/
|
||||
|
||||
#include "TestUtil.hpp"
|
||||
#include <xo/testutil/Utest.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
#include <sys/wait.h>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* @author Roland Conybeare, May 2026
|
||||
**/
|
||||
|
||||
#include "TestUtil.hpp"
|
||||
#include <xo/testutil/Utest.hpp>
|
||||
#include <xo/alloc2/ResourceVisitor.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* @author Roland Conybeare, May 2026
|
||||
**/
|
||||
|
||||
#include "TestUtil.hpp"
|
||||
#include <xo/testutil/Utest.hpp>
|
||||
#include "role.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
/** @file TestUtil.cpp
|
||||
*
|
||||
* @author Roland Conybeare, May 2026
|
||||
**/
|
||||
|
||||
#include "TestUtil.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
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 */
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/** @file TestUtil.hpp
|
||||
*
|
||||
* @author Roland Conybeare, May 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
|
||||
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 */
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
* @author Roland Conybeare, May 2026
|
||||
**/
|
||||
|
||||
#include "TestUtil.hpp"
|
||||
#include <xo/testutil/Utest.hpp>
|
||||
#include <xo/alloc2/VisitReason.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,100 +1,18 @@
|
|||
/* file alloc2_utest_main.cpp */
|
||||
|
||||
#include "TestUtil.hpp"
|
||||
#include <xo/subsys/Subsystem.hpp>
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
#include <CLI/CLI.hpp>
|
||||
#define CATCH_CONFIG_RUNNER // before UtestListener.hpp
|
||||
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include <catch2/catch.hpp>
|
||||
#include <xo/testutil/UtestAppStart.hpp>
|
||||
#include <xo/testutil/UtestListener.hpp>
|
||||
|
||||
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<const char *> 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 */
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "TestUtil.hpp"
|
||||
#include <xo/testutil/Utest.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/alloc2/Arena.hpp>
|
||||
#include <xo/arena/print.hpp>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* @author Roland Conybeare, May 2026
|
||||
**/
|
||||
|
||||
#include "TestUtil.hpp"
|
||||
#include <xo/testutil/Utest.hpp>
|
||||
#include "dp.hpp"
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/alloc2/Arena.hpp>
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@
|
|||
* Application code will deal with ubox<AComplex,DPolarCoords>
|
||||
**/
|
||||
|
||||
#include "TestUtil.hpp"
|
||||
#include <xo/testutil/Utest.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue