summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2014-01-04 04:43:42 (GMT)
committerNico Weber <nicolasweber@gmx.de>2014-01-04 04:43:42 (GMT)
commit637b4572ba9c98b812858a37521af1d442b3ccc4 (patch)
tree32950e41a467b5cec0502006ad3c21fd56b6f218
parent691474973aeeb4d1002cd3c8fae3e106767e36f6 (diff)
downloadNinja-637b4572ba9c98b812858a37521af1d442b3ccc4.zip
Ninja-637b4572ba9c98b812858a37521af1d442b3ccc4.tar.gz
Ninja-637b4572ba9c98b812858a37521af1d442b3ccc4.tar.bz2
Add a test for collection of dead log entries.
-rw-r--r--src/build_log_test.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/build_log_test.cc b/src/build_log_test.cc
index 60f7423..db1e0be 100644
--- a/src/build_log_test.cc
+++ b/src/build_log_test.cc
@@ -262,4 +262,44 @@ TEST_F(BuildLogTest, MultiTargetEdge) {
ASSERT_EQ(22, e2->end_time);
}
+struct BuildLogRecompactTest : public BuildLogTest {
+ virtual bool IsPathDead(StringPiece s) { return s == "out2"; }
+};
+
+TEST_F(BuildLogRecompactTest, Recompact) {
+ AssertParse(&state_,
+"build out: cat in\n"
+"build out2: cat in\n");
+
+ BuildLog log1;
+ string err;
+ EXPECT_TRUE(log1.OpenForWrite(kTestFilename, this, &err));
+ ASSERT_EQ("", err);
+ // Record the same edge several times, to trigger recompaction
+ // the next time the log is opened.
+ for (int i = 0; i < 200; ++i)
+ log1.RecordCommand(state_.edges_[0], 15, 18 + i);
+ log1.RecordCommand(state_.edges_[1], 21, 22);
+ log1.Close();
+
+ // Load...
+ BuildLog log2;
+ EXPECT_TRUE(log2.Load(kTestFilename, &err));
+ ASSERT_EQ("", err);
+ ASSERT_EQ(2u, log2.entries().size());
+ ASSERT_TRUE(log2.LookupByOutput("out"));
+ ASSERT_TRUE(log2.LookupByOutput("out2"));
+ // ...and force a recompaction.
+ EXPECT_TRUE(log2.OpenForWrite(kTestFilename, this, &err));
+ log2.Close();
+
+ // "out2" is dead, it should've been removed.
+ BuildLog log3;
+ EXPECT_TRUE(log2.Load(kTestFilename, &err));
+ ASSERT_EQ("", err);
+ ASSERT_EQ(1u, log2.entries().size());
+ ASSERT_TRUE(log2.LookupByOutput("out"));
+ ASSERT_FALSE(log2.LookupByOutput("out2"));
+}
+
} // anonymous namespace