Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit eeed724

Browse files
committedJan 5, 2012
make Lexer::Error not emit trailing newline
Now it's consistent with other errors. Fixes part of issue ninja-build#187.
1 parent 23ab282 commit eeed724

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed
 

‎src/lexer.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ bool Lexer::Error(const string& message, string* err) {
5353
*err += "...";
5454
*err += "\n";
5555
*err += string(col, ' ');
56-
*err += "^ near here\n";
56+
*err += "^ near here";
5757
}
5858

5959
return false;

‎src/lexer_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ TEST(Lexer, Error) {
7474
ASSERT_FALSE(lexer.ReadVarValue(&eval, &err));
7575
EXPECT_EQ("input:2: bad $-escape (literal $ must be written as $$)\n"
7676
"bad $\n"
77-
" ^ near here\n"
77+
" ^ near here"
7878
, err);
7979
}
8080

‎src/ninja.cc

+1-4
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,7 @@ int main(int argc, char** argv) {
588588
ManifestParser parser(&globals.state, &file_reader);
589589
string err;
590590
if (!parser.Load(input_file, &err)) {
591-
// The pattern in Ninja for errors is to return a one-line string,
592-
// but parse errors are special in that they are multiline with
593-
// context. Just report it verbatim.
594-
fprintf(stderr, "%s", err.c_str());
591+
Error("%s", err.c_str());
595592
return 1;
596593
}
597594

‎src/parsers_test.cc

+18-18
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ TEST_F(ParserTest, Errors) {
232232
EXPECT_FALSE(parser.ParseTest("foobar", &err));
233233
EXPECT_EQ("input:1: expected '=', got eof\n"
234234
"foobar\n"
235-
" ^ near here\n"
235+
" ^ near here"
236236
, err);
237237
}
238238

@@ -242,7 +242,7 @@ TEST_F(ParserTest, Errors) {
242242
EXPECT_FALSE(parser.ParseTest("x 3", &err));
243243
EXPECT_EQ("input:1: expected '=', got identifier\n"
244244
"x 3\n"
245-
" ^ near here\n"
245+
" ^ near here"
246246
, err);
247247
}
248248

@@ -252,7 +252,7 @@ TEST_F(ParserTest, Errors) {
252252
EXPECT_FALSE(parser.ParseTest("x = 3", &err));
253253
EXPECT_EQ("input:1: unexpected EOF\n"
254254
"x = 3\n"
255-
" ^ near here\n"
255+
" ^ near here"
256256
, err);
257257
}
258258

@@ -263,7 +263,7 @@ TEST_F(ParserTest, Errors) {
263263
EXPECT_FALSE(parser.ParseTest("x = 3\ny 2", &err));
264264
EXPECT_EQ("input:2: expected '=', got identifier\n"
265265
"y 2\n"
266-
" ^ near here\n"
266+
" ^ near here"
267267
, err);
268268
}
269269

@@ -274,7 +274,7 @@ TEST_F(ParserTest, Errors) {
274274
EXPECT_FALSE(parser.ParseTest("x = $", &err));
275275
EXPECT_EQ("input:1: bad $-escape (literal $ must be written as $$)\n"
276276
"x = $\n"
277-
" ^ near here\n"
277+
" ^ near here"
278278
, err);
279279
}
280280

@@ -285,7 +285,7 @@ TEST_F(ParserTest, Errors) {
285285
EXPECT_FALSE(parser.ParseTest("x = $\n $[\n", &err));
286286
EXPECT_EQ("input:2: bad $-escape (literal $ must be written as $$)\n"
287287
" $[\n"
288-
" ^ near here\n"
288+
" ^ near here"
289289
, err);
290290
}
291291

@@ -305,7 +305,7 @@ TEST_F(ParserTest, Errors) {
305305
EXPECT_FALSE(parser.ParseTest("build x: y z\n", &err));
306306
EXPECT_EQ("input:1: unknown build rule 'y'\n"
307307
"build x: y z\n"
308-
" ^ near here\n"
308+
" ^ near here"
309309
, err);
310310
}
311311

@@ -316,7 +316,7 @@ TEST_F(ParserTest, Errors) {
316316
EXPECT_FALSE(parser.ParseTest("build x:: y z\n", &err));
317317
EXPECT_EQ("input:1: expected build command name\n"
318318
"build x:: y z\n"
319-
" ^ near here\n"
319+
" ^ near here"
320320
, err);
321321
}
322322

@@ -329,7 +329,7 @@ TEST_F(ParserTest, Errors) {
329329
&err));
330330
EXPECT_EQ("input:4: expected newline, got ':'\n"
331331
" :\n"
332-
" ^ near here\n"
332+
" ^ near here"
333333
, err);
334334
}
335335

@@ -352,7 +352,7 @@ TEST_F(ParserTest, Errors) {
352352
&err));
353353
EXPECT_EQ("input:2: bad $-escape (literal $ must be written as $$)\n"
354354
" command = ${fafsd\n"
355-
" ^ near here\n"
355+
" ^ near here"
356356
, err);
357357
}
358358

@@ -366,7 +366,7 @@ TEST_F(ParserTest, Errors) {
366366
&err));
367367
EXPECT_EQ("input:3: bad $-escape (literal $ must be written as $$)\n"
368368
"build $: cat foo\n"
369-
" ^ near here\n"
369+
" ^ near here"
370370
, err);
371371
}
372372

@@ -389,7 +389,7 @@ TEST_F(ParserTest, Errors) {
389389
&err));
390390
EXPECT_EQ("input:3: unexpected variable 'othervar'\n"
391391
" othervar = bar\n"
392-
" ^ near here\n"
392+
" ^ near here"
393393
, err);
394394
}
395395

@@ -402,7 +402,7 @@ TEST_F(ParserTest, Errors) {
402402
&err));
403403
EXPECT_EQ("input:3: bad $-escape (literal $ must be written as $$)\n"
404404
"build $: cc bar.cc\n"
405-
" ^ near here\n"
405+
" ^ near here"
406406
, err);
407407
}
408408

@@ -414,7 +414,7 @@ TEST_F(ParserTest, Errors) {
414414
&err));
415415
EXPECT_EQ("input:1: expected target name\n"
416416
"default\n"
417-
" ^ near here\n"
417+
" ^ near here"
418418
, err);
419419
}
420420

@@ -426,7 +426,7 @@ TEST_F(ParserTest, Errors) {
426426
&err));
427427
EXPECT_EQ("input:1: unknown target 'nonexistent'\n"
428428
"default nonexistent\n"
429-
" ^ near here\n"
429+
" ^ near here"
430430
, err);
431431
}
432432

@@ -440,7 +440,7 @@ TEST_F(ParserTest, Errors) {
440440
&err));
441441
EXPECT_EQ("input:4: expected newline, got ':'\n"
442442
"default b:\n"
443-
" ^ near here\n"
443+
" ^ near here"
444444
, err);
445445
}
446446

@@ -451,7 +451,7 @@ TEST_F(ParserTest, Errors) {
451451
EXPECT_FALSE(parser.ParseTest("default $a\n", &err));
452452
EXPECT_EQ("input:1: empty path\n"
453453
"default $a\n"
454-
" ^ near here\n"
454+
" ^ near here"
455455
, err);
456456
}
457457

@@ -510,7 +510,7 @@ TEST_F(ParserTest, MissingSubNinja) {
510510
EXPECT_FALSE(parser.ParseTest("subninja foo.ninja\n", &err));
511511
EXPECT_EQ("input:1: loading 'foo.ninja': No such file or directory\n"
512512
"subninja foo.ninja\n"
513-
" ^ near here\n"
513+
" ^ near here"
514514
, err);
515515
}
516516

0 commit comments

Comments
 (0)
This repository has been archived.