check_test.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 {
  7. TEST(CheckTest, CheckTrue) { CHECK(true); }
  8. TEST(CheckTest, CheckFalse) {
  9. ASSERT_DEATH({ CHECK(false); }, "CHECK failure: false\n");
  10. }
  11. TEST(CheckTest, CheckTrueCallbackNotUsed) {
  12. bool called = false;
  13. auto callback = [&]() {
  14. called = true;
  15. return "called";
  16. };
  17. CHECK(true) << callback();
  18. EXPECT_FALSE(called);
  19. }
  20. TEST(CheckTest, CheckFalseMessage) {
  21. ASSERT_DEATH({ CHECK(false) << "msg"; }, "CHECK failure: false: msg\n");
  22. }
  23. TEST(CheckTest, CheckOutputForms) {
  24. const char msg[] = "msg";
  25. std::string str = "str";
  26. int i = 1;
  27. CHECK(true) << msg << str << i << 0;
  28. }
  29. TEST(CheckTest, Fatal) {
  30. ASSERT_DEATH({ FATAL() << "msg"; }, "FATAL: msg\n");
  31. }
  32. auto FatalNoReturnRequired() -> int { FATAL() << "msg"; }
  33. TEST(ErrorTest, FatalNoReturnRequired) {
  34. ASSERT_DEATH({ FatalNoReturnRequired(); }, "FATAL: msg\n");
  35. }
  36. } // namespace Carbon