Skip to content

Commit

Permalink
Merge branch 'main' into implement-383
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre authored Sep 9, 2024
2 parents 07e9b11 + 4d36789 commit 4130c38
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
9 changes: 9 additions & 0 deletions src/find/matchers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,15 @@ fn build_matcher_tree(
i += 1;
Some(Printf::new(args[i], Some(file))?.into_box())
}
"-fprint0" => {
if i >= args.len() - 1 {
return Err(From::from(format!("missing argument to {}", args[i])));
}
i += 1;

let file = get_or_create_file(args[i])?;
Some(Printer::new(PrintDelimiter::Null, Some(file)).into_box())
}
"-ls" => Some(Ls::new(None).into_box()),
"-fls" => {
if i >= args.len() - 1 {
Expand Down
30 changes: 17 additions & 13 deletions src/find/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,20 +1338,24 @@ mod tests {
}

#[test]
fn find_fprint() {
let deps = FakeDependencies::new();
let rc = find_main(
&[
"find",
"./test_data/simple",
"-fprint",
"test_data/find_fprint",
],
&deps,
);
assert_eq!(rc, 0);
fn find_fprinter() {
let printer = ["fprint", "fprint0"];

let _ = fs::remove_file("test_data/find_fprint");
for p in printer.iter() {
let deps = FakeDependencies::new();
let rc = find_main(
&[
"find",
"./test_data/simple",
format!("-{p}").as_str(),
format!("test_data/find_{p}").as_str(),
],
&deps,
);
assert_eq!(rc, 0);

let _ = fs::remove_file(format!("test_data/find_{p}"));
}
}

#[test]
Expand Down
44 changes: 26 additions & 18 deletions tests/find_cmd_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,24 +952,32 @@ fn find_daystart() {

#[test]
#[serial(working_dir)]
fn find_fprint() {
let _ = fs::remove_file("test_data/find_fprint");

Command::cargo_bin("find")
.expect("found binary")
.args(["test_data/simple", "-fprint", "test_data/find_fprint"])
.assert()
.success()
.stdout(predicate::str::is_empty())
.stderr(predicate::str::is_empty());

// read test_data/find_fprint
let mut f = File::open("test_data/find_fprint").unwrap();
let mut contents = String::new();
f.read_to_string(&mut contents).unwrap();
assert!(contents.contains("test_data/simple"));

let _ = fs::remove_file("test_data/find_fprint");
fn find_fprinter() {
let printer = ["fprint", "fprint0"];

for p in printer.iter() {
let _ = fs::remove_file(format!("test_data/find_{p}"));

Command::cargo_bin("find")
.expect("found binary")
.args([
"test_data/simple",
format!("-{p}").as_str(),
format!("test_data/find_{p}").as_str(),
])
.assert()
.success()
.stdout(predicate::str::is_empty())
.stderr(predicate::str::is_empty());

// read test_data/find_fprint
let mut f = File::open(format!("test_data/find_{p}")).unwrap();
let mut contents = String::new();
f.read_to_string(&mut contents).unwrap();
assert!(contents.contains("test_data/simple"));

let _ = fs::remove_file(format!("test_data/find_{p}"));
}
}

#[test]
Expand Down

0 comments on commit 4130c38

Please sign in to comment.