Possible test fix: Some tests fail on some linux

An issue raised that the test output looked a lot like the mac output.
This change causes test to pass if output is either mac or linux style
This commit is contained in:
andy.boot
2021-08-05 15:12:13 +01:00
parent 2047f99c6d
commit 2ad420d370
+63 -89
View File
@@ -54,7 +54,11 @@ pub fn test_main_basic() {
let mut cmd = Command::cargo_bin("dust").unwrap(); let mut cmd = Command::cargo_bin("dust").unwrap();
let assert = cmd.arg("-c").arg("/tmp/test_dir/").unwrap().stdout; let assert = cmd.arg("-c").arg("/tmp/test_dir/").unwrap().stdout;
let output = str::from_utf8(&assert).unwrap(); 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)] #[cfg_attr(target_os = "windows", ignore)]
@@ -70,36 +74,35 @@ pub fn test_main_multi_arg() {
.unwrap() .unwrap()
.stdout; .stdout;
let output = str::from_utf8(&assert).unwrap(); 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() -> Vec<String> {
fn main_output() -> String { // Some linux currently thought to be Manjaro, Arch
r#" // Although probably depends on how drive is formatted
let mac_and_some_linux = r#"
0B ┌── a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0% 0B ┌── a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
4.0K ├── hello_file│████████████████████████████████████████████████ │ 100% 4.0K ├── hello_file│████████████████████████████████████████████████ │ 100%
4.0K ┌─┴ many │████████████████████████████████████████████████ │ 100% 4.0K ┌─┴ many │████████████████████████████████████████████████ │ 100%
4.0K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100% 4.0K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
"# "#
.trim() .trim()
.to_string() .to_string();
}
#[cfg(target_os = "linux")] let ubuntu = r#"
fn main_output() -> String {
r#"
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0% 0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
4.0K ├── hello_file│ ░░░░░░░░░░░░░░░░█████████████████ │ 33% 4.0K ├── hello_file│ ░░░░░░░░░░░░░░░░█████████████████ │ 33%
8.0K ┌─┴ many │ █████████████████████████████████ │ 67% 8.0K ┌─┴ many │ █████████████████████████████████ │ 67%
12K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100% 12K ┌─┴ test_dir │████████████████████████████████████████████████ │ 100%
"# "#
.trim() .trim()
.to_string() .to_string();
}
#[cfg(target_os = "windows")] vec![mac_and_some_linux, ubuntu]
fn main_output() -> String {
"windows results vary by host".to_string()
} }
#[cfg_attr(target_os = "windows", ignore)] #[cfg_attr(target_os = "windows", ignore)]
@@ -114,36 +117,32 @@ pub fn test_main_long_paths() {
.unwrap() .unwrap()
.stdout; .stdout;
let output = str::from_utf8(&assert).unwrap(); 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() -> Vec<String> {
fn main_output_long_paths() -> String { let mac_and_some_linux = r#"
r#"
0B ┌── /tmp/test_dir/many/a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0% 0B ┌── /tmp/test_dir/many/a_file │░░░░░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
4.0K ├── /tmp/test_dir/many/hello_file│█████████████████████████████ │ 100% 4.0K ├── /tmp/test_dir/many/hello_file│█████████████████████████████ │ 100%
4.0K ┌─┴ /tmp/test_dir/many │█████████████████████████████ │ 100% 4.0K ┌─┴ /tmp/test_dir/many │█████████████████████████████ │ 100%
4.0K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100% 4.0K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100%
"# "#
.trim() .trim()
.to_string() .to_string();
} let ubuntu = r#"
#[cfg(target_os = "linux")]
fn main_output_long_paths() -> String {
r#"
0B ┌── /tmp/test_dir/many/a_file │ ░░░░░░░░░░░░░░░░░░░█ │ 0% 0B ┌── /tmp/test_dir/many/a_file │ ░░░░░░░░░░░░░░░░░░░█ │ 0%
4.0K ├── /tmp/test_dir/many/hello_file│ ░░░░░░░░░░██████████ │ 33% 4.0K ├── /tmp/test_dir/many/hello_file│ ░░░░░░░░░░██████████ │ 33%
8.0K ┌─┴ /tmp/test_dir/many │ ████████████████████ │ 67% 8.0K ┌─┴ /tmp/test_dir/many │ ████████████████████ │ 67%
12K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100% 12K ┌─┴ /tmp/test_dir │█████████████████████████████ │ 100%
"# "#
.trim() .trim()
.to_string() .to_string();
} vec![mac_and_some_linux, ubuntu]
#[cfg(target_os = "windows")]
fn main_output_long_paths() -> String {
"windows results vary by host".to_string()
} }
#[cfg_attr(target_os = "windows", ignore)] #[cfg_attr(target_os = "windows", ignore)]
@@ -153,36 +152,19 @@ pub fn test_apparent_size() {
let mut cmd = Command::cargo_bin("dust").unwrap(); let mut cmd = Command::cargo_bin("dust").unwrap();
let assert = cmd.arg("-c").arg("-s").arg("/tmp/test_dir").unwrap().stdout; let assert = cmd.arg("-c").arg("-s").arg("/tmp/test_dir").unwrap().stdout;
let output = str::from_utf8(&assert).unwrap(); 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() -> Vec<String> {
fn output_apparent_size() -> String { // The directory sizes vary a lot based on what the underlying filesystem is
r#" // so different distros give different results. Really we should be checking that
0B ┌── a_file │ ░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0% // the standard '4.0K' isn't there
6B ├── hello_file│ ░░░░░░░░░░░░░░░░░░░░░░░░█ │ 0% let apparent_size = "6B ├── hello_file│".into();
4.0K ┌─┴ many │ █████████████████████████ │ 50% vec![apparent_size]
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()
} }
// Check against directories and files whos names are substrings of each other // Check against directories and files whos names are substrings of each other
@@ -193,12 +175,15 @@ pub fn test_substring_of_names_and_long_names() {
let mut cmd = Command::cargo_bin("dust").unwrap(); let mut cmd = Command::cargo_bin("dust").unwrap();
let output = cmd.arg("-c").arg("/tmp/test_dir2").unwrap().stdout; let output = cmd.arg("-c").arg("/tmp/test_dir2").unwrap().stdout;
let output = str::from_utf8(&output).unwrap(); 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() -> Vec<String> {
fn no_substring_of_names_output() -> String { let ubuntu = "
"
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g.. 0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g..
4.0K ├── dir_name_clash 4.0K ├── dir_name_clash
4.0K │ ┌── hello 4.0K │ ┌── hello
@@ -208,12 +193,9 @@ fn no_substring_of_names_output() -> String {
24K ┌─┴ test_dir2 24K ┌─┴ test_dir2
" "
.trim() .trim()
.into() .into();
}
#[cfg(target_os = "macos")] let mac_and_some_linux = "
fn no_substring_of_names_output() -> String {
"
0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g.. 0B ┌── long_dir_name_what_a_very_long_dir_name_what_happens_when_this_g..
4.0K │ ┌── hello 4.0K │ ┌── hello
4.0K ├─┴ dir 4.0K ├─┴ dir
@@ -223,12 +205,8 @@ fn no_substring_of_names_output() -> String {
12K ┌─┴ test_dir2 12K ┌─┴ test_dir2
" "
.trim() .trim()
.into() .into();
} vec![mac_and_some_linux, ubuntu]
#[cfg(target_os = "windows")]
fn no_substring_of_names_output() -> String {
"PRs".into()
} }
#[cfg_attr(target_os = "windows", ignore)] #[cfg_attr(target_os = "windows", ignore)]
@@ -238,33 +216,29 @@ pub fn test_unicode_directories() {
let mut cmd = Command::cargo_bin("dust").unwrap(); let mut cmd = Command::cargo_bin("dust").unwrap();
let output = cmd.arg("-c").arg("/tmp/test_dir_unicode").unwrap().stdout; let output = cmd.arg("-c").arg("/tmp/test_dir_unicode").unwrap().stdout;
let output = str::from_utf8(&output).unwrap(); 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() -> Vec<String> {
fn unicode_dir() -> String {
// The way unicode & asian characters are rendered on the terminal should make this line up // The way unicode & asian characters are rendered on the terminal should make this line up
" let ubuntu = "
0B ┌── ラウトは難しいです!.japan│ █ │ 0% 0B ┌── ラウトは難しいです!.japan│ █ │ 0%
0B ├── 👩.unicode │ █ │ 0% 0B ├── 👩.unicode │ █ │ 0%
4.0K ┌─┴ test_dir_unicode │██████████████████████████████████ │ 100% 4.0K ┌─┴ test_dir_unicode │██████████████████████████████████ │ 100%
" "
.trim() .trim()
.into() .into();
}
#[cfg(target_os = "macos")] let mac_and_some_linux = "
fn unicode_dir() -> String {
"
0B ┌── ラウトは難しいです!.japan│ █ │ 0% 0B ┌── ラウトは難しいです!.japan│ █ │ 0%
0B ├── 👩.unicode │ █ │ 0% 0B ├── 👩.unicode │ █ │ 0%
0B ┌─┴ test_dir_unicode │ █ │ 0% 0B ┌─┴ test_dir_unicode │ █ │ 0%
" "
.trim() .trim()
.into() .into();
} vec![mac_and_some_linux, ubuntu]
#[cfg(target_os = "windows")]
fn unicode_dir() -> String {
"".into()
} }