summaryrefslogtreecommitdiffstats
path: root/src/deps_log_test.cc
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2013-04-30 16:11:09 (GMT)
committerNico Weber <nicolasweber@gmx.de>2013-05-01 18:07:31 (GMT)
commit1eaacc8ccf26363ae3a820675721164873a31f3d (patch)
treeaafcbd40e4faa4da866c95dbe2a64a3889719f3f /src/deps_log_test.cc
parentf70a90edc6681fef7e75c7bc7f2860d40c2490ee (diff)
downloadNinja-1eaacc8ccf26363ae3a820675721164873a31f3d.zip
Ninja-1eaacc8ccf26363ae3a820675721164873a31f3d.tar.gz
Ninja-1eaacc8ccf26363ae3a820675721164873a31f3d.tar.bz2
Keep a DepsLog's data valid after a call to DepsLog::Recompact().
Previously, a DepsLog would become invalid after Recompact() was called, due to Recompact() making all node ids refer to a temporary DepsLog object constructed in Recompact().
Diffstat (limited to 'src/deps_log_test.cc')
-rw-r--r--src/deps_log_test.cc29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/deps_log_test.cc b/src/deps_log_test.cc
index 31f0414..0591736 100644
--- a/src/deps_log_test.cc
+++ b/src/deps_log_test.cc
@@ -188,18 +188,43 @@ TEST_F(DepsLogTest, Recompact) {
string err;
ASSERT_TRUE(log.Load(kTestFilename, &state, &err));
- DepsLog::Deps* deps = log.GetDeps(state.GetNode("out.o"));
+ Node* out = state.GetNode("out.o");
+ DepsLog::Deps* deps = log.GetDeps(out);
ASSERT_TRUE(deps);
ASSERT_EQ(1, deps->mtime);
ASSERT_EQ(1, deps->node_count);
ASSERT_EQ("foo.h", deps->nodes[0]->path());
+ Node* other_out = state.GetNode("other_out.o");
+ deps = log.GetDeps(other_out);
+ ASSERT_TRUE(deps);
+ ASSERT_EQ(1, deps->mtime);
+ ASSERT_EQ(2, deps->node_count);
+ ASSERT_EQ("foo.h", deps->nodes[0]->path());
+ ASSERT_EQ("baz.h", deps->nodes[1]->path());
+
ASSERT_TRUE(log.Recompact(kTestFilename, &err));
+ // The in-memory deps graph should still be valid after recompaction.
+ deps = log.GetDeps(out);
+ ASSERT_TRUE(deps);
+ ASSERT_EQ(1, deps->mtime);
+ ASSERT_EQ(1, deps->node_count);
+ ASSERT_EQ("foo.h", deps->nodes[0]->path());
+ ASSERT_EQ(out, log.nodes()[out->id()]);
+
+ deps = log.GetDeps(other_out);
+ ASSERT_TRUE(deps);
+ ASSERT_EQ(1, deps->mtime);
+ ASSERT_EQ(2, deps->node_count);
+ ASSERT_EQ("foo.h", deps->nodes[0]->path());
+ ASSERT_EQ("baz.h", deps->nodes[1]->path());
+ ASSERT_EQ(other_out, log.nodes()[other_out->id()]);
+
+ // The file should have shrunk a bit for the smaller deps.
struct stat st;
ASSERT_EQ(0, stat(kTestFilename, &st));
int file_size_3 = (int)st.st_size;
- // The file should have shrunk a bit for the smaller deps.
ASSERT_LT(file_size_3, file_size_2);
}
}