summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandy.boot <bootandy@gmail.com>2023-01-04 22:59:38 +0000
committerandy.boot <bootandy@gmail.com>2023-01-05 01:11:16 +0000
commit07c228fd0856259a046aefa9f4136effbb287340 (patch)
tree08187e1f4e16db74f2044f469110778e22cfb403
parentc457a295b5f8640cae27c035cb40af8907cbdc4c (diff)
Fix: depth=0 bug for multiple argumentsfix2
https://github.com/bootandy/dust/issues/282
-rw-r--r--src/filter.rs11
-rw-r--r--tests/test_flags.rs1
-rw-r--r--tests/tests_symlinks.rs15
3 files changed, 17 insertions, 10 deletions
diff --git a/src/filter.rs b/src/filter.rs
index 1eadbf2..cad491b 100644
--- a/src/filter.rs
+++ b/src/filter.rs
@@ -20,13 +20,20 @@ pub fn get_biggest(
let mut heap = BinaryHeap::new();
let number_top_level_nodes = top_level_nodes.len();
+
let root = get_new_root(top_level_nodes);
let mut allowed_nodes = HashSet::new();
allowed_nodes.insert(root.name.as_path());
- heap = add_children(using_a_filter, min_size, only_dir, &root, depth, heap);
- for _ in number_top_level_nodes..n {
+ if number_top_level_nodes > 1 {
+ heap = add_children(using_a_filter, min_size, only_dir, &root, usize::MAX, heap);
+ } else {
+ heap = add_children(using_a_filter, min_size, only_dir, &root, depth, heap);
+ }
+
+ let number_of_lines_in_output = n - number_top_level_nodes;
+ for _ in 0..number_of_lines_in_output {
let line = heap.pop();
match line {
Some(line) => {
diff --git a/tests/test_flags.rs b/tests/test_flags.rs
index 81f1119..610d1e1 100644
--- a/tests/test_flags.rs
+++ b/tests/test_flags.rs
@@ -73,6 +73,7 @@ pub fn test_ignore_dir() {
let output = build_command(vec!["-c", "-X", "dir_substring", "tests/test_dir2/"]);
assert!(!output.contains("dir_substring"));
}
+// Add test for multiple dirs - with -d 0 and maybe -d 1 check the
#[test]
pub fn test_with_bad_param() {
diff --git a/tests/tests_symlinks.rs b/tests/tests_symlinks.rs
index 620d5c9..f89007d 100644
--- a/tests/tests_symlinks.rs
+++ b/tests/tests_symlinks.rs
@@ -47,7 +47,7 @@ pub fn test_soft_sym_link() {
let mut cmd = Command::cargo_bin("dust").unwrap();
// Mac test runners create long filenames in tmp directories
let output = cmd
- .args(["-p", "-c", "-s", "-w 999", dir_s])
+ .args(["-p", "-c", "-s", "-w", "999", dir_s])
.unwrap()
.stdout;
@@ -74,7 +74,7 @@ pub fn test_hard_sym_link() {
let mut cmd = Command::cargo_bin("dust").unwrap();
// Mac test runners create long filenames in tmp directories
- let output = cmd.args(["-p", "-c", "-w 999", dir_s]).unwrap().stdout;
+ let output = cmd.args(["-p", "-c", "-w", "999", dir_s]).unwrap().stdout;
// The link should not appear in the output because multiple inodes are now ordered
// then filtered.
@@ -100,17 +100,15 @@ pub fn test_hard_sym_link_no_dup_multi_arg() {
// Mac test runners create long filenames in tmp directories
let output = cmd
- .args(["-p", "-c", "-w 999", "-b", dir_link_s, dir_s])
+ .args(["-p", "-c", "-w", "999", "-b", dir_link_s, dir_s])
.unwrap()
.stdout;
- // The link or the file should appeart but not both
+ // The link or the file should appear but not both
let output = str::from_utf8(&output).unwrap();
- println!("cmd:\n{:?}", cmd);
- println!("output:\n{:?}", output);
let has_file_only = output.contains(file_path_s) && !output.contains(&link_name_s);
let has_link_only = !output.contains(file_path_s) && output.contains(&link_name_s);
- assert!(has_file_only || has_link_only)
+ assert!(has_file_only || has_link_only);
}
#[cfg_attr(target_os = "windows", ignore)]
@@ -131,7 +129,8 @@ pub fn test_recursive_sym_link() {
.arg("-c")
.arg("-r")
.arg("-s")
- .arg("-w 999")
+ .arg("-w")
+ .arg("999")
.arg(dir_s)
.unwrap()
.stdout;