summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2012-01-05 04:12:22 (GMT)
committerEvan Martin <martine@danga.com>2012-01-05 04:13:35 (GMT)
commiteeed724111402fb4746dbd2544c90ab946d03c67 (patch)
tree160354192a9a234f2373c8b9111f854f0498e0c2
parent23ab2829f5f3dd66d95e1d3230f9c4bcb70cfabf (diff)
downloadNinja-eeed724111402fb4746dbd2544c90ab946d03c67.zip
Ninja-eeed724111402fb4746dbd2544c90ab946d03c67.tar.gz
Ninja-eeed724111402fb4746dbd2544c90ab946d03c67.tar.bz2
make Lexer::Error not emit trailing newline
Now it's consistent with other errors. Fixes part of issue #187.
-rw-r--r--src/lexer.cc2
-rw-r--r--src/lexer_test.cc2
-rw-r--r--src/ninja.cc5
-rw-r--r--src/parsers_test.cc36
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);
}