mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
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:
+94
-84
@@ -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"));
|
||||
}
|
||||
|
||||
+43
-57
@@ -1,8 +1,9 @@
|
||||
use assert_cmd::Command;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::panic;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::str;
|
||||
use tempfile::Builder;
|
||||
use tempfile::TempDir;
|
||||
|
||||
@@ -37,59 +38,45 @@ pub fn test_soft_sym_link() {
|
||||
let b = format!(" ├── {}", file_path_s);
|
||||
let a = format!("─┴ {}", dir_s);
|
||||
|
||||
assert_cli::Assert::main_binary()
|
||||
.with_args(&["-p", "-c", &dir_s])
|
||||
.stdout()
|
||||
.contains(a.as_str())
|
||||
.stdout()
|
||||
.contains(b.as_str())
|
||||
.stdout()
|
||||
.contains(c.as_str())
|
||||
.unwrap();
|
||||
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||
let output = cmd.arg("-p").arg("-c").arg(dir_s).unwrap().stdout;
|
||||
|
||||
let output = str::from_utf8(&output).unwrap();
|
||||
|
||||
assert!(output.contains(a.as_str()));
|
||||
assert!(output.contains(b.as_str()));
|
||||
assert!(output.contains(c.as_str()));
|
||||
}
|
||||
|
||||
// TODO: Replace with assert_cmd library
|
||||
// #[cfg_attr(target_os = "windows", ignore)]
|
||||
// #[test]
|
||||
// pub fn test_hard_sym_link() {
|
||||
// let dir = Builder::new().tempdir().unwrap();
|
||||
// let file = build_temp_file(&dir);
|
||||
// let dir_s = dir.path().to_str().unwrap();
|
||||
// let file_path_s = file.to_str().unwrap();
|
||||
#[cfg_attr(target_os = "windows", ignore)]
|
||||
#[test]
|
||||
pub fn test_hard_sym_link() {
|
||||
let dir = Builder::new().tempdir().unwrap();
|
||||
let file = build_temp_file(&dir);
|
||||
let dir_s = dir.path().to_str().unwrap();
|
||||
let file_path_s = file.to_str().unwrap();
|
||||
|
||||
// let link_name = dir.path().join("the_link");
|
||||
// let link_name_s = link_name.to_str().unwrap();
|
||||
// let c = Command::new("ln")
|
||||
// .arg(file_path_s)
|
||||
// .arg(link_name_s)
|
||||
// .output();
|
||||
// assert!(c.is_ok());
|
||||
let link_name = dir.path().join("the_link");
|
||||
let link_name_s = link_name.to_str().unwrap();
|
||||
let c = Command::new("ln")
|
||||
.arg(file_path_s)
|
||||
.arg(link_name_s)
|
||||
.output();
|
||||
assert!(c.is_ok());
|
||||
|
||||
// let a = format!("─┴ {}", dir_s);
|
||||
// let b = format!(" ┌── {}", link_name_s);
|
||||
// let b2 = format!(" ┌── {}", file_path_s);
|
||||
let link_output = format!(" ┌── {}", link_name_s);
|
||||
let file_output = format!(" ┌── {}", file_path_s);
|
||||
let dirs_output = format!("─┴ {}", dir_s);
|
||||
|
||||
// // Because this is a hard link the file and hard link look identical. Therefore
|
||||
// // we cannot guarantee which version will appear first.
|
||||
// let result = panic::catch_unwind(|| {
|
||||
// assert_cli::Assert::main_binary()
|
||||
// .with_args(&["-p", "-c", dir_s])
|
||||
// .stdout()
|
||||
// .contains(a.as_str())
|
||||
// .stdout()
|
||||
// .contains(b2.as_str())
|
||||
// .unwrap();
|
||||
// });
|
||||
// if result.is_err() {
|
||||
// assert_cli::Assert::main_binary()
|
||||
// .with_args(&["-p", "-c", dir_s])
|
||||
// .stdout()
|
||||
// .contains(a.as_str())
|
||||
// .stdout()
|
||||
// .contains(b.as_str())
|
||||
// .unwrap();
|
||||
// }
|
||||
// }
|
||||
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||
let output = cmd.arg("-p").arg("-c").arg(dir_s).unwrap().stdout;
|
||||
|
||||
// Because this is a hard link the file and hard link look identical. Therefore
|
||||
// we cannot guarantee which version will appear first.
|
||||
let output = str::from_utf8(&output).unwrap();
|
||||
assert!(output.contains(dirs_output.as_str()));
|
||||
assert!(output.contains(link_output.as_str()) || output.contains(file_output.as_str()));
|
||||
}
|
||||
|
||||
#[cfg_attr(target_os = "windows", ignore)]
|
||||
#[test]
|
||||
@@ -108,13 +95,12 @@ pub fn test_recursive_sym_link() {
|
||||
assert!(c.is_ok());
|
||||
|
||||
let a = format!("─┬ {}", dir_s);
|
||||
let b = format!(" └── {}", link_name_s);
|
||||
let b = format!(" └── {}", link_name_s);
|
||||
|
||||
assert_cli::Assert::main_binary()
|
||||
.with_args(&["-c", "-r", "-p", dir_s])
|
||||
.stdout()
|
||||
.contains(a.as_str())
|
||||
.stdout()
|
||||
.contains(b.as_str())
|
||||
.unwrap();
|
||||
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||
let output = cmd.arg("-p").arg("-c").arg("-r").arg(dir_s).unwrap().stdout;
|
||||
|
||||
let output = str::from_utf8(&output).unwrap();
|
||||
assert!(output.contains(a.as_str()));
|
||||
assert!(output.contains(b.as_str()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user