summaryrefslogtreecommitdiffstats
path: root/src/test.cc
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2015-03-19 23:42:06 (GMT)
committerNico Weber <nicolasweber@gmx.de>2015-03-19 23:42:06 (GMT)
commitf5c5789aad8001e15a7e4f1ee0dee0c2b688e993 (patch)
tree9e26b5bbf6486a710eba81c0d0214b2fb3f3e348 /src/test.cc
parent20a840539ce87a343b414f52a3330706a731b044 (diff)
downloadNinja-f5c5789aad8001e15a7e4f1ee0dee0c2b688e993.zip
Ninja-f5c5789aad8001e15a7e4f1ee0dee0c2b688e993.tar.gz
Ninja-f5c5789aad8001e15a7e4f1ee0dee0c2b688e993.tar.bz2
Another crash fix for duplicate edges. Fixes #939.
Patch #933 fixed a crash with duplicate edges by not adding edges to the graph if all the edge's outputs are already built by other edges. However, it added the edge to the out_edges of the edge's input nodes before deleting it, letting inputs refer to dead edges. To fix, move the check for deleting an edge above the code that adds inputs. Expand VerifyGraph() to check that nodes don't refer to edges that aren't present in the state.
Diffstat (limited to 'src/test.cc')
-rw-r--r--src/test.cc16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/test.cc b/src/test.cc
index 76b8416..ddecd3d 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -111,19 +111,31 @@ void VerifyGraph(const State& state) {
e != state.edges_.end(); ++e) {
// All edges need at least one output.
EXPECT_FALSE((*e)->outputs_.empty());
- // Check that the edge's inputs have the edge as out edge.
+ // Check that the edge's inputs have the edge as out-edge.
for (vector<Node*>::const_iterator in_node = (*e)->inputs_.begin();
in_node != (*e)->inputs_.end(); ++in_node) {
const vector<Edge*>& out_edges = (*in_node)->out_edges();
EXPECT_NE(std::find(out_edges.begin(), out_edges.end(), *e),
out_edges.end());
}
- // Check that the edge's outputs have the edge as in edge.
+ // Check that the edge's outputs have the edge as in-edge.
for (vector<Node*>::const_iterator out_node = (*e)->outputs_.begin();
out_node != (*e)->outputs_.end(); ++out_node) {
EXPECT_EQ((*out_node)->in_edge(), *e);
}
}
+
+ // The union of all in- and out-edges of each nodes should be exactly edges_.
+ set<const Edge*> node_edge_set;
+ for (State::Paths::const_iterator p = state.paths_.begin();
+ p != state.paths_.end(); ++p) {
+ const Node* n = p->second;
+ if (n->in_edge())
+ node_edge_set.insert(n->in_edge());
+ node_edge_set.insert(n->out_edges().begin(), n->out_edges().end());
+ }
+ set<const Edge*> edge_set(state.edges_.begin(), state.edges_.end());
+ EXPECT_EQ(node_edge_set, edge_set);
}
void VirtualFileSystem::Create(const string& path,