// Copyright 2022 The Abseil Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // ----------------------------------------------------------------------------- // File: log/internal/test_matchers.h // ----------------------------------------------------------------------------- // // This file declares Googletest's matchers used in the Abseil Logging library // unit tests. #ifndef ABSL_LOG_INTERNAL_TEST_MATCHERS_H_ #define ABSL_LOG_INTERNAL_TEST_MATCHERS_H_ #include #include #include #include "gmock/gmock.h" #include "gtest/gtest.h" #include "absl/base/config.h" #include "absl/base/log_severity.h" #include "absl/log/internal/config.h" #include "absl/log/internal/test_helpers.h" #include "absl/log/log_entry.h" #include "absl/strings/string_view.h" #include "absl/time/time.h" namespace absl { ABSL_NAMESPACE_BEGIN namespace log_internal { // These matchers correspond to the components of `absl::LogEntry`. ::testing::Matcher SourceFilename( const ::testing::Matcher& source_filename); ::testing::Matcher SourceBasename( const ::testing::Matcher& source_basename); // Be careful with this one; multi-line statements using `__LINE__` evaluate // differently on different platforms. In particular, the MSVC implementation // of `EXPECT_DEATH` returns the line number of the macro expansion to all lines // within the code block that's expected to die. ::testing::Matcher SourceLine( const ::testing::Matcher& source_line); ::testing::Matcher Prefix( const ::testing::Matcher& prefix); ::testing::Matcher LogSeverity( const ::testing::Matcher& log_severity); ::testing::Matcher Timestamp( const ::testing::Matcher& 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 TimestampInMatchWindow(); ::testing::Matcher ThreadID( const ::testing::Matcher&); ::testing::Matcher TextMessageWithPrefixAndNewline( const ::testing::Matcher& text_message_with_prefix_and_newline); ::testing::Matcher TextMessageWithPrefix( const ::testing::Matcher& text_message_with_prefix); ::testing::Matcher TextMessage( const ::testing::Matcher& text_message); ::testing::Matcher TextPrefix( const ::testing::Matcher& text_prefix); ::testing::Matcher Verbosity( const ::testing::Matcher& verbosity); ::testing::Matcher Stacktrace( const ::testing::Matcher& stacktrace); // Behaves as `Eq(stream.str())`, but produces better failure messages. ::testing::Matcher MatchesOstream( const std::ostringstream& stream); ::testing::Matcher DeathTestValidateExpectations(); // This feature coming soon =). #define ENCODED_MESSAGE(message_matcher) ::testing::_ } // namespace log_internal ABSL_NAMESPACE_END } // namespace absl #endif // ABSL_LOG_INTERNAL_TEST_MATCHERS_H_