Files
carbon-lang/common/check_test.cpp
T
Geoff RomerandJon Meow 33dd9a873d Debugging quality-of-life improvements (#810)
* Debugging quality-of-life improvements

- Use std::abort for `CHECK`/`FATAL` failures, which acts as a debugger breakpoint as well as automatically printing a stack trace.
- Re-enable printing continuations in `--trace` mode.
- Log the source location of each step in `--trace` mode.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-09-08 09:25:16 -07:00

49 lines
1.1 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "common/check.h"
#include "gtest/gtest.h"
namespace Carbon {
TEST(CheckTest, CheckTrue) { CHECK(true); }
TEST(CheckTest, CheckFalse) {
ASSERT_DEATH({ CHECK(false); }, "CHECK failure: false\n");
}
TEST(CheckTest, CheckTrueCallbackNotUsed) {
bool called = false;
auto callback = [&]() {
called = true;
return "called";
};
CHECK(true) << callback();
EXPECT_FALSE(called);
}
TEST(CheckTest, CheckFalseMessage) {
ASSERT_DEATH({ CHECK(false) << "msg"; }, "CHECK failure: false: msg\n");
}
TEST(CheckTest, CheckOutputForms) {
const char msg[] = "msg";
std::string str = "str";
int i = 1;
CHECK(true) << msg << str << i << 0;
}
TEST(CheckTest, Fatal) {
ASSERT_DEATH({ FATAL() << "msg"; }, "FATAL: msg\n");
}
auto FatalNoReturnRequired() -> int { FATAL() << "msg"; }
TEST(ErrorTest, FatalNoReturnRequired) {
ASSERT_DEATH({ FatalNoReturnRequired(); }, "FATAL: msg\n");
}
} // namespace Carbon