Skip to content

Commit

Permalink
added assertions to make sure the path code is correct in graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Sep 19, 2023
1 parent 245e69c commit 2284b7a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/cargo/util/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ impl<N: Eq + Ord + Clone, E: Default + Clone> Graph<N, E> {
result.push(p);
pkg = p.0;
}
#[cfg(debug_assertions)]
{
for x in result.windows(2) {
let [(n1, _), (n2, Some(e12))] = x else {
unreachable!()
};
assert!(std::ptr::eq(self.edge(n1, n2).unwrap(), *e12));
}
let last = result.last().unwrap().0;
// fixme: this may be wrong when there are cycles, but we dont have them in tests.
assert!(!self.nodes.contains_key(last));
}
result
}

Expand Down Expand Up @@ -134,6 +146,21 @@ impl<N: Eq + Ord + Clone, E: Default + Clone> Graph<N, E> {
result.push(p);
pkg = p.0;
}
#[cfg(debug_assertions)]
{
for x in result.windows(2) {
let [(n2, _), (n1, Some(e12))] = x else {
unreachable!()
};
assert!(std::ptr::eq(self.edge(n1, n2).unwrap(), *e12));
}
let last = result.last().unwrap().0;
// fixme: this may be wrong when there are cycles, but we dont have them in tests.
assert!(!self
.nodes
.iter()
.any(|(_, adjacent)| adjacent.contains_key(last)));
}
result
}
}
Expand Down

0 comments on commit 2284b7a

Please sign in to comment.