Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 63 additions & 89 deletions tests/test_exact_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ pub fn test_main_basic() {
let mut cmd = Command::cargo_bin("dust").unwrap();
let assert = cmd.arg("-c").arg("/tmp/test_dir/").unwrap().stdout;
let output = str::from_utf8(&assert).unwrap();
assert!(output.contains(&main_output()));
let mut we_match = false;
for mo in main_output() {
we_match = we_match || output.contains(&mo);
}
assert!(we_match);
}

#[cfg_attr(target_os = "windows", ignore)]
Expand All @@ -70,36 +74,35 @@ pub fn test_main_multi_arg() {
.unwrap()
.stdout;
let output = str::from_utf8(&assert).unwrap();
assert!(output.contains(&main_output()));
let mut we_match = false;
for mo in main_output() {
we_match = we_match || output.contains(&mo);
}
assert!(we_match);
}

#[cfg(target_os = "macos")]
fn main_output() -> String {
r#"
fn main_output() -> Vec<String> {
// Some linux currently thought to be Manjaro, Arch
// Although probably depends on how drive is formatted
let mac_and_some_linux = r#"
0B ┌── a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
4.0K ├── hello_file│████████████████████████████████████████████████ │ 100%
4.0K ┌─┴ many │████████████████████████████████████████████████ │ 100%
4.0K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
"#
.trim()
.to_string()
}
.to_string();

#[cfg(target_os = "linux")]
fn main_output() -> String {
r#"
let ubuntu = r#"
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
4.0K ├── hello_file│ ░░░░░░░░░░░░░░░░█████████████████ │ 33%
8.0K ┌─┴ many │ █████████████████████████████████ │ 67%
12K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
"#
.trim()
.to_string()
}
.to_string();

#[cfg(target_os = "windows")]
fn main_output() -> String {
"windows results vary by host".to_string()
vec![mac_and_some_linux, ubuntu]
}

#[cfg_attr(target_os = "windows", ignore)]
Expand All @@ -114,36 +117,32 @@ pub fn test_main_long_paths() {
.unwrap()
.stdout;
let output = str::from_utf8(&assert).unwrap();
assert!(output.contains(&main_output_long_paths()));

let mut we_match = false;
for mo in main_output_long_paths() {
we_match = we_match || output.contains(&mo);
}
assert!(we_match);
}

#[cfg(target_os = "macos")]
fn main_output_long_paths() -> String {
r#"
fn main_output_long_paths() -> Vec<String> {
let mac_and_some_linux = r#"
0B ┌── /tmp/test_dir/many/a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
4.0K ├── /tmp/test_dir/many/hello_file│█████████████████████████████ │ 100%
4.0K ┌─┴ /tmp/test_dir/many │█████████████████████████████ │ 100%
4.0K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100%
"#
.trim()
.to_string()
}

#[cfg(target_os = "linux")]
fn main_output_long_paths() -> String {
r#"
.to_string();
let ubuntu = r#"
0B ┌── /tmp/test_dir/many/a_file │ ░░░░░░░░░░░░░░░░░░░█ │ 0%
4.0K ├── /tmp/test_dir/many/hello_file│ ░░░░░░░░░░██████████ │ 33%
8.0K ┌─┴ /tmp/test_dir/many │ ████████████████████ │ 67%
12K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100%
"#
.trim()
.to_string()
}

#[cfg(target_os = "windows")]
fn main_output_long_paths() -> String {
"windows results vary by host".to_string()
.to_string();
vec![mac_and_some_linux, ubuntu]
}

#[cfg_attr(target_os = "windows", ignore)]
Expand All @@ -153,36 +152,19 @@ pub fn test_apparent_size() {
let mut cmd = Command::cargo_bin("dust").unwrap();
let assert = cmd.arg("-c").arg("-s").arg("/tmp/test_dir").unwrap().stdout;
let output = str::from_utf8(&assert).unwrap();
assert!(output.contains(&output_apparent_size()));
let mut we_match = false;
for mo in output_apparent_size() {
we_match = we_match || output.contains(&mo);
}
assert!(we_match);
}

#[cfg(target_os = "linux")]
fn output_apparent_size() -> String {
r#"
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
6B ├── hello_file│ ░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
4.0K ┌─┴ many │ █████████████████████████ │ 50%
8.0K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
"#
.trim()
.to_string()
}

#[cfg(target_os = "macos")]
fn output_apparent_size() -> String {
r#"
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
6B ├── hello_file│ ░░░░░░░░░░░░░░░░░░░░░░░░░░██ │ 3%
134B ┌─┴ many │ ████████████████████████████ │ 58%
230B ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
"#
.trim()
.to_string()
}

#[cfg(target_os = "windows")]
fn output_apparent_size() -> String {
"windows results vary by host".to_string()
fn output_apparent_size() -> Vec<String> {
// The directory sizes vary a lot based on what the underlying filesystem is
// so different distros give different results. Really we should be checking that
// the standard '4.0K' isn't there
let apparent_size = "6B ├── hello_file│".into();
vec![apparent_size]
}

// Check against directories and files whos names are substrings of each other
Expand All @@ -193,12 +175,15 @@ pub fn test_substring_of_names_and_long_names() {
let mut cmd = Command::cargo_bin("dust").unwrap();
let output = cmd.arg("-c").arg("/tmp/test_dir2").unwrap().stdout;
let output = str::from_utf8(&output).unwrap();
assert!(output.contains(&no_substring_of_names_output()));
let mut we_match = false;
for mo in no_substring_of_names_output() {
we_match = we_match || output.contains(&mo);
}
assert!(we_match);
}

#[cfg(target_os = "linux")]
fn no_substring_of_names_output() -> String {
"
fn no_substring_of_names_output() -> Vec<String> {
let ubuntu = "
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g..
4.0K ├── dir_name_clash
4.0K │ ┌── hello
Expand All @@ -208,12 +193,9 @@ fn no_substring_of_names_output() -> String {
24K ┌─┴ test_dir2
"
.trim()
.into()
}
.into();

#[cfg(target_os = "macos")]
fn no_substring_of_names_output() -> String {
"
let mac_and_some_linux = "
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g..
4.0K │ ┌── hello
4.0K ├─┴ dir
Expand All @@ -223,12 +205,8 @@ fn no_substring_of_names_output() -> String {
12K ┌─┴ test_dir2
"
.trim()
.into()
}

#[cfg(target_os = "windows")]
fn no_substring_of_names_output() -> String {
"PRs".into()
.into();
vec![mac_and_some_linux, ubuntu]
}

#[cfg_attr(target_os = "windows", ignore)]
Expand All @@ -238,33 +216,29 @@ pub fn test_unicode_directories() {
let mut cmd = Command::cargo_bin("dust").unwrap();
let output = cmd.arg("-c").arg("/tmp/test_dir_unicode").unwrap().stdout;
let output = str::from_utf8(&output).unwrap();
assert!(output.contains(&unicode_dir()));
let mut we_match = false;
for mo in unicode_dir() {
we_match = we_match || output.contains(&mo);
}
assert!(we_match);
}

#[cfg(target_os = "linux")]
fn unicode_dir() -> String {
fn unicode_dir() -> Vec<String> {
// The way unicode & asian characters are rendered on the terminal should make this line up
"
let ubuntu = "
0B ┌── ラウトは難しいです!.japan│ █ │ 0%
0B ├── 👩.unicode │ █ │ 0%
4.0K ┌─┴ test_dir_unicode │██████████████████████████████████ │ 100%
"
.trim()
.into()
}
.into();

#[cfg(target_os = "macos")]
fn unicode_dir() -> String {
"
let mac_and_some_linux = "
0B ┌── ラウトは難しいです!.japan│ █ │ 0%
0B ├── 👩.unicode │ █ │ 0%
0B ┌─┴ test_dir_unicode │ █ │ 0%
"
.trim()
.into()
}

#[cfg(target_os = "windows")]
fn unicode_dir() -> String {
"".into()
.into();
vec![mac_and_some_linux, ubuntu]
}