Skip to content

Commit cd2e4e3

Browse files
committed
add a test
1 parent 87ee3e9 commit cd2e4e3

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/cargo/util/graph.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,12 @@ impl<'s, N: Eq + Ord + Clone + 's, E: Default + Clone + 's> Graph<N, E> {
165165
));
166166
}
167167
let last = result.last().unwrap().0;
168-
// fixme: this may sometimes be wrong when there are cycles.
169-
if !fn_edge(&self, last).next().is_none() {
168+
let set: Vec<_> = result.iter().map(|(k, _)| k).collect();
169+
if !fn_edge(&self, last)
170+
.filter(|(e, _)| !set.contains(&e))
171+
.next()
172+
.is_none()
173+
{
170174
self.print_for_test();
171175
unreachable!("The last element in the path should not have outgoing edges");
172176
}
@@ -188,6 +192,14 @@ fn path_to_case() {
188192
);
189193
}
190194

195+
#[test]
196+
fn path_to_self() {
197+
// Extracted from #12941
198+
let mut new: Graph<i32, ()> = Graph::new();
199+
new.link(0, 0);
200+
assert_eq!(new.path_to_bottom(&0), vec![(&0, None)]);
201+
}
202+
191203
impl<N: Eq + Ord + Clone, E: Default + Clone> Default for Graph<N, E> {
192204
fn default() -> Graph<N, E> {
193205
Graph::new()

tests/testsuite/test.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,6 +3555,34 @@ fn cyclic_dev() {
35553555
p.cargo("test --workspace").run();
35563556
}
35573557

3558+
#[cargo_test]
3559+
fn cyclical_dep_with_missing_feature() {
3560+
// Checks for error handling when a cyclical dev-dependency specify a
3561+
// feature that doesn't exist.
3562+
let p = project()
3563+
.file(
3564+
"Cargo.toml",
3565+
r#"
3566+
[package]
3567+
name = "foo"
3568+
version = "0.1.0"
3569+
3570+
[dev-dependencies]
3571+
foo = { path = ".", features = ["missing"] }
3572+
"#,
3573+
)
3574+
.file("src/lib.rs", "")
3575+
.build();
3576+
p.cargo("check")
3577+
.with_status(101)
3578+
.with_stderr(
3579+
"thread 'main' panicked at src/cargo/util/graph.rs:149:20:
3580+
the only path was a cycle, no dependency graph has this shape
3581+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace",
3582+
)
3583+
.run();
3584+
}
3585+
35583586
#[cargo_test]
35593587
fn publish_a_crate_without_tests() {
35603588
Package::new("testless", "0.1.0")

0 commit comments

Comments
 (0)