Files
carbon-lang/explorer/common/error_builders_test.cpp
T
Richard Smith 8f0f69b65f Remove RuntimeError / CompilationError. (#2258)
Instead, work out the prefix for an error based on whether it was produced during parsing, semantic analysis, or when running the program.
2022-10-04 15:39:04 -07:00

30 lines
766 B
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 "explorer/common/error_builders.h"
#include <gtest/gtest.h>
#include "explorer/common/source_location.h"
namespace Carbon::Testing {
namespace {
auto ToString(const Error& err) -> std::string {
std::string result;
llvm::raw_string_ostream out(result);
err.Print(out);
return result;
}
TEST(ErrorBuildersTest, ProgramError) {
Error err = ProgramError(SourceLocation("x", 1)) << "test";
EXPECT_EQ(err.location(), "x:1");
EXPECT_EQ(err.message(), "test");
EXPECT_EQ(ToString(err), "x:1: test");
}
} // namespace
} // namespace Carbon::Testing