test_helpers.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2022 The Abseil Authors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // -----------------------------------------------------------------------------
  16. // File: log/internal/test_helpers.h
  17. // -----------------------------------------------------------------------------
  18. //
  19. // This file declares testing helpers for the logging library.
  20. #ifndef ABSL_LOG_INTERNAL_TEST_HELPERS_H_
  21. #define ABSL_LOG_INTERNAL_TEST_HELPERS_H_
  22. #include "gtest/gtest.h"
  23. #include "absl/base/config.h"
  24. #include "absl/base/log_severity.h"
  25. #include "absl/log/globals.h"
  26. namespace absl {
  27. ABSL_NAMESPACE_BEGIN
  28. namespace log_internal {
  29. // `ABSL_MIN_LOG_LEVEL` can't be used directly since it is not always defined.
  30. constexpr auto kAbslMinLogLevel =
  31. #ifdef ABSL_MIN_LOG_LEVEL
  32. static_cast<absl::LogSeverityAtLeast>(ABSL_MIN_LOG_LEVEL);
  33. #else
  34. absl::LogSeverityAtLeast::kInfo;
  35. #endif
  36. // Returns false if the specified severity level is disabled by
  37. // `ABSL_MIN_LOG_LEVEL` or `absl::MinLogLevel()`.
  38. bool LoggingEnabledAt(absl::LogSeverity severity);
  39. // -----------------------------------------------------------------------------
  40. // Googletest Death Test Predicates
  41. // -----------------------------------------------------------------------------
  42. #if GTEST_HAS_DEATH_TEST
  43. bool DiedOfFatal(int exit_status);
  44. bool DiedOfQFatal(int exit_status);
  45. #endif
  46. // -----------------------------------------------------------------------------
  47. // Helper for Log initialization in test
  48. // -----------------------------------------------------------------------------
  49. class LogTestEnvironment : public ::testing::Environment {
  50. public:
  51. ~LogTestEnvironment() override = default;
  52. void SetUp() override;
  53. };
  54. } // namespace log_internal
  55. ABSL_NAMESPACE_END
  56. } // namespace absl
  57. #endif // ABSL_LOG_INTERNAL_TEST_HELPERS_H_