mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 09:11:05 +01:00
Error: track message and prefix/location separately. (#1529)
This allows us to combine multiple Errors together without repeating the prefix information. Also fixes several cases where two "COMPILATION ERROR" prefixes would be prepended to the same message when errors with prefixes and locations were produced by the lexer and parser.
This commit is contained in:
@@ -11,19 +11,35 @@
|
||||
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, CompilationError) {
|
||||
Error err = CompilationError(SourceLocation("x", 1)) << "test";
|
||||
EXPECT_EQ(err.message(), "COMPILATION ERROR: x:1: test");
|
||||
EXPECT_EQ(err.prefix(), "COMPILATION ERROR");
|
||||
EXPECT_EQ(err.location(), "x:1");
|
||||
EXPECT_EQ(err.message(), "test");
|
||||
EXPECT_EQ(ToString(err), "COMPILATION ERROR: x:1: test");
|
||||
}
|
||||
|
||||
TEST(ErrorBuildersTest, ProgramError) {
|
||||
Error err = ProgramError(SourceLocation("x", 1)) << "test";
|
||||
EXPECT_EQ(err.message(), "PROGRAM ERROR: x:1: test");
|
||||
EXPECT_EQ(err.prefix(), "PROGRAM ERROR");
|
||||
EXPECT_EQ(err.location(), "x:1");
|
||||
EXPECT_EQ(err.message(), "test");
|
||||
EXPECT_EQ(ToString(err), "PROGRAM ERROR: x:1: test");
|
||||
}
|
||||
|
||||
TEST(ErrorBuildersTest, RuntimeError) {
|
||||
Error err = RuntimeError(SourceLocation("x", 1)) << "test";
|
||||
EXPECT_EQ(err.message(), "RUNTIME ERROR: x:1: test");
|
||||
EXPECT_EQ(err.prefix(), "RUNTIME ERROR");
|
||||
EXPECT_EQ(err.location(), "x:1");
|
||||
EXPECT_EQ(err.message(), "test");
|
||||
EXPECT_EQ(ToString(err), "RUNTIME ERROR: x:1: test");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user