diff --git a/src/main.rs b/src/main.rs index bbc7c00..a59c6fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -307,16 +307,21 @@ fn main() { indicator.stop(); let print_errors = config.get_print_errors(&options); - print_any_errors(print_errors, walk_data.errors); + let final_errors = walk_data.errors.lock().unwrap(); + print_any_errors(print_errors, &final_errors); - print_output( - config, - options, - tree, - walk_data.by_filecount, - is_colors, - terminal_width, - ) + if tree.children.is_empty() && !final_errors.file_not_found.is_empty() { + std::process::exit(1) + } else { + print_output( + config, + options, + tree, + walk_data.by_filecount, + is_colors, + terminal_width, + ) + } }); } @@ -357,8 +362,7 @@ fn print_output( } } -fn print_any_errors(print_errors: bool, errors: Arc>) { - let final_errors = errors.lock().unwrap(); +fn print_any_errors(print_errors: bool, final_errors: &RuntimeErrors) { if !final_errors.file_not_found.is_empty() { let err = final_errors .file_not_found diff --git a/tests/test_flags.rs b/tests/test_flags.rs index 17df511..a096e85 100644 --- a/tests/test_flags.rs +++ b/tests/test_flags.rs @@ -107,7 +107,9 @@ pub fn test_ignore_all_in_file() { #[test] pub fn test_with_bad_param() { let mut cmd = Command::cargo_bin("dust").unwrap(); - let result = cmd.arg("bad_place").unwrap(); + cmd.arg("-P").arg("bad_place"); + let output_error = cmd.unwrap_err(); + let result = output_error.as_output().unwrap(); let stderr = str::from_utf8(&result.stderr).unwrap(); assert!(stderr.contains("No such file or directory")); }