From eeed724111402fb4746dbd2544c90ab946d03c67 Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Wed, 4 Jan 2012 20:12:22 -0800 Subject: make Lexer::Error not emit trailing newline Now it's consistent with other errors. Fixes part of issue #187. --- src/lexer.cc | 2 +- src/lexer_test.cc | 2 +- src/ninja.cc | 5 +---- src/parsers_test.cc | 36 ++++++++++++++++++------------------ 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/lexer.cc b/src/lexer.cc index 6bcdedc..b4707d2 100644 --- a/src/lexer.cc +++ b/src/lexer.cc @@ -53,7 +53,7 @@ bool Lexer::Error(const string& message, string* err) { *err += "..."; *err += "\n"; *err += string(col, ' '); - *err += "^ near here\n"; + *err += "^ near here"; } return false; diff --git a/src/lexer_test.cc b/src/lexer_test.cc index 44d1d04..1c5894e 100644 --- a/src/lexer_test.cc +++ b/src/lexer_test.cc @@ -74,7 +74,7 @@ TEST(Lexer, Error) { ASSERT_FALSE(lexer.ReadVarValue(&eval, &err)); EXPECT_EQ("input:2: bad $-escape (literal $ must be written as $$)\n" "bad $\n" - " ^ near here\n" + " ^ near here" , err); } diff --git a/src/ninja.cc b/src/ninja.cc index 64ab454..1d6c204 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -588,10 +588,7 @@ reload: ManifestParser parser(&globals.state, &file_reader); string err; if (!parser.Load(input_file, &err)) { - // The pattern in Ninja for errors is to return a one-line string, - // but parse errors are special in that they are multiline with - // context. Just report it verbatim. - fprintf(stderr, "%s", err.c_str()); + Error("%s", err.c_str()); return 1; } diff --git a/src/parsers_test.cc b/src/parsers_test.cc index d6b3117..7830917 100644 --- a/src/parsers_test.cc +++ b/src/parsers_test.cc @@ -232,7 +232,7 @@ TEST_F(ParserTest, Errors) { EXPECT_FALSE(parser.ParseTest("foobar", &err)); EXPECT_EQ("input:1: expected '=', got eof\n" "foobar\n" - " ^ near here\n" + " ^ near here" , err); } @@ -242,7 +242,7 @@ TEST_F(ParserTest, Errors) { EXPECT_FALSE(parser.ParseTest("x 3", &err)); EXPECT_EQ("input:1: expected '=', got identifier\n" "x 3\n" - " ^ near here\n" + " ^ near here" , err); } @@ -252,7 +252,7 @@ TEST_F(ParserTest, Errors) { EXPECT_FALSE(parser.ParseTest("x = 3", &err)); EXPECT_EQ("input:1: unexpected EOF\n" "x = 3\n" - " ^ near here\n" + " ^ near here" , err); } @@ -263,7 +263,7 @@ TEST_F(ParserTest, Errors) { EXPECT_FALSE(parser.ParseTest("x = 3\ny 2", &err)); EXPECT_EQ("input:2: expected '=', got identifier\n" "y 2\n" - " ^ near here\n" + " ^ near here" , err); } @@ -274,7 +274,7 @@ TEST_F(ParserTest, Errors) { EXPECT_FALSE(parser.ParseTest("x = $", &err)); EXPECT_EQ("input:1: bad $-escape (literal $ must be written as $$)\n" "x = $\n" - " ^ near here\n" + " ^ near here" , err); } @@ -285,7 +285,7 @@ TEST_F(ParserTest, Errors) { EXPECT_FALSE(parser.ParseTest("x = $\n $[\n", &err)); EXPECT_EQ("input:2: bad $-escape (literal $ must be written as $$)\n" " $[\n" - " ^ near here\n" + " ^ near here" , err); } @@ -305,7 +305,7 @@ TEST_F(ParserTest, Errors) { EXPECT_FALSE(parser.ParseTest("build x: y z\n", &err)); EXPECT_EQ("input:1: unknown build rule 'y'\n" "build x: y z\n" - " ^ near here\n" + " ^ near here" , err); } @@ -316,7 +316,7 @@ TEST_F(ParserTest, Errors) { EXPECT_FALSE(parser.ParseTest("build x:: y z\n", &err)); EXPECT_EQ("input:1: expected build command name\n" "build x:: y z\n" - " ^ near here\n" + " ^ near here" , err); } @@ -329,7 +329,7 @@ TEST_F(ParserTest, Errors) { &err)); EXPECT_EQ("input:4: expected newline, got ':'\n" " :\n" - " ^ near here\n" + " ^ near here" , err); } @@ -352,7 +352,7 @@ TEST_F(ParserTest, Errors) { &err)); EXPECT_EQ("input:2: bad $-escape (literal $ must be written as $$)\n" " command = ${fafsd\n" - " ^ near here\n" + " ^ near here" , err); } @@ -366,7 +366,7 @@ TEST_F(ParserTest, Errors) { &err)); EXPECT_EQ("input:3: bad $-escape (literal $ must be written as $$)\n" "build $: cat foo\n" - " ^ near here\n" + " ^ near here" , err); } @@ -389,7 +389,7 @@ TEST_F(ParserTest, Errors) { &err)); EXPECT_EQ("input:3: unexpected variable 'othervar'\n" " othervar = bar\n" - " ^ near here\n" + " ^ near here" , err); } @@ -402,7 +402,7 @@ TEST_F(ParserTest, Errors) { &err)); EXPECT_EQ("input:3: bad $-escape (literal $ must be written as $$)\n" "build $: cc bar.cc\n" - " ^ near here\n" + " ^ near here" , err); } @@ -414,7 +414,7 @@ TEST_F(ParserTest, Errors) { &err)); EXPECT_EQ("input:1: expected target name\n" "default\n" - " ^ near here\n" + " ^ near here" , err); } @@ -426,7 +426,7 @@ TEST_F(ParserTest, Errors) { &err)); EXPECT_EQ("input:1: unknown target 'nonexistent'\n" "default nonexistent\n" - " ^ near here\n" + " ^ near here" , err); } @@ -440,7 +440,7 @@ TEST_F(ParserTest, Errors) { &err)); EXPECT_EQ("input:4: expected newline, got ':'\n" "default b:\n" - " ^ near here\n" + " ^ near here" , err); } @@ -451,7 +451,7 @@ TEST_F(ParserTest, Errors) { EXPECT_FALSE(parser.ParseTest("default $a\n", &err)); EXPECT_EQ("input:1: empty path\n" "default $a\n" - " ^ near here\n" + " ^ near here" , err); } @@ -510,7 +510,7 @@ TEST_F(ParserTest, MissingSubNinja) { EXPECT_FALSE(parser.ParseTest("subninja foo.ninja\n", &err)); EXPECT_EQ("input:1: loading 'foo.ninja': No such file or directory\n" "subninja foo.ninja\n" - " ^ near here\n" + " ^ near here" , err); } -- cgit v0.12