From e69d8bfda4b369717e67ff1d9bfa458b402c0e73 Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Sun, 22 May 2011 09:25:34 -0700 Subject: include filename in subninja load err message --- src/parsers.cc | 10 ++++++---- src/parsers_test.cc | 10 +++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/parsers.cc b/src/parsers.cc index d22dd97..e4402af 100644 --- a/src/parsers.cc +++ b/src/parsers.cc @@ -510,12 +510,11 @@ bool ManifestParser::ParseFileInclude(string* err) { string path; if (!tokenizer_.ReadIdent(&path)) return tokenizer_.ErrorExpected("path to ninja file", err); - if (!tokenizer_.Newline(err)) - return false; string contents; - if (!file_reader_->ReadFile(path, &contents, err)) - return false; + string read_err; + if (!file_reader_->ReadFile(path, &contents, &read_err)) + return tokenizer_.Error("loading " + path + ": " + read_err, err); ManifestParser subparser(state_, file_reader_); if (type == "subninja") { @@ -531,5 +530,8 @@ bool ManifestParser::ParseFileInclude(string* err) { if (!subparser.Parse(contents, &sub_err)) return tokenizer_.Error("in '" + path + "': " + sub_err, err); + if (!tokenizer_.Newline(err)) + return false; + return true; } diff --git a/src/parsers_test.cc b/src/parsers_test.cc index 0ffd69e..f21cccf 100644 --- a/src/parsers_test.cc +++ b/src/parsers_test.cc @@ -32,7 +32,7 @@ struct ParserTest : public testing::Test, files_read_.push_back(path); map::iterator i = files_.find(path); if (i == files_.end()) { - *err = "file not found"; + *err = "No such file or directory"; // Match strerror() for ENOENT. return false; } *content = i->second; @@ -335,6 +335,14 @@ TEST_F(ParserTest, SubNinja) { EXPECT_EQ("varref outer", state.edges_[2]->EvaluateCommand()); } +TEST_F(ParserTest, MissingSubNinja) { + ManifestParser parser(&state, this); + string err; + EXPECT_FALSE(parser.Parse("subninja foo.ninja\n", &err)); + EXPECT_EQ("line 1, col 10: loading foo.ninja: No such file or directory", + err); +} + TEST_F(ParserTest, Include) { files_["include.ninja"] = "var = inner\n"; ASSERT_NO_FATAL_FAILURE(AssertParse( -- cgit v0.12