diff options
author | Evan Martin <martine@danga.com> | 2011-05-11 16:58:29 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2011-05-11 18:29:01 (GMT) |
commit | eccebffca22672b4f9d4c381e38eaad5884c352f (patch) | |
tree | c420e4b6c5189fea6c87d084bef9e23872be9e8c /src/build_log_test.cc | |
parent | fa8830b546428e1daa829d0ddf2465697e0d9bb3 (diff) | |
download | Ninja-eccebffca22672b4f9d4c381e38eaad5884c352f.zip Ninja-eccebffca22672b4f9d4c381e38eaad5884c352f.tar.gz Ninja-eccebffca22672b4f9d4c381e38eaad5884c352f.tar.bz2 |
don't crash on truncated log files
Add a test that tries all truncations of a log file and verifies it
doesn't crash.
Diffstat (limited to 'src/build_log_test.cc')
-rw-r--r-- | src/build_log_test.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/build_log_test.cc b/src/build_log_test.cc index caf1540..8bb2bfa 100644 --- a/src/build_log_test.cc +++ b/src/build_log_test.cc @@ -69,3 +69,31 @@ TEST_F(BuildLogTest, DoubleEntry) { ASSERT_TRUE(e); ASSERT_EQ("command def", e->command); } + +TEST_F(BuildLogTest, Truncate) { + AssertParse(&state_, +"build out: cat mid\n" +"build mid: cat in\n"); + + BuildLog log1; + string err; + EXPECT_TRUE(log1.OpenForWrite(kTestFilename, &err)); + ASSERT_EQ("", err); + log1.RecordCommand(state_.edges_[0], 15, 18); + log1.RecordCommand(state_.edges_[1], 20, 25); + log1.Close(); + + struct stat statbuf; + ASSERT_EQ(0, stat(kTestFilename, &statbuf)); + ASSERT_GT(statbuf.st_size, 0); + + // For all possible truncations of the input file, assert that we don't + // crash or report an error when parsing. + for (off_t size = statbuf.st_size; size > 0; --size) { + ASSERT_EQ(0, truncate(kTestFilename, size)); + + BuildLog log2; + EXPECT_TRUE(log2.Load(kTestFilename, &err)); + ASSERT_EQ("", err); + } +} |