check_test.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. // TODO: figure out why we can't use \\d+ instead of .+ in these patterns.
  10. ASSERT_DEATH({ CHECK(false); },
  11. "CHECK failure at common/check_test.cpp:.+: false\n");
  12. }
  13. TEST(CheckTest, CheckTrueCallbackNotUsed) {
  14. bool called = false;
  15. auto callback = [&]() {
  16. called = true;
  17. return "called";
  18. };
  19. CHECK(true) << callback();
  20. EXPECT_FALSE(called);
  21. }
  22. TEST(CheckTest, CheckFalseMessage) {
  23. ASSERT_DEATH({ CHECK(false) << "msg"; },
  24. "CHECK failure at common/check_test.cpp:.+: false: msg\n");
  25. }
  26. TEST(CheckTest, CheckOutputForms) {
  27. const char msg[] = "msg";
  28. std::string str = "str";
  29. int i = 1;
  30. CHECK(true) << msg << str << i << 0;
  31. }
  32. TEST(CheckTest, Fatal) {
  33. ASSERT_DEATH({ FATAL() << "msg"; },
  34. "FATAL failure at common/check_test.cpp:.+: msg\n");
  35. }
  36. auto FatalNoReturnRequired() -> int { FATAL() << "msg"; }
  37. TEST(ErrorTest, FatalNoReturnRequired) {
  38. ASSERT_DEATH({ FatalNoReturnRequired(); },
  39. "FATAL failure at common/check_test.cpp:.+: msg\n");
  40. }
  41. } // namespace Carbon