mirror of
https://github.com/bootandy/dust.git
synced 2025-12-11 15:20:39 -08:00
Compare commits
1 Commits
same_dir_n
...
clean_test
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f93c90f5e |
@@ -1,5 +1,6 @@
|
|||||||
use assert_cmd::Command;
|
use assert_cmd::Command;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
use std::process::Output;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::sync::Once;
|
use std::sync::Once;
|
||||||
|
|
||||||
@@ -38,48 +39,44 @@ fn initialize() {
|
|||||||
copy_test_data("tests/test_dir");
|
copy_test_data("tests/test_dir");
|
||||||
copy_test_data("tests/test_dir2");
|
copy_test_data("tests/test_dir2");
|
||||||
copy_test_data("tests/test_dir_unicode");
|
copy_test_data("tests/test_dir_unicode");
|
||||||
|
|
||||||
|
Command::new("sh")
|
||||||
|
.arg("-c")
|
||||||
|
.arg("mkdir -p /tmp/unreadable_folder && chmod 000 /tmp/unreadable_folder")
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exact_output_test<T: AsRef<OsStr>>(
|
fn run_cmd<T: AsRef<OsStr>>(command_args: Vec<T>) -> Output {
|
||||||
command_args: Vec<T>,
|
|
||||||
valid_outputs: Vec<String>,
|
|
||||||
error_outputs: Vec<String>,
|
|
||||||
) {
|
|
||||||
initialize();
|
initialize();
|
||||||
|
let mut to_run = &mut Command::cargo_bin("dust").unwrap();
|
||||||
let mut a = &mut Command::cargo_bin("dust").unwrap();
|
|
||||||
|
|
||||||
for p in command_args {
|
for p in command_args {
|
||||||
a = a.arg(p);
|
to_run = to_run.arg(p);
|
||||||
}
|
}
|
||||||
|
to_run.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
if !valid_outputs.is_empty() {
|
fn exact_stdout_test<T: AsRef<OsStr>>(command_args: Vec<T>, valid_stdout: Vec<String>) {
|
||||||
let stdout_output = str::from_utf8(&a.unwrap().stdout).unwrap().to_owned();
|
let to_run = run_cmd(command_args);
|
||||||
let will_fail = valid_outputs.iter().any(|i| stdout_output.contains(i));
|
|
||||||
if !will_fail {
|
|
||||||
eprintln!(
|
|
||||||
"output(stdout):\n{}\ndoes not contain any of:\n{}",
|
|
||||||
stdout_output,
|
|
||||||
valid_outputs.join("\n\n")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
assert!(will_fail);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check stderr
|
let stdout_output = str::from_utf8(&to_run.stdout).unwrap().to_owned();
|
||||||
if !error_outputs.is_empty() {
|
let will_fail = valid_stdout.iter().any(|i| stdout_output.contains(i));
|
||||||
let stderr_output = str::from_utf8(&a.unwrap().stderr).unwrap().to_owned();
|
if !will_fail {
|
||||||
let will_fail = error_outputs.iter().any(|i| stderr_output.contains(i));
|
eprintln!(
|
||||||
if !will_fail {
|
"output(stdout):\n{}\ndoes not contain any of:\n{}",
|
||||||
eprintln!(
|
stdout_output,
|
||||||
"output(stderr):\n{}\ndoes not contain any of:\n{}",
|
valid_stdout.join("\n\n")
|
||||||
stderr_output,
|
);
|
||||||
valid_outputs.join("\n\n")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
assert!(will_fail);
|
|
||||||
}
|
}
|
||||||
|
assert!(will_fail);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exact_stderr_test<T: AsRef<OsStr>>(command_args: Vec<T>, valid_stderr: String) {
|
||||||
|
let to_run = run_cmd(command_args);
|
||||||
|
|
||||||
|
let stderr_output = str::from_utf8(&to_run.stderr).unwrap().trim();
|
||||||
|
assert_eq!(stderr_output, valid_stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// "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
|
||||||
@@ -87,7 +84,7 @@ fn exact_output_test<T: AsRef<OsStr>>(
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_main_basic() {
|
pub fn test_main_basic() {
|
||||||
// -c is no color mode - This makes testing much simpler
|
// -c is no color mode - This makes testing much simpler
|
||||||
exact_output_test(vec!["-c", "-B", "/tmp/test_dir/"], main_output(), vec![]);
|
exact_stdout_test(vec!["-c", "-B", "/tmp/test_dir/"], main_output());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(target_os = "windows", ignore)]
|
#[cfg_attr(target_os = "windows", ignore)]
|
||||||
@@ -100,7 +97,7 @@ pub fn test_main_multi_arg() {
|
|||||||
"/tmp/test_dir",
|
"/tmp/test_dir",
|
||||||
"/tmp/test_dir",
|
"/tmp/test_dir",
|
||||||
];
|
];
|
||||||
exact_output_test(command_args, main_output(), vec![]);
|
exact_stdout_test(command_args, main_output());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main_output() -> Vec<String> {
|
fn main_output() -> Vec<String> {
|
||||||
@@ -131,7 +128,7 @@ fn main_output() -> Vec<String> {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_main_long_paths() {
|
pub fn test_main_long_paths() {
|
||||||
let command_args = vec!["-c", "-p", "-B", "/tmp/test_dir/"];
|
let command_args = vec!["-c", "-p", "-B", "/tmp/test_dir/"];
|
||||||
exact_output_test(command_args, main_output_long_paths(), vec![]);
|
exact_stdout_test(command_args, main_output_long_paths());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main_output_long_paths() -> Vec<String> {
|
fn main_output_long_paths() -> Vec<String> {
|
||||||
@@ -159,7 +156,7 @@ fn main_output_long_paths() -> Vec<String> {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_substring_of_names_and_long_names() {
|
pub fn test_substring_of_names_and_long_names() {
|
||||||
let command_args = vec!["-c", "-B", "/tmp/test_dir2"];
|
let command_args = vec!["-c", "-B", "/tmp/test_dir2"];
|
||||||
exact_output_test(command_args, no_substring_of_names_output(), vec![]);
|
exact_stdout_test(command_args, no_substring_of_names_output());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn no_substring_of_names_output() -> Vec<String> {
|
fn no_substring_of_names_output() -> Vec<String> {
|
||||||
@@ -193,7 +190,7 @@ fn no_substring_of_names_output() -> Vec<String> {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_unicode_directories() {
|
pub fn test_unicode_directories() {
|
||||||
let command_args = vec!["-c", "-B", "/tmp/test_dir_unicode"];
|
let command_args = vec!["-c", "-B", "/tmp/test_dir_unicode"];
|
||||||
exact_output_test(command_args, unicode_dir(), vec![]);
|
exact_stdout_test(command_args, unicode_dir());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unicode_dir() -> Vec<String> {
|
fn unicode_dir() -> Vec<String> {
|
||||||
@@ -220,7 +217,7 @@ fn unicode_dir() -> Vec<String> {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_apparent_size() {
|
pub fn test_apparent_size() {
|
||||||
let command_args = vec!["-c", "-s", "-b", "/tmp/test_dir"];
|
let command_args = vec!["-c", "-s", "-b", "/tmp/test_dir"];
|
||||||
exact_output_test(command_args, apparent_size_output(), vec![]);
|
exact_stdout_test(command_args, apparent_size_output());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apparent_size_output() -> Vec<String> {
|
fn apparent_size_output() -> Vec<String> {
|
||||||
@@ -245,38 +242,21 @@ fn apparent_size_output() -> Vec<String> {
|
|||||||
#[cfg_attr(target_os = "windows", ignore)]
|
#[cfg_attr(target_os = "windows", ignore)]
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_permission_normal() {
|
pub fn test_permission_normal() {
|
||||||
Command::new("sh")
|
|
||||||
.arg("-c")
|
|
||||||
.arg("mkdir -p /tmp/unreadable_folder && chmod 000 /tmp/unreadable_folder")
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
let command_args = vec!["/tmp/unreadable_folder"];
|
let command_args = vec!["/tmp/unreadable_folder"];
|
||||||
let permission_msg = r#"Did not have permissions for all"#.trim().to_string();
|
let permission_msg =
|
||||||
exact_output_test(command_args, vec![], vec![permission_msg]);
|
r#"Did not have permissions for all directories (add --print-errors to see errors)"#
|
||||||
|
.trim()
|
||||||
Command::new("sh")
|
.to_string();
|
||||||
.arg("-c")
|
exact_stderr_test(command_args, permission_msg);
|
||||||
.arg("chmod 555 /tmp/unreadable_folder")
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(target_os = "windows", ignore)]
|
#[cfg_attr(target_os = "windows", ignore)]
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_permission_flag() {
|
pub fn test_permission_flag() {
|
||||||
Command::new("sh")
|
|
||||||
.arg("-c")
|
|
||||||
.arg("mkdir -p /tmp/unreadable_folder && chmod 000 /tmp/unreadable_folder")
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
// add the flag to CLI
|
// add the flag to CLI
|
||||||
let command_args = vec!["--print-errors", "/tmp/unreadable_folder"];
|
let command_args = vec!["--print-errors", "/tmp/unreadable_folder"];
|
||||||
let permission_msg = r#"Did not have permissions for directories"#.trim().to_string();
|
let permission_msg = r#"Did not have permissions for directories: /tmp/unreadable_folder"#
|
||||||
exact_output_test(command_args, vec![], vec![permission_msg]);
|
.trim()
|
||||||
|
.to_string();
|
||||||
Command::new("sh")
|
exact_stderr_test(command_args, permission_msg);
|
||||||
.arg("-c")
|
|
||||||
.arg("chmod 555 /tmp/unreadable_folder")
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user