mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Lots of code cleanup
- Try to use iterator adapters and collect in various places, where possible. This especially benefits draw_it. - Try to use `.map` and other similar methods on Options and Results, where possible - Replaced nearly all clones with reference-based equivalents - Summarizing nodes by file extension is now much more efficient - PartialOrd and PartialEq implementations now agree - Replace #[cfg(...)] function definitions with simpler if cfg!(...) equivelents - Simplify CLI Values handling by taking advantage of Values::default - Various spelling corrections in comments - Add `ColorState` enum to replace bool, for clarity - Fix tests that break under some detected terminal widths when paths are long - Use sort_by instead of (sort, reverse) - Use new `ExtensionNode` struct internally to simplify extension aggregation code
This commit is contained in:
@@ -20,14 +20,11 @@ fn copy_test_data(dir: &str) {
|
||||
// First remove the existing directory - just incase it is there and has incorrect data
|
||||
let last_slash = dir.rfind('/').unwrap();
|
||||
let last_part_of_dir = dir.chars().skip(last_slash).collect::<String>();
|
||||
match Command::new("rm")
|
||||
let _ = Command::new("rm")
|
||||
.arg("-rf")
|
||||
.arg("/tmp/".to_owned() + &*last_part_of_dir)
|
||||
.ok()
|
||||
{
|
||||
Ok(_) => {}
|
||||
Err(_) => {}
|
||||
};
|
||||
.ok();
|
||||
|
||||
match Command::new("cp").arg("-r").arg(dir).arg("/tmp/").ok() {
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
@@ -48,14 +45,14 @@ fn exact_output_test<T: AsRef<OsStr>>(valid_outputs: Vec<String>, command_args:
|
||||
initialize();
|
||||
|
||||
let mut a = &mut Command::cargo_bin("dust").unwrap();
|
||||
|
||||
for p in command_args {
|
||||
a = a.arg(p);
|
||||
}
|
||||
let output: String = str::from_utf8(&a.unwrap().stdout).unwrap().into();
|
||||
|
||||
assert!(valid_outputs
|
||||
.iter()
|
||||
.fold(false, |sum, i| sum || output.contains(i)));
|
||||
let output = str::from_utf8(&a.unwrap().stdout).unwrap().to_owned();
|
||||
|
||||
assert!(valid_outputs.iter().any(|i| output.contains(i)));
|
||||
}
|
||||
|
||||
// "windows" result data can vary by host (size seems to be variable by one byte); fix code vs test and re-enable
|
||||
@@ -129,7 +126,7 @@ fn main_output_long_paths() -> Vec<String> {
|
||||
vec![mac_and_some_linux, ubuntu]
|
||||
}
|
||||
|
||||
// Check against directories and files whos names are substrings of each other
|
||||
// Check against directories and files whose names are substrings of each other
|
||||
#[cfg_attr(target_os = "windows", ignore)]
|
||||
#[test]
|
||||
pub fn test_substring_of_names_and_long_names() {
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ pub fn test_d_flag_works_and_still_recurses_down() {
|
||||
assert!(output.contains("4 ┌─┴ test_dir2"));
|
||||
}
|
||||
|
||||
// Check against directories and files whos names are substrings of each other
|
||||
// Check against directories and files whose names are substrings of each other
|
||||
#[test]
|
||||
pub fn test_ignore_dir() {
|
||||
let output = build_command(vec!["-c", "-X", "dir_substring", "tests/test_dir2/"]);
|
||||
|
||||
+12
-4
@@ -39,9 +39,12 @@ pub fn test_soft_sym_link() {
|
||||
let a = format!("─┴ {}", dir_s);
|
||||
|
||||
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])
|
||||
.arg("-p")
|
||||
.arg("-c")
|
||||
.arg("-s")
|
||||
.args(["-w", "999"])
|
||||
.arg(dir_s)
|
||||
.unwrap()
|
||||
.stdout;
|
||||
|
||||
@@ -72,8 +75,13 @@ pub fn test_hard_sym_link() {
|
||||
let dirs_output = format!("─┴ {}", dir_s);
|
||||
|
||||
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
|
||||
.arg("-p")
|
||||
.arg("-c")
|
||||
.args(["-w", "999"])
|
||||
.arg(dir_s)
|
||||
.unwrap()
|
||||
.stdout;
|
||||
|
||||
// The link should not appear in the output because multiple inodes are now ordered
|
||||
// then filtered.
|
||||
|
||||
Reference in New Issue
Block a user