check_test.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "common/check.h"
  5. #include <gtest/gtest.h>
  6. namespace Carbon::Testing {
  7. namespace {
  8. TEST(CheckTest, CheckTrue) { CHECK(true); }
  9. TEST(CheckTest, CheckFalse) {
  10. // TODO: figure out why we can't use \\d+ instead of .+ in these patterns.
  11. ASSERT_DEATH({ CHECK(false); },
  12. "CHECK failure at common/check_test.cpp:.+: false\n");
  13. }
  14. TEST(CheckTest, CheckTrueCallbackNotUsed) {
  15. bool called = false;
  16. auto callback = [&]() {
  17. called = true;
  18. return "called";
  19. };
  20. CHECK(true) << callback();
  21. EXPECT_FALSE(called);
  22. }
  23. TEST(CheckTest, CheckFalseMessage) {
  24. ASSERT_DEATH({ CHECK(false) << "msg"; },
  25. "CHECK failure at common/check_test.cpp:.+: false: msg\n");
  26. }
  27. TEST(CheckTest, CheckOutputForms) {
  28. const char msg[] = "msg";
  29. std::string str = "str";
  30. int i = 1;
  31. CHECK(true) << msg << str << i << 0;
  32. }
  33. TEST(CheckTest, Fatal) {
  34. ASSERT_DEATH({ FATAL() << "msg"; },
  35. "FATAL failure at common/check_test.cpp:.+: msg\n");
  36. }
  37. auto FatalNoReturnRequired() -> int { FATAL() << "msg"; }
  38. TEST(ErrorTest, FatalNoReturnRequired) {
  39. ASSERT_DEATH({ FatalNoReturnRequired(); },
  40. "FATAL failure at common/check_test.cpp:.+: msg\n");
  41. }
  42. } // namespace
  43. } // namespace Carbon::Testing