1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

Merge pull request #7093 from jfinkels/tsort-print-cycle

tsort: print nodes and cycles as they are visited
This commit is contained in:
Sylvestre Ledru 2025-01-13 08:52:38 +01:00 committed by GitHub
commit 35b896f5e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 120 additions and 39 deletions

View file

@ -83,3 +83,31 @@ fn test_split_on_any_whitespace() {
.succeeds()
.stdout_only("a\nb\n");
}
#[test]
fn test_cycle() {
// The graph looks like: a --> b <==> c --> d
new_ucmd!()
.pipe_in("a b b c c d c b")
.fails()
.code_is(1)
.stdout_is("a\nc\nd\nb\n")
.stderr_is("tsort: -: input contains a loop:\ntsort: b\ntsort: c\n");
}
#[test]
fn test_two_cycles() {
// The graph looks like:
//
// a
// |
// V
// c <==> b <==> d
//
new_ucmd!()
.pipe_in("a b b c c b b d d b")
.fails()
.code_is(1)
.stdout_is("a\nc\nd\nb\n")
.stderr_is("tsort: -: input contains a loop:\ntsort: b\ntsort: c\ntsort: -: input contains a loop:\ntsort: b\ntsort: d\n");
}