This logger is used for tests. It caches all the log messages and prints them to the console when a test fails. For debug purposes this behaviour can be overwritten with the 'IOX2_TESTING_ALLOW_LOG' environment variable, e.g. 'IOX2_TESTING_ALLOW_LOG=ON ./hoofs_moduletests –gtest_filter=SharedMemoryObject_Test*'. Furthermore, it can also be used to check for the occurrence on specific log messages, e.g. when a function is expected to log an error.
More...
#include <testing_logger.hpp>
|
| void | flush () noexcept override |
| |
This logger is used for tests. It caches all the log messages and prints them to the console when a test fails. For debug purposes this behaviour can be overwritten with the 'IOX2_TESTING_ALLOW_LOG' environment variable, e.g. 'IOX2_TESTING_ALLOW_LOG=ON ./hoofs_moduletests –gtest_filter=SharedMemoryObject_Test*'. Furthermore, it can also be used to check for the occurrence on specific log messages, e.g. when a function is expected to log an error.
call_to_function_Which_logs_an_error();
[](const auto& log_messages){
ASSERT_THAT(log_messages.size(), Eq(1U));
EXPECT_THAT(log_messages[0], HasSubstr(expected_output));
});
static auto check_log_message_if_log_level_is_supported(legacy::log::LogLevel log_level, const std::function< void(const std::vector< std::string > &)> &check) -> void
Runs the provided checker function for the collected log messages.
Definition at line 65 of file testing_logger.hpp.
◆ ~TestingLogger()
| iox2::bb::testing::TestingLogger::~TestingLogger |
( |
| ) |
|
|
overridedefault |
◆ TestingLogger() [1/2]
| iox2::bb::testing::TestingLogger::TestingLogger |
( |
const TestingLogger & |
| ) |
|
|
delete |
◆ TestingLogger() [2/2]
| iox2::bb::testing::TestingLogger::TestingLogger |
( |
TestingLogger && |
| ) |
|
|
delete |
◆ check_log_message_if_log_level_is_supported()
| static auto iox2::bb::testing::TestingLogger::check_log_message_if_log_level_is_supported |
( |
legacy::log::LogLevel |
log_level, |
|
|
const std::function< void(const std::vector< std::string > &)> & |
check |
|
) |
| -> void |
|
inlinestatic |
◆ clear_log_buffer()
| auto iox2::bb::testing::TestingLogger::clear_log_buffer |
( |
| ) |
-> void |
|
inlinenoexcept |
Removes all log messages from the internal cache. This is automatically done at the start of each test.
Definition at line 123 of file testing_logger.hpp.
◆ does_logger_support_log_level()
| static constexpr auto iox2::bb::testing::TestingLogger::does_logger_support_log_level |
( |
const legacy::log::LogLevel |
log_level | ) |
-> bool |
|
inlinestaticconstexprnoexcept |
◆ flush()
| void iox2::bb::testing::TestingLogger::flush |
( |
| ) |
|
|
inlineoverrideprotectednoexcept |
◆ get_number_of_log_messages()
| static auto iox2::bb::testing::TestingLogger::get_number_of_log_messages |
( |
| ) |
-> uint64_t |
|
inlinestaticnoexcept |
◆ init()
| static auto iox2::bb::testing::TestingLogger::init |
( |
| ) |
-> void |
|
inlinestaticnoexcept |
Initialized the logger. This should be called in the main function of the test binary.
#include "test.hpp"
int main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
static auto init() noexcept -> void
Initialized the logger. This should be called in the main function of the test binary.
Definition at line 91 of file testing_logger.hpp.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ print_log_buffer()
| auto iox2::bb::testing::TestingLogger::print_log_buffer |
( |
| ) |
-> void |
|
inlinenoexcept |
Prints all log messages from the internal cache. This is automatically done at the end of a failed test.
Definition at line 129 of file testing_logger.hpp.
References iox2::log().
The documentation for this class was generated from the following file: