Skip to content

Commit

Permalink
Merge branch 'main' into implement-372
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre authored Jul 9, 2024
2 parents d5af780 + 9c11f11 commit 0649b10
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/find/matchers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,11 @@ fn build_matcher_tree(
config.today_start = true;
None
}
"-noleaf" => {
// No change of behavior
config.no_leaf_dirs = true;
None
}
"-d" | "-depth" => {
// TODO add warning if it appears after actual testing criterion
config.depth_first = true;
Expand Down
15 changes: 15 additions & 0 deletions src/find/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct Config {
help_requested: bool,
version_requested: bool,
today_start: bool,
no_leaf_dirs: bool,
}

impl Default for Config {
Expand All @@ -35,6 +36,10 @@ impl Default for Config {
help_requested: false,
version_requested: false,
today_start: false,
// Directory information and traversal are done by walkdir,
// and this configuration field will exist as
// a compatibility item for GNU findutils.
no_leaf_dirs: false,
}
}
}
Expand Down Expand Up @@ -158,6 +163,7 @@ fn process_dir<'a>(
}
Ok(entry) => {
let mut matcher_io = matchers::MatcherIO::new(deps);

if matcher.matches(&entry, &mut matcher_io) {
found_count += 1;
}
Expand Down Expand Up @@ -1254,6 +1260,15 @@ mod tests {
],
&deps,
);
}

#[test]
#[cfg(unix)]
fn test_noleaf() {
use crate::find::tests::FakeDependencies;

let deps = FakeDependencies::new();
let rc = find_main(&["find", "./test_data/simple/subdir", "-noleaf"], &deps);

assert_eq!(rc, 0);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/find_cmd_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,5 +904,16 @@ fn find_ignore_readdir_race() {
])
.assert()
.success()
}

#[test]
#[serial(working_dir)]
fn find_noleaf() {
Command::cargo_bin("find")
.expect("found binary")
.args(["test_data/simple/subdir", "-noleaf"])
.assert()
.success()
.stdout(predicate::str::contains("test_data/simple/subdir"))
.stderr(predicate::str::is_empty());
}

0 comments on commit 0649b10

Please sign in to comment.