diff --git a/src/tsort/tsort.rs b/src/tsort/tsort.rs old mode 100644 new mode 100755 index 08c52cabe..145dd61fe --- a/src/tsort/tsort.rs +++ b/src/tsort/tsort.rs @@ -149,7 +149,7 @@ impl Graph { self.init_node(from); } - if !self.has_edge(from, to) { + if from != to && !self.has_edge(from, to) { self.in_edges.get_mut(to).unwrap().insert(from.clone()); self.out_edges.get_mut(from).unwrap().push(to.clone()); } diff --git a/tests/test_tsort.rs b/tests/test_tsort.rs index 2fe199cdd..9503ad969 100644 --- a/tests/test_tsort.rs +++ b/tests/test_tsort.rs @@ -8,3 +8,10 @@ fn test_sort_call_graph() { .run() .stdout_is_fixture("call_graph.expected"); } + +#[test] +fn test_sort_self_loop() { + new_ucmd!() + .pipe_in("first first\nfirst second second second") + .succeeds().stdout_only("first\nsecond\n"); +}