diff options
| author | Dan Engelbrecht <[email protected]> | 2023-11-15 12:13:00 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-15 12:13:00 +0100 |
| commit | 9f2a7e58fb8a30e630d8b465d2ba832a861579c2 (patch) | |
| tree | f7b4cef8ae2a6fe96c58848f23d8de14bcedf4d9 /src/zencore/testing.cpp | |
| parent | fix race contdition when signaling shutdown of process and waiting for comple... (diff) | |
| download | zen-9f2a7e58fb8a30e630d8b465d2ba832a861579c2.tar.xz zen-9f2a7e58fb8a30e630d8b465d2ba832a861579c2.zip | |
add doctest listener so we can output when test/subtests begin (#538)
* add doctest listener so we can output when test/subtests begin
* disable sentry when running a test server
Diffstat (limited to 'src/zencore/testing.cpp')
| -rw-r--r-- | src/zencore/testing.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/zencore/testing.cpp b/src/zencore/testing.cpp index 54d89ded2..936424e0f 100644 --- a/src/zencore/testing.cpp +++ b/src/zencore/testing.cpp @@ -5,12 +5,64 @@ #if ZEN_WITH_TESTS +# include <doctest/doctest.h> + namespace zen::testing { using namespace std::literals; +struct TestListener : public doctest::IReporter +{ + const std::string_view ColorYellow = "\033[0;33m"sv; + const std::string_view ColorNone = "\033[0m"sv; + + // constructor has to accept the ContextOptions by ref as a single argument + TestListener(const doctest::ContextOptions&) {} + + void report_query(const doctest::QueryData& /*in*/) override {} + + void test_run_start() override {} + + void test_run_end(const doctest::TestRunStats& /*in*/) override {} + + void test_case_start(const doctest::TestCaseData& in) override + { + Current = ∈ + ZEN_CONSOLE("{}======== TEST_CASE: {:<50} ========{}", ColorYellow, Current->m_name, ColorNone); + } + + // called when a test case is reentered because of unfinished subcases + void test_case_reenter(const doctest::TestCaseData& /*in*/) override + { + ZEN_CONSOLE("{}-------------------------------------------------------------------------------{}", ColorYellow, ColorNone); + } + + void test_case_end(const doctest::CurrentTestCaseStats& /*in*/) override { Current = nullptr; } + + void test_case_exception(const doctest::TestCaseException& /*in*/) override {} + + void subcase_start(const doctest::SubcaseSignature& in) override + { + ZEN_CONSOLE("{}-------- SUBCASE: {:<50} --------{}", + ColorYellow, + fmt::format("{}/{}", Current->m_name, in.m_name.c_str()), + ColorNone); + } + + void subcase_end() override {} + + void log_assert(const doctest::AssertData& /*in*/) override {} + + void log_message(const doctest::MessageData& /*in*/) override {} + + void test_case_skipped(const doctest::TestCaseData& /*in*/) override {} + + const doctest::TestCaseData* Current = nullptr; +}; + struct TestRunner::Impl { + Impl() { REGISTER_LISTENER("ZenTestListener", 1, TestListener); } doctest::Context Session; }; |