11#include < gtest/gtest.h>
22
33#include < iostream>
4+ #include < ostream>
45#include < string>
56
67#include " databento/log.hpp"
@@ -9,37 +10,29 @@ namespace databento {
910namespace test {
1011class ConsoleLogReceiverTests : public testing ::Test {
1112 protected:
12- ConsoleLogReceiver target_{};
13+ std::ostringstream stream_{};
14+ ConsoleLogReceiver target_{stream_};
1315};
1416
1517TEST_F (ConsoleLogReceiverTests, TestOutput) {
16- testing::internal::CaptureStderr ();
1718 const std::string msg = " Something went wrong" ;
1819 target_.Receive (LogLevel::Warning, msg);
19- std::clog.flush ();
20- const std::string output = testing::internal::GetCapturedStderr ();
20+ const std::string output = stream_.str ();
2121 // ConsoleLogReceiver adds newline
2222 ASSERT_EQ (msg + ' \n ' , output);
2323}
2424
2525TEST_F (ConsoleLogReceiverTests, TestFilter) {
26- testing::internal::CaptureStderr ();
2726 const std::string msg = " Something happened" ;
2827 target_.Receive (LogLevel::Debug, msg);
29- std::clog.flush ();
30- const std::string output = testing::internal::GetCapturedStderr ();
28+ const std::string output = stream_.str ();
3129 ASSERT_TRUE (output.empty ());
3230}
3331
3432TEST (ILogReceiverTests, TestDefault) {
3533 auto * log_receiver = ILogReceiver::Default ();
3634 ASSERT_NE (log_receiver, nullptr );
3735 ASSERT_NE (dynamic_cast <ConsoleLogReceiver*>(log_receiver), nullptr );
38- testing::internal::CaptureStderr ();
39- const std::string msg = " Fatal error" ;
40- log_receiver->Receive (LogLevel::Error, msg);
41- const std::string output = testing::internal::GetCapturedStderr ();
42- ASSERT_EQ (msg + ' \n ' , output);
4336}
4437} // namespace test
4538} // namespace databento
0 commit comments