#pragma once #ifndef MESSMER_CPPUTILS_TEST_LOGGING_TESTUTILS_LOGGINGTEST_H #define MESSMER_CPPUTILS_TEST_LOGGING_TESTUTILS_LOGGINGTEST_H #include #include #include "cpp-utils/logging/logging.h" #include class MockLogger final { public: MockLogger(): _capturedLogData(), _logger(spdlog::create("MockLogger", _capturedLogData, true)) { } ~MockLogger() { spdlog::drop("MockLogger"); }; std::shared_ptr get() { return _logger; } std::string capturedLog() const { return _capturedLogData.str(); } private: std::ostringstream _capturedLogData; std::shared_ptr _logger; }; class LoggingTest: public ::testing::Test { public: LoggingTest(): mockLogger() {} std::string captureStderr(std::function func) { testing::internal::CaptureStderr(); func(); return testing::internal::GetCapturedStderr(); } ~LoggingTest() override { cpputils::logging::reset(); } MockLogger mockLogger; }; #endif