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
+43 -57
View File
@@ -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()));
}