ORE Studio 0.0.4
Loading...
Searching...
No Matches
logging_listener.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_TESTING_LOGGING_LISTENER_HPP
21#define ORES_TESTING_LOGGING_LISTENER_HPP
22
23#include <catch2/catch_test_case_info.hpp>
24#include <catch2/reporters/catch_reporter_event_listener.hpp>
25#include "ores.utility/log/lifecycle_manager.hpp"
26
27namespace ores::testing {
28
48class logging_listener : public Catch::EventListenerBase {
49public:
53 static void set_test_module_name(const std::string& module_name);
54
60 std::string extract_suite_name(const Catch::TestCaseInfo& testInfo);
61
67 std::string extract_module_name();
68
69public:
70 using Catch::EventListenerBase::EventListenerBase;
71
72 void testRunStarting(Catch::TestRunInfo const& testRunInfo) override;
73 void testRunEnded(Catch::TestRunStats const& testRunStats) override;
74 void testCaseStarting(Catch::TestCaseInfo const& testInfo) override;
75 void testCaseEnded(Catch::TestCaseStats const& testCaseStats) override;
76 void assertionEnded(Catch::AssertionStats const& assertionStats) override;
77 void sectionStarting(Catch::SectionInfo const& sectionInfo) override;
78 void sectionEnded(Catch::SectionStats const& sectionStats) override;
79
80private:
81 std::shared_ptr<utility::log::lifecycle_manager> lifecycle_manager_;
82};
83
84}
85
86#endif
Testing infrastructure common to all test projects.
Definition database_helper.hpp:27
Catch2 event listener that sets up logging for each test case and logs all test events to Boost....
Definition logging_listener.hpp:48
std::string extract_module_name()
Extracts the module name from the test binary name.
Definition logging_listener.cpp:89
static void set_test_module_name(const std::string &module_name)
Sets the test module name from the main function.
Definition logging_listener.cpp:93
std::string extract_suite_name(const Catch::TestCaseInfo &testInfo)
Extracts the first tag from a Catch2 test case as the suite name.
Definition logging_listener.cpp:75