Refactor command line errors to mirror diagnostic style (#4568)

This changes to an `Error` return to let the driver do the "error: "
prefix, except for one case with `help` that needs more work to change
(I'm not planning on picking up that TODO). It also changes
capitalization, backtick use, and a few minor punctuation things to try
to better match the diagnostic style.

This also adds `Error` matchers so that the changes to command line
testing are clearer.
This commit is contained in:
Jon Ross-Perkins
2024-11-26 19:22:05 +00:00
committed by GitHub
parent f921923b4b
commit 5880954041
11 changed files with 475 additions and 372 deletions
+5 -5
View File
@@ -105,13 +105,13 @@ class DriverTest : public testing::Test {
TEST_F(DriverTest, BadCommandErrors) {
EXPECT_FALSE(driver_.RunCommand({}).success);
EXPECT_THAT(test_error_stream_.TakeStr(), HasSubstr("ERROR"));
EXPECT_THAT(test_error_stream_.TakeStr(), HasSubstr("error:"));
EXPECT_FALSE(driver_.RunCommand({"foo"}).success);
EXPECT_THAT(test_error_stream_.TakeStr(), HasSubstr("ERROR"));
EXPECT_THAT(test_error_stream_.TakeStr(), HasSubstr("error:"));
EXPECT_FALSE(driver_.RunCommand({"foo --bar --baz"}).success);
EXPECT_THAT(test_error_stream_.TakeStr(), HasSubstr("ERROR"));
EXPECT_THAT(test_error_stream_.TakeStr(), HasSubstr("error:"));
}
TEST_F(DriverTest, CompileCommandErrors) {
@@ -119,8 +119,8 @@ TEST_F(DriverTest, CompileCommandErrors) {
EXPECT_FALSE(driver_.RunCommand({"compile"}).success);
EXPECT_THAT(
test_error_stream_.TakeStr(),
StrEq("ERROR: Not all required positional arguments were provided. First "
"missing and required positional argument: 'FILE'\n"));
StrEq("error: not all required positional arguments were provided; first "
"missing and required positional argument: `FILE`\n"));
// Invalid output filename. No reliably error message here.
// TODO: Likely want a different filename on Windows.