test: cover strip_dot_prefix for implicit-cwd recursive search

This commit is contained in:
Sylvestre Ledru
2026-05-30 09:59:05 +02:00
parent 89aec4a45a
commit 55cb643545
+19
View File
@@ -903,6 +903,25 @@ fn recursive_no_file_defaults_to_cwd_not_stdin() {
.stdout_contains("a.txt");
}
#[test]
fn recursive_implicit_cwd_strips_dot_prefix() {
// `-r` with no path argument searches the implicit ".", so reported paths
// come back as "./only.txt" (or ".\\only.txt" on Windows). GNU strips that
// leading prefix; `strip_dot_prefix` in src/searcher.rs must do the same.
// A single file keeps the output deterministic and lets us assert the exact
// line, which `stdout_contains` in `recursive_no_file_defaults_to_cwd_not_stdin`
// cannot (it would also pass with a leaked "./" prefix).
let (scene, _) = ucmd();
scene.fixtures.mkdir_all("flat");
scene.fixtures.write("flat/only.txt", "grep me\n");
let mut c = scene.cmd(env!("CARGO_BIN_EXE_grep"));
c.current_dir(scene.fixtures.plus("flat"))
.args(&["-r", "grep"])
.succeeds()
.stdout_is("only.txt:grep me\n");
}
#[test]
fn recursive_with_include_exclude() {
let (scene, _) = ucmd();