ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
logging_listener Class Reference

Catch2 event listener that sets up logging for each test case and logs all test events to Boost.Log files. More...

#include <logging_listener.hpp>

Inherits EventListenerBase.

Collaboration diagram for logging_listener:
Collaboration graph

Public Member Functions

std::string extract_suite_name (const Catch::TestCaseInfo &testInfo)
 Extracts the first tag from a Catch2 test case as the suite name.
 
std::string extract_module_name ()
 Extracts the module name from the test binary name.
 
void testRunStarting (Catch::TestRunInfo const &testRunInfo) override
 
void testRunEnded (Catch::TestRunStats const &testRunStats) override
 
void testCaseStarting (Catch::TestCaseInfo const &testInfo) override
 
void testCaseEnded (Catch::TestCaseStats const &testCaseStats) override
 
void assertionEnded (Catch::AssertionStats const &assertionStats) override
 
void sectionStarting (Catch::SectionInfo const &sectionInfo) override
 
void sectionEnded (Catch::SectionStats const &sectionStats) override
 

Static Public Member Functions

static void set_test_module_name (const std::string &module_name)
 Sets the test module name from the main function.
 

Detailed Description

Catch2 event listener that sets up logging for each test case and logs all test events to Boost.Log files.

This listener automatically initializes the logging infrastructure before each test case starts and cleans it up when the test completes. It also logs all Catch2 test events (test start/end, sections, assertions) to the Boost.Log file.

The listener must be registered in each test's main.cpp file using: CATCH_REGISTER_LISTENER(ores::utility::test::logging_listener)

In your tests, use logger() to access the current test's logger:

TEST_CASE("my_test", "[my_suite]") { BOOST_LOG_SEV(logger(), info) << "Test message"; }

Member Function Documentation

◆ extract_suite_name()

std::string extract_suite_name ( const Catch::TestCaseInfo &  testInfo)

Extracts the first tag from a Catch2 test case as the suite name.

If no tags are present, returns "default_suite".

◆ extract_module_name()

std::string extract_module_name ( )

Extracts the module name from the test binary name.

Assumes the binary follows the pattern "ores.*.tests"