Move from assert_cli to assert_cmd

assert_cli is deprecated.
This allows us to use 'or' in the output of our integration tests
This commit is contained in:
andy.boot
2020-03-23 00:17:10 +00:00
parent 1953e107c2
commit 7cc7047b28
4 changed files with 247 additions and 282 deletions
+94 -84
View File
@@ -1,51 +1,52 @@
use assert_cmd::Command;
use std::str;
mod tests_symlinks;
// File sizes differ on both platform and on the format of the disk.
// We can at least test the file names are there
#[test]
pub fn test_basic_output() {
assert_cli::Assert::main_binary()
.with_args(&["src/test_dir/"])
.stdout()
.contains(" ┌─┴ ")
.stdout()
.contains("test_dir ")
.stdout()
.contains(" ┌─┴ ")
.stdout()
.contains("many ")
.stdout()
.contains(" ├── ")
.stdout()
.contains("hello_file")
.stdout()
.contains(" ┌── ")
.stdout()
.contains("a_file ")
.unwrap();
use tempfile::TempDir;
let mut cmd = Command::cargo_bin("dust").unwrap();
let output = cmd.arg("src/test_dir/").unwrap().stdout;
let output = str::from_utf8(&output).unwrap();
assert!(output.contains(" ┌─┴ "));
assert!(output.contains("test_dir "));
assert!(output.contains(" ┌─┴ "));
assert!(output.contains("many "));
assert!(output.contains(" ├── "));
assert!(output.contains("hello_file"));
assert!(output.contains(" ┌── "));
assert!(output.contains("a_file "));
}
// fix! [rivy; 2020-22-01] "windows" result data can vary by host (size seems to be variable by one byte); fix code vs test and re-enable
// "windows" result data can vary by host (size seems to be variable by one byte); fix code vs test and re-enable
#[cfg_attr(target_os = "windows", ignore)]
#[test]
pub fn test_main_basic() {
// -c is no color mode - This makes testing much simpler
assert_cli::Assert::main_binary()
.with_args(&["-c", "src/test_dir"])
.stdout()
.is(main_output().as_str())
.unwrap();
let mut cmd = Command::cargo_bin("dust").unwrap();
let assert = cmd.arg("-c").arg("src/test_dir/").unwrap().stdout;
let output = str::from_utf8(&assert).unwrap();
assert!(output.contains(&main_output()));
}
// fix! [rivy; 2020-22-01] "windows" result data can vary by host (size seems to be variable by one byte); fix code vs test and re-enable
#[cfg_attr(target_os = "windows", ignore)]
#[test]
pub fn test_main_multi_arg() {
assert_cli::Assert::main_binary()
.with_args(&["-c", "src/test_dir/many/", "src/test_dir/", "src/test_dir"])
.stdout()
.is(main_output().as_str())
.unwrap();
let mut cmd = Command::cargo_bin("dust").unwrap();
let assert = cmd
.arg("-c")
.arg("src/test_dir/many/")
.arg("src/test_dir")
.arg("src/test_dir")
.unwrap()
.stdout;
let output = str::from_utf8(&assert).unwrap();
assert!(output.contains(&main_output()));
}
#[cfg(target_os = "macos")]
@@ -56,6 +57,7 @@ fn main_output() -> String {
4.0K ┌─┴ many │██████████████████████████████████████████████ │ 100%
4.0K ┌─┴ test_dir │██████████████████████████████████████████████ │ 100%
"#
.trim()
.to_string()
}
@@ -66,24 +68,23 @@ fn main_output() -> String {
4.0K ├── hello_file│ ░░░░░░░░░░░░░░░████████████████ │ 33%
8.0K ┌─┴ many │ ███████████████████████████████ │ 67%
12K ┌─┴ test_dir │██████████████████████████████████████████████ │ 100%
"#
"#
.trim()
.to_string()
}
#[cfg(target_os = "windows")]
fn main_output() -> String {
"PRs welcome".to_string()
"windows results vary by host".to_string()
}
// fix! [rivy; 2020-22-01] "windows" result data can vary by host (size seems to be variable by one byte); fix code vs test and re-enable
#[cfg_attr(target_os = "windows", ignore)]
#[test]
pub fn test_main_long_paths() {
assert_cli::Assert::main_binary()
.with_args(&["-c", "-p", "src/test_dir"])
.stdout()
.is(main_output_long_paths().as_str())
.unwrap();
let mut cmd = Command::cargo_bin("dust").unwrap();
let assert = cmd.arg("-c").arg("-p").arg("src/test_dir/").unwrap().stdout;
let output = str::from_utf8(&assert).unwrap();
assert!(output.contains(&main_output_long_paths()));
}
#[cfg(target_os = "macos")]
@@ -93,7 +94,8 @@ fn main_output_long_paths() -> String {
4.0K ├── src/test_dir/many/hello_file│████████████████████████████ │ 100%
4.0K ┌─┴ src/test_dir/many │████████████████████████████ │ 100%
4.0K ┌─┴ src/test_dir │████████████████████████████ │ 100%
"#
"#
.trim()
.to_string()
}
@@ -104,24 +106,23 @@ fn main_output_long_paths() -> String {
4.0K ├── src/test_dir/many/hello_file│ ░░░░░░░░░██████████ │ 33%
8.0K ┌─┴ src/test_dir/many │ ███████████████████ │ 67%
12K ┌─┴ src/test_dir │████████████████████████████ │ 100%
"#
"#
.trim()
.to_string()
}
#[cfg(target_os = "windows")]
fn main_output_long_paths() -> String {
"PRs welcome".to_string()
"windows results vary by host".to_string()
}
// fix! [rivy; 2020-22-01] "windows" result data can vary by host (size seems to be variable by one byte); fix code vs test and re-enable
#[cfg_attr(target_os = "windows", ignore)]
#[test]
pub fn test_apparent_size() {
assert_cli::Assert::main_binary()
.with_args(&["-c", "-s", "src/test_dir"])
.stdout()
.is(output_apparent_size().as_str())
.unwrap();
let mut cmd = Command::cargo_bin("dust").unwrap();
let assert = cmd.arg("-c").arg("-s").arg("src/test_dir").unwrap().stdout;
let output = str::from_utf8(&assert).unwrap();
assert!(output.contains(&output_apparent_size()));
}
#[cfg(target_os = "linux")]
@@ -131,7 +132,8 @@ fn output_apparent_size() -> String {
6B ├── hello_file│ ░░░░░░░░░░░░░░░░░░░░░░░█ │ 0%
4.0K ┌─┴ many │ ████████████████████████ │ 50%
8.0K ┌─┴ test_dir │██████████████████████████████████████████████ │ 100%
"#
"#
.trim()
.to_string()
}
@@ -142,50 +144,51 @@ fn output_apparent_size() -> String {
6B ├── hello_file│ ░░░░░░░░░░░░░░░░░░░░░░░░░██ │ 3%
134B ┌─┴ many │ ███████████████████████████ │ 58%
230B ┌─┴ test_dir │██████████████████████████████████████████████ │ 100%
"#
"#
.trim()
.to_string()
}
#[cfg(target_os = "windows")]
fn output_apparent_size() -> String {
"".to_string()
"windows results vary by host".to_string()
}
#[test]
pub fn test_reverse_flag() {
assert_cli::Assert::main_binary()
.with_args(&["-c", "-r", "src/test_dir/"])
.stdout()
.contains(" └─┬ test_dir ")
.stdout()
.contains(" └─┬ many ")
.stdout()
.contains(" ── hello_file")
.stdout()
.contains(" └── a_file ")
.unwrap();
let mut cmd = Command::cargo_bin("dust").unwrap();
let output = cmd.arg("-c").arg("-r").arg("src/test_dir/").unwrap().stdout;
let output = str::from_utf8(&output).unwrap();
assert!(output.contains(" └─┬ test_dir "));
assert!(output.contains(" └─┬ many "));
assert!(output.contains(" ├── hello_file"));
assert!(output.contains(" ── a_file "));
}
#[test]
pub fn test_d_flag_works() {
// We should see the top level directory but not the sub dirs / files:
assert_cli::Assert::main_binary()
.with_args(&["-d", "1", "-s", "src/test_dir"])
.stdout()
.doesnt_contain("hello_file")
.unwrap();
let mut cmd = Command::cargo_bin("dust").unwrap();
let output = cmd
.arg("-d")
.arg("1")
.arg("-s")
.arg("src/test_dir/")
.unwrap()
.stdout;
let output = str::from_utf8(&output).unwrap();
assert!(!output.contains("hello_file"));
}
// Check against directories and files whos names are substrings of each other
// fix! [rivy; 2020-22-01] "windows" result data can vary by host (size seems to be variable by one byte); fix code vs test and re-enable
#[cfg_attr(target_os = "windows", ignore)]
#[test]
pub fn test_substring_of_names() {
assert_cli::Assert::main_binary()
.with_args(&["-c", "src/test_dir2"])
.stdout()
.is(no_substring_of_names_output().as_str())
.unwrap();
let mut cmd = Command::cargo_bin("dust").unwrap();
let output = cmd.arg("-c").arg("src/test_dir2").unwrap().stdout;
let output = str::from_utf8(&output).unwrap();
assert!(output.contains(&no_substring_of_names_output()));
}
#[cfg(target_os = "linux")]
@@ -198,6 +201,7 @@ fn no_substring_of_names_output() -> String {
8.0K ├─┴ dir │ ███████████████ │ 33%
24K ┌─┴ test_dir2 │████████████████████████████████████████████ │ 100%
"
.trim()
.into()
}
@@ -211,6 +215,7 @@ fn no_substring_of_names_output() -> String {
4.0K ├─┴ dir │ ███████████████ │ 33%
12K ┌─┴ test_dir2 │████████████████████████████████████████████ │ 100%
"
.trim()
.into()
}
@@ -219,15 +224,13 @@ fn no_substring_of_names_output() -> String {
"PRs".into()
}
// fix! [rivy; 2020-22-01] "windows" result data can vary by host (size seems to be variable by one byte); fix code vs test and re-enable
#[cfg_attr(target_os = "windows", ignore)]
#[test]
pub fn test_unicode_directories() {
assert_cli::Assert::main_binary()
.with_args(&["-c", "src/test_dir3"])
.stdout()
.is(unicode_dir().as_str())
.unwrap();
let mut cmd = Command::cargo_bin("dust").unwrap();
let output = cmd.arg("-c").arg("src/test_dir3").unwrap().stdout;
let output = str::from_utf8(&output).unwrap();
assert!(output.contains(&unicode_dir()));
}
#[cfg(target_os = "linux")]
@@ -238,6 +241,7 @@ fn unicode_dir() -> String {
0B ├── ラウトは難しいです!.japan│ █ │ 0%
4.0K ┌─┴ test_dir3 │████████████████████████████████ │ 100%
"
.trim()
.into()
}
@@ -248,6 +252,7 @@ fn unicode_dir() -> String {
0B ├── ラウトは難しいです!.japan│ █ │ 0%
0B ┌─┴ test_dir3 │ █ │ 0%
"
.trim()
.into()
}
@@ -259,9 +264,14 @@ fn unicode_dir() -> String {
// Check against directories and files whos names are substrings of each other
#[test]
pub fn test_ignore_dir() {
assert_cli::Assert::main_binary()
.with_args(&["-c", "-X", "dir_substring", "src/test_dir2"])
.stdout()
.doesnt_contain("dir_substring")
.unwrap();
let mut cmd = Command::cargo_bin("dust").unwrap();
let output = cmd
.arg("-c")
.arg("-X")
.arg("dir_substring")
.arg("src/test_dir3")
.unwrap()
.stdout;
let output = str::from_utf8(&output).unwrap();
assert!(!output.contains("dir_substring"));
}