error_test.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 "executable_semantics/common/error.h"
  5. #include "gtest/gtest.h"
  6. namespace Carbon {
  7. namespace {
  8. TEST(ErrorTest, FatalUserError) {
  9. ASSERT_DEATH({ FATAL_RUNTIME_ERROR_NO_LINE() << "test"; }, "ERROR: test\n");
  10. }
  11. TEST(ErrorTest, FatalRuntimeError) {
  12. ASSERT_DEATH({ FATAL_RUNTIME_ERROR_NO_LINE() << "test"; },
  13. "RUNTIME ERROR: test\n");
  14. }
  15. TEST(ErrorTest, FatalCompilationError) {
  16. ASSERT_DEATH({ FATAL_COMPILATION_ERROR_NO_LINE() << "test"; },
  17. "COMPILATION ERROR: test\n");
  18. }
  19. TEST(ErrorTest, FatalUserErrorLine) {
  20. ASSERT_DEATH({ FATAL_USER_ERROR(1) << "test"; }, "ERROR: 1: test\n");
  21. }
  22. auto NoReturnRequired() -> int { FATAL_USER_ERROR_NO_LINE() << "test"; }
  23. TEST(ErrorTest, NoReturnRequired) {
  24. ASSERT_DEATH({ NoReturnRequired(); }, "ERROR: test\n");
  25. }
  26. } // namespace
  27. } // namespace Carbon