diff options
author | Andy Getzendanner <durandal@google.com> | 2024-07-03 11:14:24 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-07-03 11:15:25 -0700 |
commit | 6e701508ea7505a8316f44a3ace6abcea585f287 (patch) | |
tree | 01c3164b91a051fadcb60a28737f09e7bf72def4 /absl | |
parent | 0d9c2fc763dd766b868665a302ff4526748c4b36 (diff) |
Encode some additional metadata when writing protobuf-encoded logs.
PiperOrigin-RevId: 649138261
Change-Id: I8687eb7b06cc9e96779d1d3e98b44b4f643c95a8
Diffstat (limited to 'absl')
-rw-r--r-- | absl/log/internal/log_message.cc | 105 | ||||
-rw-r--r-- | absl/log/internal/test_matchers.cc | 9 | ||||
-rw-r--r-- | absl/log/internal/test_matchers.h | 2 | ||||
-rw-r--r-- | absl/log/log_basic_test_impl.inc | 207 | ||||
-rw-r--r-- | absl/log/log_format_test.cc | 674 | ||||
-rw-r--r-- | absl/log/log_modifier_methods_test.cc | 36 | ||||
-rw-r--r-- | absl/log/log_streamer_test.cc | 269 | ||||
-rw-r--r-- | absl/log/structured_test.cc | 5 |
8 files changed, 692 insertions, 615 deletions
diff --git a/absl/log/internal/log_message.cc b/absl/log/internal/log_message.cc index 58505267..4e9b08af 100644 --- a/absl/log/internal/log_message.cc +++ b/absl/log/internal/log_message.cc @@ -27,6 +27,7 @@ #include <algorithm> #include <array> #include <atomic> +#include <ios> #include <memory> #include <ostream> #include <string> @@ -67,7 +68,14 @@ namespace log_internal { namespace { // message `logging.proto.Event` enum EventTag : uint8_t { + kFileName = 2, + kFileLine = 3, + kTimeNsecs = 4, + kSeverity = 5, + kThreadId = 6, kValue = 7, + kSequenceNumber = 9, + kThreadName = 10, }; // message `logging.proto.Value` @@ -100,6 +108,23 @@ bool PrintValue(absl::Span<char>& dst, absl::Span<const char> buf) { return true; } +// See `logging.proto.Severity` +int32_t ProtoSeverity(absl::LogSeverity severity, int verbose_level) { + switch (severity) { + case absl::LogSeverity::kInfo: + if (verbose_level == absl::LogEntry::kNoVerbosityLevel) return 800; + return 600 - verbose_level; + case absl::LogSeverity::kWarning: + return 900; + case absl::LogSeverity::kError: + return 950; + case absl::LogSeverity::kFatal: + return 1100; + default: + return 800; + } +} + absl::string_view Basename(absl::string_view filepath) { #ifdef _WIN32 size_t path = filepath.find_last_of("/\\"); @@ -145,26 +170,37 @@ struct LogMessage::LogMessageData final { // A `logging.proto.Event` proto message is built into `encoded_buf`. std::array<char, kLogMessageBufferSize> encoded_buf; - // `encoded_remaining` is the suffix of `encoded_buf` that has not been filled - // yet. If a datum to be encoded does not fit into `encoded_remaining` and - // cannot be truncated to fit, the size of `encoded_remaining` will be zeroed - // to prevent encoding of any further data. Note that in this case its data() - // pointer will not point past the end of `encoded_buf`. - absl::Span<char> encoded_remaining; + // `encoded_remaining()` is the suffix of `encoded_buf` that has not been + // filled yet. If a datum to be encoded does not fit into + // `encoded_remaining()` and cannot be truncated to fit, the size of + // `encoded_remaining()` will be zeroed to prevent encoding of any further + // data. Note that in this case its `data()` pointer will not point past the + // end of `encoded_buf`. + // The first use of `encoded_remaining()` is our chance to record metadata + // after any modifications (e.g. by `AtLocation()`) but before any data have + // been recorded. We want to record metadata before data so that data are + // preferentially truncated if we run out of buffer. + absl::Span<char>& encoded_remaining() { + if (encoded_remaining_actual_do_not_use_directly.data() == nullptr) { + encoded_remaining_actual_do_not_use_directly = + absl::MakeSpan(encoded_buf); + InitializeEncodingAndFormat(); + } + return encoded_remaining_actual_do_not_use_directly; + } + absl::Span<char> encoded_remaining_actual_do_not_use_directly; // A formatted string message is built in `string_buf`. std::array<char, kLogMessageBufferSize> string_buf; + void InitializeEncodingAndFormat(); void FinalizeEncodingAndFormat(); }; LogMessage::LogMessageData::LogMessageData(const char* file, int line, absl::LogSeverity severity, absl::Time timestamp) - : extra_sinks_only(false), - manipulated(nullptr), - // This `absl::MakeSpan` silences spurious -Wuninitialized from GCC: - encoded_remaining(absl::MakeSpan(encoded_buf)) { + : extra_sinks_only(false), manipulated(nullptr) { // Legacy defaults for LOG's ostream: manipulated.setf(std::ios_base::showbase | std::ios_base::boolalpha); entry.full_filename_ = file; @@ -177,13 +213,25 @@ LogMessage::LogMessageData::LogMessageData(const char* file, int line, entry.tid_ = absl::base_internal::GetCachedTID(); } +void LogMessage::LogMessageData::InitializeEncodingAndFormat() { + EncodeStringTruncate(EventTag::kFileName, entry.source_filename(), + &encoded_remaining()); + EncodeVarint(EventTag::kFileLine, entry.source_line(), &encoded_remaining()); + EncodeVarint(EventTag::kTimeNsecs, absl::ToUnixNanos(entry.timestamp()), + &encoded_remaining()); + EncodeVarint(EventTag::kSeverity, + ProtoSeverity(entry.log_severity(), entry.verbosity()), + &encoded_remaining()); + EncodeVarint(EventTag::kThreadId, entry.tid(), &encoded_remaining()); +} + void LogMessage::LogMessageData::FinalizeEncodingAndFormat() { - // Note that `encoded_remaining` may have zero size without pointing past the - // end of `encoded_buf`, so the difference between `data()` pointers is used - // to compute the size of `encoded_data`. + // Note that `encoded_remaining()` may have zero size without pointing past + // the end of `encoded_buf`, so the difference between `data()` pointers is + // used to compute the size of `encoded_data`. absl::Span<const char> encoded_data( encoded_buf.data(), - static_cast<size_t>(encoded_remaining.data() - encoded_buf.data())); + static_cast<size_t>(encoded_remaining().data() - encoded_buf.data())); // `string_remaining` is the suffix of `string_buf` that has not been filled // yet. absl::Span<char> string_remaining(string_buf); @@ -211,7 +259,6 @@ void LogMessage::LogMessageData::FinalizeEncodingAndFormat() { if (PrintValue(string_remaining, field.bytes_value())) continue; break; } - break; } auto chars_written = static_cast<size_t>(string_remaining.data() - string_buf.data()); @@ -413,7 +460,7 @@ void LogMessage::Flush() { data_->FinalizeEncodingAndFormat(); data_->entry.encoding_ = absl::string_view(data_->encoded_buf.data(), - static_cast<size_t>(data_->encoded_remaining.data() - + static_cast<size_t>(data_->encoded_remaining().data() - data_->encoded_buf.data())); SendToLog(); } @@ -421,7 +468,7 @@ void LogMessage::Flush() { void LogMessage::SetFailQuietly() { data_->fail_quietly = true; } LogMessage::OstreamView::OstreamView(LogMessageData& message_data) - : data_(message_data), encoded_remaining_copy_(data_.encoded_remaining) { + : data_(message_data), encoded_remaining_copy_(data_.encoded_remaining()) { // This constructor sets the `streambuf` up so that streaming into an attached // ostream encodes string data in-place. To do that, we write appropriate // headers into the buffer using a copy of the buffer view so that we can @@ -444,8 +491,8 @@ LogMessage::OstreamView::~OstreamView() { if (!string_start_.data()) { // The second field header didn't fit. Whether the first one did or not, we // shouldn't commit `encoded_remaining_copy_`, and we also need to zero the - // size of `data_->encoded_remaining` so that no more data are encoded. - data_.encoded_remaining.remove_suffix(data_.encoded_remaining.size()); + // size of `data_->encoded_remaining()` so that no more data are encoded. + data_.encoded_remaining().remove_suffix(data_.encoded_remaining().size()); return; } const absl::Span<const char> contents(pbase(), @@ -454,7 +501,7 @@ LogMessage::OstreamView::~OstreamView() { encoded_remaining_copy_.remove_prefix(contents.size()); EncodeMessageLength(string_start_, &encoded_remaining_copy_); EncodeMessageLength(message_start_, &encoded_remaining_copy_); - data_.encoded_remaining = encoded_remaining_copy_; + data_.encoded_remaining() = encoded_remaining_copy_; } std::ostream& LogMessage::OstreamView::stream() { return data_.manipulated; } @@ -521,13 +568,13 @@ void LogMessage::LogBacktraceIfNeeded() { view.stream() << ") "; } -// Encodes into `data_->encoded_remaining` a partial `logging.proto.Event` +// Encodes into `data_->encoded_remaining()` a partial `logging.proto.Event` // containing the specified string data using a `Value` field appropriate to // `str_type`. Truncates `str` if necessary, but emits nothing and marks the // buffer full if even the field headers do not fit. template <LogMessage::StringType str_type> void LogMessage::CopyToEncodedBuffer(absl::string_view str) { - auto encoded_remaining_copy = data_->encoded_remaining; + auto encoded_remaining_copy = data_->encoded_remaining(); auto start = EncodeMessageStart( EventTag::kValue, BufferSizeFor(WireType::kLengthDelimited) + str.size(), &encoded_remaining_copy); @@ -540,11 +587,11 @@ void LogMessage::CopyToEncodedBuffer(absl::string_view str) { str, &encoded_remaining_copy)) { // The string may have been truncated, but the field header fit. EncodeMessageLength(start, &encoded_remaining_copy); - data_->encoded_remaining = encoded_remaining_copy; + data_->encoded_remaining() = encoded_remaining_copy; } else { - // The field header(s) did not fit; zero `encoded_remaining` so we don't + // The field header(s) did not fit; zero `encoded_remaining()` so we don't // write anything else later. - data_->encoded_remaining.remove_suffix(data_->encoded_remaining.size()); + data_->encoded_remaining().remove_suffix(data_->encoded_remaining().size()); } } template void LogMessage::CopyToEncodedBuffer<LogMessage::StringType::kLiteral>( @@ -553,7 +600,7 @@ template void LogMessage::CopyToEncodedBuffer< LogMessage::StringType::kNotLiteral>(absl::string_view str); template <LogMessage::StringType str_type> void LogMessage::CopyToEncodedBuffer(char ch, size_t num) { - auto encoded_remaining_copy = data_->encoded_remaining; + auto encoded_remaining_copy = data_->encoded_remaining(); auto value_start = EncodeMessageStart( EventTag::kValue, BufferSizeFor(WireType::kLengthDelimited) + num, &encoded_remaining_copy); @@ -566,11 +613,11 @@ void LogMessage::CopyToEncodedBuffer(char ch, size_t num) { log_internal::AppendTruncated(ch, num, encoded_remaining_copy); EncodeMessageLength(str_start, &encoded_remaining_copy); EncodeMessageLength(value_start, &encoded_remaining_copy); - data_->encoded_remaining = encoded_remaining_copy; + data_->encoded_remaining() = encoded_remaining_copy; } else { - // The field header(s) did not fit; zero `encoded_remaining` so we don't + // The field header(s) did not fit; zero `encoded_remaining()` so we don't // write anything else later. - data_->encoded_remaining.remove_suffix(data_->encoded_remaining.size()); + data_->encoded_remaining().remove_suffix(data_->encoded_remaining().size()); } } template void LogMessage::CopyToEncodedBuffer<LogMessage::StringType::kLiteral>( diff --git a/absl/log/internal/test_matchers.cc b/absl/log/internal/test_matchers.cc index 8c6515c4..042083d8 100644 --- a/absl/log/internal/test_matchers.cc +++ b/absl/log/internal/test_matchers.cc @@ -26,6 +26,7 @@ #include "absl/base/attributes.h" #include "absl/base/config.h" #include "absl/log/internal/test_helpers.h" +#include "absl/log/log_entry.h" #include "absl/strings/string_view.h" #include "absl/time/clock.h" #include "absl/time/time.h" @@ -131,11 +132,9 @@ Matcher<const absl::LogEntry&> Timestamp( return Property("timestamp", &absl::LogEntry::timestamp, timestamp); } -Matcher<const absl::LogEntry&> TimestampInMatchWindow() { - return Property("timestamp", &absl::LogEntry::timestamp, - AllOf(Ge(absl::Now()), Truly([](absl::Time arg) { - return arg <= absl::Now(); - }))); +Matcher<absl::Time> InMatchWindow() { + return AllOf(Ge(absl::Now()), + Truly([](absl::Time arg) { return arg <= absl::Now(); })); } Matcher<const absl::LogEntry&> ThreadID( diff --git a/absl/log/internal/test_matchers.h b/absl/log/internal/test_matchers.h index fc653a91..906eda24 100644 --- a/absl/log/internal/test_matchers.h +++ b/absl/log/internal/test_matchers.h @@ -62,7 +62,7 @@ namespace log_internal { const ::testing::Matcher<absl::Time>& timestamp); // Matches if the `LogEntry`'s timestamp falls after the instantiation of this // matcher and before its execution, as is normal when used with EXPECT_CALL. -::testing::Matcher<const absl::LogEntry&> TimestampInMatchWindow(); +::testing::Matcher<absl::Time> InMatchWindow(); ::testing::Matcher<const absl::LogEntry&> ThreadID( const ::testing::Matcher<absl::LogEntry::tid_t>&); ::testing::Matcher<const absl::LogEntry&> TextMessageWithPrefixAndNewline( diff --git a/absl/log/log_basic_test_impl.inc b/absl/log/log_basic_test_impl.inc index 8083ff2c..7baf5e7b 100644 --- a/absl/log/log_basic_test_impl.inc +++ b/absl/log/log_basic_test_impl.inc @@ -53,6 +53,7 @@ using ::absl::log_internal::DeathTestValidateExpectations; using ::absl::log_internal::DiedOfFatal; using ::absl::log_internal::DiedOfQFatal; #endif +using ::absl::log_internal::InMatchWindow; using ::absl::log_internal::LoggingEnabledAt; using ::absl::log_internal::LogSeverity; using ::absl::log_internal::Prefix; @@ -62,7 +63,7 @@ using ::absl::log_internal::SourceLine; using ::absl::log_internal::Stacktrace; using ::absl::log_internal::TextMessage; using ::absl::log_internal::ThreadID; -using ::absl::log_internal::TimestampInMatchWindow; +using ::absl::log_internal::Timestamp; using ::absl::log_internal::Verbosity; using ::testing::AnyNumber; using ::testing::Eq; @@ -98,18 +99,20 @@ TEST_P(BasicLogTest, Info) { if (LoggingEnabledAt(absl::LogSeverity::kInfo)) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq(__FILE__)), - SourceBasename(Eq("log_basic_test_impl.inc")), - SourceLine(Eq(log_line)), Prefix(IsTrue()), - LogSeverity(Eq(absl::LogSeverity::kInfo)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("hello world")), - Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - literal: "hello world" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq(__FILE__)), + SourceBasename(Eq("log_basic_test_impl.inc")), + SourceLine(Eq(log_line)), Prefix(IsTrue()), + LogSeverity(Eq(absl::LogSeverity::kInfo)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("hello world")), + Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::INFO), Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(literal: "hello world")pb")))), + Stacktrace(IsEmpty())))); } test_sink.StartCapturingLogs(); @@ -127,18 +130,20 @@ TEST_P(BasicLogTest, Warning) { if (LoggingEnabledAt(absl::LogSeverity::kWarning)) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq(__FILE__)), - SourceBasename(Eq("log_basic_test_impl.inc")), - SourceLine(Eq(log_line)), Prefix(IsTrue()), - LogSeverity(Eq(absl::LogSeverity::kWarning)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("hello world")), - Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - literal: "hello world" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq(__FILE__)), + SourceBasename(Eq("log_basic_test_impl.inc")), + SourceLine(Eq(log_line)), Prefix(IsTrue()), + LogSeverity(Eq(absl::LogSeverity::kWarning)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("hello world")), + Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::WARNING), Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(literal: "hello world")pb")))), + Stacktrace(IsEmpty())))); } test_sink.StartCapturingLogs(); @@ -156,18 +161,20 @@ TEST_P(BasicLogTest, Error) { if (LoggingEnabledAt(absl::LogSeverity::kError)) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq(__FILE__)), - SourceBasename(Eq("log_basic_test_impl.inc")), - SourceLine(Eq(log_line)), Prefix(IsTrue()), - LogSeverity(Eq(absl::LogSeverity::kError)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("hello world")), - Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - literal: "hello world" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq(__FILE__)), + SourceBasename(Eq("log_basic_test_impl.inc")), + SourceLine(Eq(log_line)), Prefix(IsTrue()), + LogSeverity(Eq(absl::LogSeverity::kError)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("hello world")), + Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::ERROR), Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(literal: "hello world")pb")))), + Stacktrace(IsEmpty())))); } test_sink.StartCapturingLogs(); @@ -211,12 +218,16 @@ TEST_P(BasicLogDeathTest, Fatal) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(IsEmpty())))) .WillOnce(DeathTestExpectedLogging()); @@ -227,12 +238,16 @@ TEST_P(BasicLogDeathTest, Fatal) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(Not(IsEmpty()))))) .WillOnce(DeathTestExpectedLogging()); } @@ -265,12 +280,16 @@ TEST_P(BasicLogDeathTest, QFatal) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(IsEmpty())))) .WillOnce(DeathTestExpectedLogging()); } @@ -294,18 +313,20 @@ TEST_P(BasicLogTest, DFatal) { if (LoggingEnabledAt(absl::LogSeverity::kError)) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq(__FILE__)), - SourceBasename(Eq("log_basic_test_impl.inc")), - SourceLine(Eq(log_line)), Prefix(IsTrue()), - LogSeverity(Eq(absl::LogSeverity::kError)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("hello world")), - Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - literal: "hello world" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq(__FILE__)), + SourceBasename(Eq("log_basic_test_impl.inc")), + SourceLine(Eq(log_line)), Prefix(IsTrue()), + LogSeverity(Eq(absl::LogSeverity::kError)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("hello world")), + Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::ERROR), Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(literal: "hello world")pb")))), + Stacktrace(IsEmpty())))); } test_sink.StartCapturingLogs(); @@ -339,12 +360,16 @@ TEST_P(BasicLogDeathTest, DFatal) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(IsEmpty())))) .WillOnce(DeathTestExpectedLogging()); @@ -355,12 +380,16 @@ TEST_P(BasicLogDeathTest, DFatal) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(Not(IsEmpty()))))) .WillOnce(DeathTestExpectedLogging()); } @@ -408,17 +437,25 @@ TEST_P(BasicLogTest, Level) { if (LoggingEnabledAt(severity)) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq(__FILE__)), - SourceBasename(Eq("log_basic_test_impl.inc")), - SourceLine(Eq(log_line)), Prefix(IsTrue()), - LogSeverity(Eq(severity)), TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("hello world")), - Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - literal: "hello world" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq(__FILE__)), + SourceBasename(Eq("log_basic_test_impl.inc")), + SourceLine(Eq(log_line)), Prefix(IsTrue()), + LogSeverity(Eq(severity)), Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("hello world")), + Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(severity == absl::LogSeverity::kInfo ? logging::proto::INFO + : severity == absl::LogSeverity::kWarning + ? logging::proto::WARNING + : severity == absl::LogSeverity::kError + ? logging::proto::ERROR + : 0), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(literal: "hello world")pb")))), + Stacktrace(IsEmpty())))); } test_sink.StartCapturingLogs(); do_log(); @@ -455,12 +492,16 @@ TEST_P(BasicLogDeathTest, Level) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(IsEmpty())))) .WillOnce(DeathTestExpectedLogging()); @@ -470,12 +511,16 @@ TEST_P(BasicLogDeathTest, Level) { SourceBasename(Eq("log_basic_test_impl.inc")), SourceLine(Eq(log_line)), Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), + Timestamp(InMatchWindow()), ThreadID(Eq(absl::base_internal::GetTID())), TextMessage(Eq("hello world")), Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb")), + ENCODED_MESSAGE(MatchesEvent( + Eq(__FILE__), Eq(log_line), InMatchWindow(), + Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(literal: "hello world")pb")))), Stacktrace(Not(IsEmpty()))))) .WillOnce(DeathTestExpectedLogging()); } diff --git a/absl/log/log_format_test.cc b/absl/log/log_format_test.cc index 8ca6df3e..beee966d 100644 --- a/absl/log/log_format_test.cc +++ b/absl/log/log_format_test.cc @@ -78,7 +78,7 @@ TEST(LogFormatTest, NoMessage) { TextPrefix(AsString(EndsWith(absl::StrCat( " log_format_test.cc:", log_line, "] ")))), TextMessage(IsEmpty()), - ENCODED_MESSAGE(EqualsProto(R"pb()pb"))))); + ENCODED_MESSAGE(HasValues(IsEmpty()))))); test_sink.StartCapturingLogs(); do_log(); @@ -96,11 +96,11 @@ TYPED_TEST(CharLogFormatTest, Printable) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("x")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "x" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("x")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "x")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -113,12 +113,11 @@ TYPED_TEST(CharLogFormatTest, Unprintable) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("\xee")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "\xee" - })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("\xee")), + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "\xee")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -137,11 +136,11 @@ TYPED_TEST(UnsignedIntLogFormatTest, Positive) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("224")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "224" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("224")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "224")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -156,11 +155,11 @@ TYPED_TEST(UnsignedIntLogFormatTest, BitfieldPositive) { auto comparison_stream = ComparisonStream(); comparison_stream << value.bits; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("42")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "42" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("42")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "42")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value.bits; @@ -179,11 +178,11 @@ TYPED_TEST(SignedIntLogFormatTest, Positive) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("224")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "224" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("224")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "224")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -196,12 +195,11 @@ TYPED_TEST(SignedIntLogFormatTest, Negative) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("-112")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "-112" - })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("-112")), + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "-112")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -216,11 +214,11 @@ TYPED_TEST(SignedIntLogFormatTest, BitfieldPositive) { auto comparison_stream = ComparisonStream(); comparison_stream << value.bits; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("21")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "21" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("21")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "21")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value.bits; @@ -235,11 +233,11 @@ TYPED_TEST(SignedIntLogFormatTest, BitfieldNegative) { auto comparison_stream = ComparisonStream(); comparison_stream << value.bits; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("-21")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "-21" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("-21")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "-21")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value.bits; @@ -276,11 +274,11 @@ TYPED_TEST(UnsignedEnumLogFormatTest, Positive) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("224")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "224" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("224")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "224")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -295,11 +293,11 @@ TYPED_TEST(UnsignedEnumLogFormatTest, BitfieldPositive) { auto comparison_stream = ComparisonStream(); comparison_stream << value.bits; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("42")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "42" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("42")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "42")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value.bits; @@ -335,11 +333,11 @@ TYPED_TEST(SignedEnumLogFormatTest, Positive) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("224")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "224" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("224")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "224")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -352,12 +350,11 @@ TYPED_TEST(SignedEnumLogFormatTest, Negative) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("-112")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "-112" - })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("-112")), + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "-112")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -372,11 +369,11 @@ TYPED_TEST(SignedEnumLogFormatTest, BitfieldPositive) { auto comparison_stream = ComparisonStream(); comparison_stream << value.bits; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("21")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "21" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("21")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "21")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value.bits; @@ -391,11 +388,11 @@ TYPED_TEST(SignedEnumLogFormatTest, BitfieldNegative) { auto comparison_stream = ComparisonStream(); comparison_stream << value.bits; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("-21")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "-21" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("-21")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "-21")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value.bits; @@ -412,9 +409,8 @@ TEST(FloatLogFormatTest, Positive) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("6.02e+23")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "6.02e+23" - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "6.02e+23")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -430,9 +426,8 @@ TEST(FloatLogFormatTest, Negative) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("-6.02e+23")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "-6.02e+23" - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "-6.02e+23")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -448,9 +443,8 @@ TEST(FloatLogFormatTest, NegativeExponent) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("6.02e-23")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "6.02e-23" - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "6.02e-23")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -466,9 +460,8 @@ TEST(DoubleLogFormatTest, Positive) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("6.02e+23")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "6.02e+23" - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "6.02e+23")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -484,9 +477,8 @@ TEST(DoubleLogFormatTest, Negative) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("-6.02e+23")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "-6.02e+23" - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "-6.02e+23")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -502,9 +494,8 @@ TEST(DoubleLogFormatTest, NegativeExponent) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("6.02e-23")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "6.02e-23" - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "6.02e-23")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -522,11 +513,11 @@ TYPED_TEST(FloatingPointLogFormatTest, Zero) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("0")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "0" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("0")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "0")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -539,11 +530,11 @@ TYPED_TEST(FloatingPointLogFormatTest, Integer) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("1")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "1" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("1")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "1")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -556,11 +547,11 @@ TYPED_TEST(FloatingPointLogFormatTest, Infinity) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(AnyOf(Eq("inf"), Eq("Inf"))), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "inf" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(AnyOf(Eq("inf"), Eq("Inf"))), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "inf")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -573,12 +564,11 @@ TYPED_TEST(FloatingPointLogFormatTest, NegativeInfinity) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(AnyOf(Eq("-inf"), Eq("-Inf"))), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "-inf" - })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(AnyOf(Eq("-inf"), Eq("-Inf"))), + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "-inf")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -591,11 +581,11 @@ TYPED_TEST(FloatingPointLogFormatTest, NaN) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(AnyOf(Eq("nan"), Eq("NaN"))), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "nan" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(AnyOf(Eq("nan"), Eq("NaN"))), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "nan")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; } @@ -616,20 +606,20 @@ TYPED_TEST(FloatingPointLogFormatTest, NegativeNaN) { test_sink, Send(AllOf( TextMessage(AnyOf(Eq("-nan"), Eq("nan"), Eq("NaN"), Eq("-nan(ind)"))), - ENCODED_MESSAGE( - AnyOf(EqualsProto(R"pb(value { str: "-nan" })pb"), - EqualsProto(R"pb(value { str: "nan" })pb"), - EqualsProto(R"pb(value { str: "-nan(ind)" })pb")))))); + ENCODED_MESSAGE(HasValues( + ElementsAre(AnyOf(EqualsProto(R"pb(str: "-nan")pb"), + EqualsProto(R"pb(str: "nan")pb"), + EqualsProto(R"pb(str: "-nan(ind)")pb")))))))); #else EXPECT_CALL( test_sink, Send(AllOf( TextMessage(MatchesOstream(comparison_stream)), TextMessage(AnyOf(Eq("-nan"), Eq("nan"), Eq("NaN"), Eq("-nan(ind)"))), - ENCODED_MESSAGE( - AnyOf(EqualsProto(R"pb(value { str: "-nan" })pb"), - EqualsProto(R"pb(value { str: "nan" })pb"), - EqualsProto(R"pb(value { str: "-nan(ind)" })pb")))))); + ENCODED_MESSAGE(HasValues( + ElementsAre(AnyOf(EqualsProto(R"pb(str: "-nan")pb"), + EqualsProto(R"pb(str: "nan")pb"), + EqualsProto(R"pb(str: "-nan(ind)")pb")))))))); #endif test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -666,13 +656,12 @@ TYPED_TEST(VoidPtrLogFormatTest, NonNull) { EXPECT_CALL( test_sink, - Send(AllOf( - TextMessage(MatchesOstream(comparison_stream)), - TextMessage( - AnyOf(Eq("0xdeadbeef"), Eq("DEADBEEF"), Eq("00000000DEADBEEF"))), - ENCODED_MESSAGE(AnyOf( - EqualsProto(R"pb(value { str: "0xdeadbeef" })pb"), - EqualsProto(R"pb(value { str: "00000000DEADBEEF" })pb")))))); + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(AnyOf(Eq("0xdeadbeef"), Eq("DEADBEEF"), + Eq("00000000DEADBEEF"))), + ENCODED_MESSAGE(HasValues(ElementsAre( + AnyOf(EqualsProto(R"pb(str: "0xdeadbeef")pb"), + EqualsProto(R"pb(str: "00000000DEADBEEF")pb")))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -694,12 +683,11 @@ TYPED_TEST(VolatilePtrLogFormatTest, Null) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("false")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "false" - })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("false")), + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "false")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -712,12 +700,11 @@ TYPED_TEST(VolatilePtrLogFormatTest, NonNull) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("true")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "true" - })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("true")), + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "true")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -743,7 +730,8 @@ TYPED_TEST(CharPtrLogFormatTest, Null) { Send(AllOf( // `MatchesOstream` deliberately omitted since we deliberately differ. TextMessage(Eq("(null)")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "(null)" })pb"))))); + ENCODED_MESSAGE( + HasValues(ElementsAre(EqualsProto(R"pb(str: "(null)")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -757,12 +745,11 @@ TYPED_TEST(CharPtrLogFormatTest, NonNull) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("value")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "value" - })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("value")), + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "value")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -775,12 +762,11 @@ TEST(BoolLogFormatTest, True) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("true")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "true" - })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("true")), + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "true")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -793,12 +779,11 @@ TEST(BoolLogFormatTest, False) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("false")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "false" - })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("false")), + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "false")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -813,9 +798,8 @@ TEST(LogFormatTest, StringLiteral) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("value")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - literal: "value" - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(literal: "value")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << "value"; @@ -828,12 +812,11 @@ TEST(LogFormatTest, CharArray) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("value")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "value" - })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("value")), + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "value")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -854,9 +837,8 @@ TEST(LogFormatTest, Custom) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("CustomClass{}")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "CustomClass{}" - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "CustomClass{}")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; } @@ -878,12 +860,11 @@ TEST(LogFormatTest, CustomNonCopyable) { auto comparison_stream = ComparisonStream(); comparison_stream << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("CustomClassNonCopyable{}")), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { str: "CustomClassNonCopyable{}" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("CustomClassNonCopyable{}")), + ENCODED_MESSAGE(HasValues(ElementsAre(EqualsProto( + R"pb(str: "CustomClassNonCopyable{}")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value; @@ -906,9 +887,9 @@ TEST(LogFormatTest, AbslStringifyExample) { EXPECT_CALL( test_sink, - Send(AllOf( - TextMessage(Eq("(10, 20)")), TextMessage(Eq(absl::StrCat(p))), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "(10, 20)" })pb"))))); + Send(AllOf(TextMessage(Eq("(10, 20)")), TextMessage(Eq(absl::StrCat(p))), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "(10, 20)")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << p; @@ -937,9 +918,9 @@ TEST(LogFormatTest, CustomWithAbslStringifyAndOstream) { EXPECT_CALL( test_sink, - Send(AllOf( - TextMessage(Eq("(10, 20)")), TextMessage(Eq(absl::StrCat(p))), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "(10, 20)" })pb"))))); + Send(AllOf(TextMessage(Eq("(10, 20)")), TextMessage(Eq(absl::StrCat(p))), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "(10, 20)")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << p; @@ -958,10 +939,10 @@ TEST(LogFormatTest, AbslStringifyStreamsNothing) { PointStreamsNothing p; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(Eq("77")), TextMessage(Eq(absl::StrCat(p, 77))), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" })pb"))))); + EXPECT_CALL(test_sink, Send(AllOf(TextMessage(Eq("77")), + TextMessage(Eq(absl::StrCat(p, 77))), + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "77")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << p << 77; @@ -985,10 +966,10 @@ TEST(LogFormatTest, AbslStringifyMultipleAppend) { EXPECT_CALL( test_sink, - Send(AllOf( - TextMessage(Eq("(10, 20)")), TextMessage(Eq(absl::StrCat(p))), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "(" } - value { str: "10, 20)" })pb"))))); + Send(AllOf(TextMessage(Eq("(10, 20)")), TextMessage(Eq(absl::StrCat(p))), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "(")pb"), + EqualsProto(R"pb(str: "10, 20)")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << p; @@ -1006,12 +987,12 @@ TEST(ManipulatorLogFormatTest, BoolAlphaTrue) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("1 true 1")), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { str: "1" } - value { literal: " " } - value { str: "true" } - value { literal: " " } - value { str: "1" })pb"))))); + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "1")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "true")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "1")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::noboolalpha << value << " " // @@ -1031,12 +1012,12 @@ TEST(ManipulatorLogFormatTest, BoolAlphaFalse) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("0 false 0")), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { str: "0" } - value { literal: " " } - value { str: "false" } - value { literal: " " } - value { str: "0" })pb"))))); + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "0")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "false")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "0")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::noboolalpha << value << " " // @@ -1053,15 +1034,15 @@ TEST(ManipulatorLogFormatTest, ShowPoint) { << std::showpoint << value << " " // << std::noshowpoint << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("77 77.0000 77")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" } - value { literal: " " } - value { str: "77.0000" } - value { literal: " " } - value { str: "77" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("77 77.0000 77")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "77")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "77.0000")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "77")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::noshowpoint << value << " " // @@ -1078,15 +1059,15 @@ TEST(ManipulatorLogFormatTest, ShowPos) { << std::showpos << value << " " // << std::noshowpos << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("77 +77 77")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" } - value { literal: " " } - value { str: "+77" } - value { literal: " " } - value { str: "77" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("77 +77 77")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "77")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "+77")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "77")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::noshowpos << value << " " // @@ -1106,12 +1087,12 @@ TEST(ManipulatorLogFormatTest, UppercaseFloat) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("7.7e+07 7.7E+07 7.7e+07")), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { str: "7.7e+07" } - value { literal: " " } - value { str: "7.7E+07" } - value { literal: " " } - value { str: "7.7e+07" })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "7.7e+07")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "7.7E+07")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "7.7e+07")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::nouppercase << value << " " // @@ -1126,12 +1107,11 @@ TEST(ManipulatorLogFormatTest, Hex) { auto comparison_stream = ComparisonStream(); comparison_stream << std::hex << value; - EXPECT_CALL( - test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("0x77")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "0x77" - })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("0x77")), + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "0x77")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::hex << value; } @@ -1143,11 +1123,11 @@ TEST(ManipulatorLogFormatTest, Oct) { auto comparison_stream = ComparisonStream(); comparison_stream << std::oct << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("077")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "077" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("077")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "077")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::oct << value; @@ -1160,11 +1140,11 @@ TEST(ManipulatorLogFormatTest, Dec) { auto comparison_stream = ComparisonStream(); comparison_stream << std::hex << std::dec << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("77")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("77")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "77")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::hex << std::dec << value; @@ -1180,15 +1160,15 @@ TEST(ManipulatorLogFormatTest, ShowbaseHex) { << std::showbase << value << " " // << std::noshowbase << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("77 0x77 77")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" } - value { literal: " " } - value { str: "0x77" } - value { literal: " " } - value { str: "77" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("77 0x77 77")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "77")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "0x77")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "77")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::hex // @@ -1207,15 +1187,15 @@ TEST(ManipulatorLogFormatTest, ShowbaseOct) { << std::showbase << value << " " // << std::noshowbase << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("77 077 77")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" } - value { literal: " " } - value { str: "077" } - value { literal: " " } - value { str: "77" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("77 077 77")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "77")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "077")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "77")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::oct // @@ -1238,12 +1218,12 @@ TEST(ManipulatorLogFormatTest, UppercaseHex) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("0xbeef 0XBEEF 0xbeef")), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { str: "0xbeef" } - value { literal: " " } - value { str: "0XBEEF" } - value { literal: " " } - value { str: "0xbeef" })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "0xbeef")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "0XBEEF")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "0xbeef")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::hex // @@ -1259,13 +1239,11 @@ TEST(ManipulatorLogFormatTest, FixedFloat) { auto comparison_stream = ComparisonStream(); comparison_stream << std::fixed << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("77000000.000000")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "77000000.000000" - })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("77000000.000000")), + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "77000000.000000")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::fixed << value; @@ -1281,9 +1259,8 @@ TEST(ManipulatorLogFormatTest, ScientificFloat) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("7.700000e+07")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "7.700000e+07" - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "7.700000e+07")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::scientific << value; @@ -1309,11 +1286,9 @@ TEST(ManipulatorLogFormatTest, FixedAndScientificFloat) { Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(AnyOf(Eq("0x1.25bb50p+26"), Eq("0x1.25bb5p+26"), Eq("0x1.25bb500000000p+26"))), - ENCODED_MESSAGE( - AnyOf(EqualsProto(R"pb(value { str: "0x1.25bb5p+26" })pb"), - EqualsProto(R"pb(value { - str: "0x1.25bb500000000p+26" - })pb")))))); + ENCODED_MESSAGE(HasValues(ElementsAre(AnyOf( + EqualsProto(R"pb(str: "0x1.25bb5p+26")pb"), + EqualsProto(R"pb(str: "0x1.25bb500000000p+26")pb")))))))); test_sink.StartCapturingLogs(); @@ -1342,11 +1317,9 @@ TEST(ManipulatorLogFormatTest, HexfloatFloat) { Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(AnyOf(Eq("0x1.25bb50p+26"), Eq("0x1.25bb5p+26"), Eq("0x1.25bb500000000p+26"))), - ENCODED_MESSAGE( - AnyOf(EqualsProto(R"pb(value { str: "0x1.25bb5p+26" })pb"), - EqualsProto(R"pb(value { - str: "0x1.25bb500000000p+26" - })pb")))))); + ENCODED_MESSAGE(HasValues(ElementsAre(AnyOf( + EqualsProto(R"pb(str: "0x1.25bb5p+26")pb"), + EqualsProto(R"pb(str: "0x1.25bb500000000p+26")pb")))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::hexfloat << value; @@ -1363,9 +1336,8 @@ TEST(ManipulatorLogFormatTest, DefaultFloatFloat) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("7.7e+07")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "7.7e+07" - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "7.7e+07")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::hexfloat << std::defaultfloat << value; @@ -1377,11 +1349,11 @@ TEST(ManipulatorLogFormatTest, Ends) { auto comparison_stream = ComparisonStream(); comparison_stream << std::ends; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq(absl::string_view("\0", 1))), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "\0" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq(absl::string_view("\0", 1))), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "\0")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::ends; @@ -1398,7 +1370,8 @@ TEST(ManipulatorLogFormatTest, Endl) { Send(AllOf( TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("\n")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "\n" })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre(EqualsProto(R"pb(str: + "\n")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::endl; @@ -1422,10 +1395,10 @@ TEST(ManipulatorLogFormatTest, SetIosFlags) { // `std::setiosflags` and `std::resetiosflags` aren't manipulators. // We're unable to distinguish their return type(s) from arbitrary // user-defined types and thus don't suppress the empty str value. - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "0x77" } - value { literal: " " } - value { str: "119" } - )pb"))))); + ENCODED_MESSAGE( + HasValues(ElementsAre(EqualsProto(R"pb(str: "0x77")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "119")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::resetiosflags(std::ios_base::basefield) @@ -1449,10 +1422,10 @@ TEST(ManipulatorLogFormatTest, SetBase) { // `std::setbase` isn't a manipulator. We're unable to // distinguish its return type from arbitrary user-defined // types and thus don't suppress the empty str value. - ENCODED_MESSAGE(EqualsProto( - R"pb(value { str: "0x77" } - value { literal: " " } - value { str: "119" })pb"))))); + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "0x77")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "119")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::setbase(16) << value << " " // @@ -1468,13 +1441,13 @@ TEST(ManipulatorLogFormatTest, SetPrecision) { EXPECT_CALL( test_sink, - Send(AllOf( - TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("6.022e+23")), - // `std::setprecision` isn't a manipulator. We're unable to - // distinguish its return type from arbitrary user-defined - // types and thus don't suppress the empty str value. - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "6.022e+23" })pb"))))); + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("6.022e+23")), + // `std::setprecision` isn't a manipulator. We're unable to + // distinguish its return type from arbitrary user-defined + // types and thus don't suppress the empty str value. + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "6.022e+23")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::setprecision(4) << value; @@ -1487,12 +1460,11 @@ TEST(ManipulatorLogFormatTest, SetPrecisionOverflow) { auto comparison_stream = ComparisonStream(); comparison_stream << std::setprecision(200) << value; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("602214085700000015187968")), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { str: "602214085700000015187968" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("602214085700000015187968")), + ENCODED_MESSAGE(HasValues(ElementsAre(EqualsProto( + R"pb(str: "602214085700000015187968")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::setprecision(200) << value; @@ -1507,13 +1479,13 @@ TEST(ManipulatorLogFormatTest, SetW) { EXPECT_CALL( test_sink, - Send(AllOf( - TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq(" 77")), - // `std::setw` isn't a manipulator. We're unable to - // distinguish its return type from arbitrary user-defined - // types and thus don't suppress the empty str value. - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: " 77" })pb"))))); + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq(" 77")), + // `std::setw` isn't a manipulator. We're unable to + // distinguish its return type from arbitrary user-defined + // types and thus don't suppress the empty str value. + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: " 77")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::setw(8) << value; @@ -1529,9 +1501,8 @@ TEST(ManipulatorLogFormatTest, Left) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("-77 ")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "-77 " - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "-77 ")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::left << std::setw(8) << value; @@ -1547,9 +1518,8 @@ TEST(ManipulatorLogFormatTest, Right) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq(" -77")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: " -77" - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: " -77")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::right << std::setw(8) << value; @@ -1565,9 +1535,8 @@ TEST(ManipulatorLogFormatTest, Internal) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("- 77")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "- 77" - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "- 77")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::internal << std::setw(8) << value; @@ -1587,9 +1556,8 @@ TEST(ManipulatorLogFormatTest, SetFill) { // unable to distinguish its return // type from arbitrary user-defined types and // thus don't suppress the empty str value. - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "00000077" - })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "00000077")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::setfill('0') << std::setw(8) << value; @@ -1610,10 +1578,10 @@ TEST(ManipulatorLogFormatTest, FromCustom) { EXPECT_CALL(test_sink, Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), TextMessage(Eq("FromCustomClass{} 0x77")), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { str: "FromCustomClass{}" } - value { literal: " " } - value { str: "0x77" })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(str: "FromCustomClass{}")pb"), + EqualsProto(R"pb(literal: " ")pb"), + EqualsProto(R"pb(str: "0x77")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value << " " << 0x77; @@ -1629,11 +1597,11 @@ TEST(ManipulatorLogFormatTest, CustomClassStreamsNothing) { auto comparison_stream = ComparisonStream(); comparison_stream << value << 77; - EXPECT_CALL( - test_sink, - Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), - TextMessage(Eq("77")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "77" })pb"))))); + EXPECT_CALL(test_sink, + Send(AllOf(TextMessage(MatchesOstream(comparison_stream)), + TextMessage(Eq("77")), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "77")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << value << 77; @@ -1656,9 +1624,9 @@ TEST(ManipulatorLogFormatTest, IOManipsDoNotAffectAbslStringify) { EXPECT_CALL( test_sink, - Send(AllOf( - TextMessage(Eq("(10, 20)")), TextMessage(Eq(absl::StrCat(p))), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "(10, 20)" })pb"))))); + Send(AllOf(TextMessage(Eq("(10, 20)")), TextMessage(Eq(absl::StrCat(p))), + ENCODED_MESSAGE(HasValues( + ElementsAre(EqualsProto(R"pb(str: "(10, 20)")pb"))))))); test_sink.StartCapturingLogs(); LOG(INFO) << std::hex << p; diff --git a/absl/log/log_modifier_methods_test.cc b/absl/log/log_modifier_methods_test.cc index 42e13b1b..4ccde404 100644 --- a/absl/log/log_modifier_methods_test.cc +++ b/absl/log/log_modifier_methods_test.cc @@ -156,9 +156,11 @@ TEST(TailCallsModifiesTest, WithMetadataFrom) { Timestamp(Eq(absl::UnixEpoch())), ThreadID(Eq(absl::LogEntry::tid_t{456})), TextMessage(Eq("forwarded: hello world")), Verbosity(Eq(7)), - ENCODED_MESSAGE( - EqualsProto(R"pb(value { literal: "forwarded: " } - value { str: "hello world" })pb"))))); + ENCODED_MESSAGE(MatchesEvent( + Eq("fake/file"), Eq(123), Eq(absl::UnixEpoch()), + Eq(logging::proto::WARNING), Eq(456), + ElementsAre(EqualsProto(R"pb(literal: "forwarded: ")pb"), + EqualsProto(R"pb(str: "hello world")pb"))))))); test_sink.StartCapturingLogs(); LOG(WARNING) @@ -179,25 +181,15 @@ TEST(TailCallsModifiesTest, WithPerror) { Send(AllOf(TextMessage(AnyOf(Eq("hello world: Bad file number [9]"), Eq("hello world: Bad file descriptor [9]"), Eq("hello world: Bad file descriptor [8]"))), - ENCODED_MESSAGE( - AnyOf(EqualsProto(R"pb(value { literal: "hello world" } - value { literal: ": " } - value { str: "Bad file number" } - value { literal: " [" } - value { str: "9" } - value { literal: "]" })pb"), - EqualsProto(R"pb(value { literal: "hello world" } - value { literal: ": " } - value { str: "Bad file descriptor" } - value { literal: " [" } - value { str: "9" } - value { literal: "]" })pb"), - EqualsProto(R"pb(value { literal: "hello world" } - value { literal: ": " } - value { str: "Bad file descriptor" } - value { literal: " [" } - value { str: "8" } - value { literal: "]" })pb")))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(literal: "hello world")pb"), + EqualsProto(R"pb(literal: ": ")pb"), + AnyOf(EqualsProto(R"pb(str: "Bad file number")pb"), + EqualsProto(R"pb(str: "Bad file descriptor")pb")), + EqualsProto(R"pb(literal: " [")pb"), + AnyOf(EqualsProto(R"pb(str: "8")pb"), + EqualsProto(R"pb(str: "9")pb")), + EqualsProto(R"pb(literal: "]")pb"))))))); test_sink.StartCapturingLogs(); errno = EBADF; diff --git a/absl/log/log_streamer_test.cc b/absl/log/log_streamer_test.cc index 40c7d488..b9b94282 100644 --- a/absl/log/log_streamer_test.cc +++ b/absl/log/log_streamer_test.cc @@ -38,6 +38,7 @@ using ::absl::log_internal::DeathTestValidateExpectations; #if GTEST_HAS_DEATH_TEST using ::absl::log_internal::DiedOfFatal; #endif +using ::absl::log_internal::InMatchWindow; using ::absl::log_internal::LogSeverity; using ::absl::log_internal::Prefix; using ::absl::log_internal::SourceFilename; @@ -45,7 +46,8 @@ using ::absl::log_internal::SourceLine; using ::absl::log_internal::Stacktrace; using ::absl::log_internal::TextMessage; using ::absl::log_internal::ThreadID; -using ::absl::log_internal::TimestampInMatchWindow; +using ::absl::log_internal::Timestamp; +using ::testing::_; using ::testing::AnyNumber; using ::testing::Eq; using ::testing::HasSubstr; @@ -67,15 +69,17 @@ TEST(LogStreamerTest, LogInfoStreamer) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), - Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kInfo)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("WriteToStream: foo")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "WriteToStream: foo" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), + Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kInfo)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("WriteToStream: foo")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), Eq(1234), InMatchWindow(), + Eq(logging::proto::INFO), Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(str: "WriteToStream: foo")pb")))), + Stacktrace(IsEmpty())))); test_sink.StartCapturingLogs(); WriteToStream("foo", &absl::LogInfoStreamer("path/file.cc", 1234).stream()); @@ -86,15 +90,17 @@ TEST(LogStreamerTest, LogWarningStreamer) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), - Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kWarning)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("WriteToStream: foo")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "WriteToStream: foo" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), + Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kWarning)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("WriteToStream: foo")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), Eq(1234), InMatchWindow(), + Eq(logging::proto::WARNING), Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(str: "WriteToStream: foo")pb")))), + Stacktrace(IsEmpty())))); test_sink.StartCapturingLogs(); WriteToStream("foo", @@ -106,15 +112,17 @@ TEST(LogStreamerTest, LogErrorStreamer) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), - Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kError)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("WriteToStream: foo")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "WriteToStream: foo" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), + Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kError)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("WriteToStream: foo")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), Eq(1234), InMatchWindow(), + Eq(logging::proto::ERROR), Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(str: "WriteToStream: foo")pb")))), + Stacktrace(IsEmpty())))); test_sink.StartCapturingLogs(); WriteToStream("foo", &absl::LogErrorStreamer("path/file.cc", 1234).stream()); @@ -130,17 +138,19 @@ TEST(LogStreamerDeathTest, LogFatalStreamer) { .Times(AnyNumber()) .WillRepeatedly(DeathTestUnexpectedLogging()); - EXPECT_CALL( - test_sink, - Send(AllOf( - SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), - Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("WriteToStream: foo")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "WriteToStream: foo" - })pb"))))) + EXPECT_CALL(test_sink, + Send(AllOf(SourceFilename(Eq("path/file.cc")), + SourceLine(Eq(1234)), Prefix(IsTrue()), + LogSeverity(Eq(absl::LogSeverity::kFatal)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("WriteToStream: foo")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), Eq(1234), + InMatchWindow(), Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(str: "WriteToStream: foo")pb"))))))) .WillOnce(DeathTestExpectedLogging()); test_sink.StartCapturingLogs(); @@ -157,15 +167,17 @@ TEST(LogStreamerTest, LogDebugFatalStreamer) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), - Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kError)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("WriteToStream: foo")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "WriteToStream: foo" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), + Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kError)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("WriteToStream: foo")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), Eq(1234), InMatchWindow(), + Eq(logging::proto::ERROR), Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(str: "WriteToStream: foo")pb")))), + Stacktrace(IsEmpty())))); test_sink.StartCapturingLogs(); WriteToStream("foo", @@ -181,17 +193,19 @@ TEST(LogStreamerDeathTest, LogDebugFatalStreamer) { .Times(AnyNumber()) .WillRepeatedly(DeathTestUnexpectedLogging()); - EXPECT_CALL( - test_sink, - Send(AllOf( - SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), - Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("WriteToStream: foo")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "WriteToStream: foo" - })pb"))))) + EXPECT_CALL(test_sink, + Send(AllOf(SourceFilename(Eq("path/file.cc")), + SourceLine(Eq(1234)), Prefix(IsTrue()), + LogSeverity(Eq(absl::LogSeverity::kFatal)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("WriteToStream: foo")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), Eq(1234), + InMatchWindow(), Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(str: "WriteToStream: foo")pb"))))))) .WillOnce(DeathTestExpectedLogging()); test_sink.StartCapturingLogs(); @@ -207,15 +221,17 @@ TEST(LogStreamerTest, LogStreamer) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), - Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kError)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("WriteToStream: foo")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "WriteToStream: foo" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), + Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kError)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("WriteToStream: foo")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), Eq(1234), InMatchWindow(), + Eq(logging::proto::ERROR), Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto(R"pb(str: "WriteToStream: foo")pb")))), + Stacktrace(IsEmpty())))); test_sink.StartCapturingLogs(); WriteToStream( @@ -233,17 +249,19 @@ TEST(LogStreamerDeathTest, LogStreamer) { .Times(AnyNumber()) .WillRepeatedly(DeathTestUnexpectedLogging()); - EXPECT_CALL( - test_sink, - Send(AllOf( - SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), - Prefix(IsTrue()), LogSeverity(Eq(absl::LogSeverity::kFatal)), - TimestampInMatchWindow(), - ThreadID(Eq(absl::base_internal::GetTID())), - TextMessage(Eq("WriteToStream: foo")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "WriteToStream: foo" - })pb"))))) + EXPECT_CALL(test_sink, + Send(AllOf(SourceFilename(Eq("path/file.cc")), + SourceLine(Eq(1234)), Prefix(IsTrue()), + LogSeverity(Eq(absl::LogSeverity::kFatal)), + Timestamp(InMatchWindow()), + ThreadID(Eq(absl::base_internal::GetTID())), + TextMessage(Eq("WriteToStream: foo")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), Eq(1234), + InMatchWindow(), Eq(logging::proto::FATAL), + Eq(absl::base_internal::GetTID()), + ElementsAre(EqualsProto( + R"pb(str: "WriteToStream: foo")pb"))))))) .WillOnce(DeathTestExpectedLogging()); test_sink.StartCapturingLogs(); @@ -260,12 +278,13 @@ TEST(LogStreamerTest, PassedByReference) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), - TextMessage(Eq("WriteToStreamRef: foo")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "WriteToStreamRef: foo" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), + TextMessage(Eq("WriteToStreamRef: foo")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), Eq(1234), _, _, _, + ElementsAre(EqualsProto(R"pb(str: "WriteToStreamRef: foo")pb")))), + Stacktrace(IsEmpty())))); test_sink.StartCapturingLogs(); WriteToStreamRef("foo", absl::LogInfoStreamer("path/file.cc", 1234).stream()); @@ -284,13 +303,14 @@ TEST(LogStreamerTest, StoredAsLocal) { // test would fail. EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), - TextMessage(Eq("WriteToStream: foo WriteToStreamRef: bar")), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { - str: "WriteToStream: foo WriteToStreamRef: bar" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), + TextMessage(Eq("WriteToStream: foo WriteToStreamRef: bar")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), Eq(1234), _, _, _, + ElementsAre(EqualsProto( + R"pb(str: "WriteToStream: foo WriteToStreamRef: bar")pb")))), + Stacktrace(IsEmpty())))); test_sink.StartCapturingLogs(); } @@ -311,12 +331,13 @@ TEST(LogStreamerDeathTest, StoredAsLocal) { TEST(LogStreamerTest, LogsEmptyLine) { absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected); - EXPECT_CALL(test_sink, Send(AllOf(SourceFilename(Eq("path/file.cc")), - SourceLine(Eq(1234)), TextMessage(Eq("")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "" - })pb")), - Stacktrace(IsEmpty())))); + EXPECT_CALL(test_sink, + Send(AllOf(SourceFilename(Eq("path/file.cc")), + SourceLine(Eq(1234)), TextMessage(Eq("")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), Eq(1234), _, _, _, + ElementsAre(EqualsProto(R"pb(str: "")pb")))), + Stacktrace(IsEmpty())))); test_sink.StartCapturingLogs(); absl::LogInfoStreamer("path/file.cc", 1234); @@ -334,9 +355,10 @@ TEST(LogStreamerDeathTest, LogsEmptyLine) { EXPECT_CALL( test_sink, - Send(AllOf( - SourceFilename(Eq("path/file.cc")), TextMessage(Eq("")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "" })pb"))))) + Send(AllOf(SourceFilename(Eq("path/file.cc")), TextMessage(Eq("")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), _, _, _, _, + ElementsAre(EqualsProto(R"pb(str: "")pb"))))))) .WillOnce(DeathTestExpectedLogging()); test_sink.StartCapturingLogs(); @@ -352,13 +374,14 @@ TEST(LogStreamerTest, MoveConstruction) { EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), - LogSeverity(Eq(absl::LogSeverity::kInfo)), - TextMessage(Eq("hello 0x10 world 0x10")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "hello 0x10 world 0x10" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), + LogSeverity(Eq(absl::LogSeverity::kInfo)), + TextMessage(Eq("hello 0x10 world 0x10")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), Eq(1234), _, Eq(logging::proto::INFO), _, + ElementsAre(EqualsProto(R"pb(str: "hello 0x10 world 0x10")pb")))), + Stacktrace(IsEmpty())))); test_sink.StartCapturingLogs(); auto streamer1 = absl::LogInfoStreamer("path/file.cc", 1234); @@ -373,22 +396,24 @@ TEST(LogStreamerTest, MoveAssignment) { testing::InSequence seq; EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq("path/file2.cc")), SourceLine(Eq(5678)), - LogSeverity(Eq(absl::LogSeverity::kWarning)), - TextMessage(Eq("something else")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "something else" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq("path/file2.cc")), SourceLine(Eq(5678)), + LogSeverity(Eq(absl::LogSeverity::kWarning)), + TextMessage(Eq("something else")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file2.cc"), Eq(5678), _, Eq(logging::proto::WARNING), _, + ElementsAre(EqualsProto(R"pb(str: "something else")pb")))), + Stacktrace(IsEmpty())))); EXPECT_CALL( test_sink, - Send(AllOf(SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), - LogSeverity(Eq(absl::LogSeverity::kInfo)), - TextMessage(Eq("hello 0x10 world 0x10")), - ENCODED_MESSAGE(EqualsProto(R"pb(value { - str: "hello 0x10 world 0x10" - })pb")), - Stacktrace(IsEmpty())))); + Send(AllOf( + SourceFilename(Eq("path/file.cc")), SourceLine(Eq(1234)), + LogSeverity(Eq(absl::LogSeverity::kInfo)), + TextMessage(Eq("hello 0x10 world 0x10")), + ENCODED_MESSAGE(MatchesEvent( + Eq("path/file.cc"), Eq(1234), _, Eq(logging::proto::INFO), _, + ElementsAre(EqualsProto(R"pb(str: "hello 0x10 world 0x10")pb")))), + Stacktrace(IsEmpty())))); test_sink.StartCapturingLogs(); auto streamer1 = absl::LogInfoStreamer("path/file.cc", 1234); diff --git a/absl/log/structured_test.cc b/absl/log/structured_test.cc index 490a35d8..6f1df186 100644 --- a/absl/log/structured_test.cc +++ b/absl/log/structured_test.cc @@ -30,6 +30,7 @@ namespace { using ::absl::log_internal::MatchesOstream; using ::absl::log_internal::TextMessage; +using ::testing::ElementsAre; using ::testing::Eq; auto *test_env ABSL_ATTRIBUTE_UNUSED = ::testing::AddGlobalTestEnvironment( @@ -53,8 +54,8 @@ TEST(StreamingFormatTest, LogAsLiteral) { EXPECT_CALL(sink, Send(AllOf(TextMessage(MatchesOstream(stream)), TextMessage(Eq("hello world")), - ENCODED_MESSAGE(EqualsProto( - R"pb(value { literal: "hello world" })pb"))))); + ENCODED_MESSAGE(HasValues(ElementsAre( + EqualsProto(R"pb(literal: "hello world")pb"))))))); sink.StartCapturingLogs(); LOG(INFO) << absl::LogAsLiteral(not_a_literal); |