Skip to content

Commit b30e1b4

Browse files
committed
test: Add test_sort_by_path and _with_exec
1 parent d1364d1 commit b30e1b4

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

tests/tests.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,49 @@ fn test_exec_batch_with_limit() {
20232023
);
20242024
}
20252025

2026+
fn shuffle_files(files: &[&'static str], seed: u64) -> Vec<&'static str> {
2027+
use rand::SeedableRng as _;
2028+
use rand::seq::SliceRandom as _;
2029+
let mut files = files.to_vec();
2030+
files.shuffle(&mut rand::rngs::StdRng::seed_from_u64(seed));
2031+
2032+
files
2033+
}
2034+
2035+
#[test]
2036+
fn test_sort_by_path() {
2037+
let te = TestEnv::new(DEFAULT_DIRS, &shuffle_files(DEFAULT_FILES, 42));
2038+
2039+
// --sort=path should produce deterministic alphabetical output
2040+
te.assert_output(
2041+
&["--sort=path", "foo"],
2042+
"a.foo
2043+
one/b.foo
2044+
one/two/C.Foo2
2045+
one/two/c.foo
2046+
one/two/three/d.foo
2047+
one/two/three/directory_foo/",
2048+
);
2049+
}
2050+
2051+
/// Shell script execution with --sort (--exec)
2052+
#[cfg(not(windows))]
2053+
#[test]
2054+
fn test_sort_by_path_with_exec() {
2055+
let te = TestEnv::new(DEFAULT_DIRS, &shuffle_files(DEFAULT_FILES, 42));
2056+
2057+
// --exec with --sort should produce output in sorted order
2058+
te.assert_output(
2059+
&["foo", "--sort=path", "--exec", "echo", "File: {}"],
2060+
"File: ./a.foo
2061+
File: ./one/b.foo
2062+
File: ./one/two/C.Foo2
2063+
File: ./one/two/c.foo
2064+
File: ./one/two/three/d.foo
2065+
File: ./one/two/three/directory_foo",
2066+
);
2067+
}
2068+
20262069
/// Shell script execution (--exec) with a custom --path-separator
20272070
#[test]
20282071
fn test_exec_with_separator() {

0 commit comments

Comments
 (0)