Skip to content

Commit 6b0ba00

Browse files
committed
FIX: Fix log tests on macOS
1 parent 566466d commit 6b0ba00

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

test/src/log_tests.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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 {
910
namespace test {
1011
class ConsoleLogReceiverTests : public testing::Test {
1112
protected:
12-
ConsoleLogReceiver target_{};
13+
std::ostringstream stream_{};
14+
ConsoleLogReceiver target_{stream_};
1315
};
1416

1517
TEST_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

2525
TEST_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

3432
TEST(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

Comments
 (0)