diff --git a/tests/by-util/test_base32.rs b/tests/by-util/test_base32.rs index 178341f44..5c74c5b59 100644 --- a/tests/by-util/test_base32.rs +++ b/tests/by-util/test_base32.rs @@ -85,11 +85,15 @@ fn test_wrap() { #[test] fn test_wrap_no_arg() { for wrap_param in &["-w", "--wrap"] { - let expected_stderr = "error: The argument '--wrap \' requires a value but none was \ - supplied\n\nUSAGE:\n base32 [OPTION]... [FILE]\n\nFor more \ - information try --help" - .to_string(); - new_ucmd!() + let ts = TestScenario::new(util_name!()); + let expected_stderr = &format!( + "error: The argument '--wrap \' requires a value but none was \ + supplied\n\nUSAGE:\n {1} {0} [OPTION]... [FILE]\n\nFor more \ + information try --help", + ts.util_name, + ts.bin_path.to_string_lossy() + ); + ts.ucmd() .arg(wrap_param) .fails() .stderr_only(expected_stderr); diff --git a/tests/by-util/test_basename.rs b/tests/by-util/test_basename.rs index d9632106e..9701e9973 100644 --- a/tests/by-util/test_basename.rs +++ b/tests/by-util/test_basename.rs @@ -114,9 +114,12 @@ fn test_no_args() { #[test] fn test_no_args_output() { - new_ucmd!() - .fails() - .stderr_is("basename: missing operand\nTry 'basename --help' for more information."); + let ts = TestScenario::new(util_name!()); + ts.ucmd().fails().stderr_is(&format!( + "{0}: missing operand\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] @@ -126,10 +129,12 @@ fn test_too_many_args() { #[test] fn test_too_many_args_output() { - new_ucmd!() - .args(&["a", "b", "c"]) - .fails() - .stderr_is("basename: extra operand 'c'\nTry 'basename --help' for more information."); + let ts = TestScenario::new(util_name!()); + ts.ucmd().args(&["a", "b", "c"]).fails().stderr_is(format!( + "{0}: extra operand 'c'\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[cfg(any(unix, target_os = "redox"))] diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 541e6b5d9..6d739f448 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -561,14 +561,17 @@ fn test_cp_backup_off() { #[test] fn test_cp_backup_no_clobber_conflicting_options() { - let (_, mut ucmd) = at_and_ucmd!(); - - ucmd.arg("--backup") + let ts = TestScenario::new(util_name!()); + ts.ucmd() + .arg("--backup") .arg("--no-clobber") .arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_HOW_ARE_YOU_SOURCE) - .fails() - .stderr_is("cp: options --backup and --no-clobber are mutually exclusive\nTry 'cp --help' for more information."); + .fails().stderr_is(&format!( + "{0}: options --backup and --no-clobber are mutually exclusive\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] diff --git a/tests/by-util/test_more.rs b/tests/by-util/test_more.rs index 9b28ee24e..a422b23a5 100644 --- a/tests/by-util/test_more.rs +++ b/tests/by-util/test_more.rs @@ -15,11 +15,15 @@ fn test_more_dir_arg() { // Maybe we could capture the error, i.e. "Device not found" in that case // but I am leaving this for later if atty::is(atty::Stream::Stdout) { - let result = new_ucmd!().arg(".").run(); + let ts = TestScenario::new(util_name!()); + let result = ts.ucmd().arg(".").run(); result.failure(); - const EXPECTED_ERROR_MESSAGE: &str = - "more: '.' is a directory.\nTry 'more --help' for more information."; - assert_eq!(result.stderr_str().trim(), EXPECTED_ERROR_MESSAGE); + let expected_error_message = &format!( + "{0}: '.' is a directory.\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + ); + assert_eq!(result.stderr_str().trim(), expected_error_message); } else { } } diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 02c65f68d..8596f8477 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -522,14 +522,17 @@ fn test_mv_backup_off() { #[test] fn test_mv_backup_no_clobber_conflicting_options() { - let (_, mut ucmd) = at_and_ucmd!(); + let ts = TestScenario::new(util_name!()); - ucmd.arg("--backup") + ts.ucmd().arg("--backup") .arg("--no-clobber") .arg("file1") .arg("file2") .fails() - .stderr_is("mv: options --backup and --no-clobber are mutually exclusive\nTry 'mv --help' for more information."); + .stderr_is(&format!("{0}: options --backup and --no-clobber are mutually exclusive\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] diff --git a/tests/by-util/test_nice.rs b/tests/by-util/test_nice.rs index 25886de78..639fa5697 100644 --- a/tests/by-util/test_nice.rs +++ b/tests/by-util/test_nice.rs @@ -22,10 +22,15 @@ fn test_negative_adjustment() { #[test] fn test_adjustment_with_no_command_should_error() { - new_ucmd!() + let ts = TestScenario::new(util_name!()); + + ts.ucmd() .args(&["-n", "19"]) .run() - .stderr_is("nice: A command must be given with an adjustment.\nTry \"nice --help\" for more information.\n"); + .stderr_is(&format!("{0}: A command must be given with an adjustment.\nTry `{1} {0} --help` for more information.\n", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index 0592be244..32bc43837 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -255,10 +255,12 @@ fn test_rm_force_no_operand() { #[test] fn test_rm_no_operand() { - let mut ucmd = new_ucmd!(); - - ucmd.fails() - .stderr_is("rm: missing an argument\nrm: for help, try 'rm --help'\n"); + let ts = TestScenario::new(util_name!()); + ts.ucmd().fails().stderr_is(&format!( + "{0}: missing an argument\n{0}: for help, try '{1} {0} --help'\n", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] diff --git a/tests/by-util/test_seq.rs b/tests/by-util/test_seq.rs index be04bf1fd..cc94d4b1f 100644 --- a/tests/by-util/test_seq.rs +++ b/tests/by-util/test_seq.rs @@ -2,16 +2,24 @@ use crate::common::util::*; #[test] fn test_rejects_nan() { - new_ucmd!().args(&["NaN"]).fails().stderr_only( - "seq: invalid 'not-a-number' argument: 'NaN'\nTry 'seq --help' for more information.", - ); + let ts = TestScenario::new(util_name!()); + + ts.ucmd().args(&["NaN"]).fails().stderr_only(format!( + "{0}: invalid 'not-a-number' argument: 'NaN'\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] fn test_rejects_non_floats() { - new_ucmd!().args(&["foo"]).fails().stderr_only( - "seq: invalid floating point argument: 'foo'\nTry 'seq --help' for more information.", - ); + let ts = TestScenario::new(util_name!()); + + ts.ucmd().args(&["foo"]).fails().stderr_only(&format!( + "{0}: invalid floating point argument: 'foo'\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } // ---- Tests for the big integer based path ---- diff --git a/tests/by-util/test_stdbuf.rs b/tests/by-util/test_stdbuf.rs index 66892ea0f..d705c0854 100644 --- a/tests/by-util/test_stdbuf.rs +++ b/tests/by-util/test_stdbuf.rs @@ -25,15 +25,19 @@ fn test_stdbuf_line_buffered_stdout() { #[cfg(not(target_os = "windows"))] #[test] fn test_stdbuf_no_buffer_option_fails() { - new_ucmd!().args(&["head"]).fails().stderr_is( + let ts = TestScenario::new(util_name!()); + + ts.ucmd().args(&["head"]).fails().stderr_is(&format!( "error: The following required arguments were not provided:\n \ --error \n \ --input \n \ --output \n\n\ USAGE:\n \ - stdbuf OPTION... COMMAND\n\n\ + {1} {0} OPTION... COMMAND\n\n\ For more information try --help", - ); + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[cfg(not(target_os = "windows"))] @@ -49,9 +53,16 @@ fn test_stdbuf_trailing_var_arg() { #[cfg(not(target_os = "windows"))] #[test] fn test_stdbuf_line_buffering_stdin_fails() { - new_ucmd!().args(&["-i", "L", "head"]).fails().stderr_is( - "stdbuf: line buffering stdin is meaningless\nTry 'stdbuf --help' for more information.", - ); + let ts = TestScenario::new(util_name!()); + + ts.ucmd() + .args(&["-i", "L", "head"]) + .fails() + .stderr_is(&format!( + "{0}: line buffering stdin is meaningless\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[cfg(not(target_os = "windows"))] diff --git a/tests/by-util/test_unlink.rs b/tests/by-util/test_unlink.rs index 1999e965c..0c82b6a39 100644 --- a/tests/by-util/test_unlink.rs +++ b/tests/by-util/test_unlink.rs @@ -14,17 +14,20 @@ fn test_unlink_file() { #[test] fn test_unlink_multiple_files() { - let (at, mut ucmd) = at_and_ucmd!(); + let ts = TestScenario::new(util_name!()); + + let (at, mut ucmd) = (ts.fixtures.clone(), ts.ucmd()); let file_a = "test_unlink_multiple_file_a"; let file_b = "test_unlink_multiple_file_b"; at.touch(file_a); at.touch(file_b); - ucmd.arg(file_a).arg(file_b).fails().stderr_is( - "unlink: extra operand: 'test_unlink_multiple_file_b'\nTry 'unlink --help' \ - for more information.\n", - ); + ucmd.arg(file_a).arg(file_b).fails().stderr_is(&format!( + "{0}: extra operand: 'test_unlink_multiple_file_b'\nTry `{1} {0} --help` for more information.", + ts.util_name, + ts.bin_path.to_string_lossy() + )); } #[test] diff --git a/tests/common/util.rs b/tests/common/util.rs index 41389d567..5441b82c2 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -713,7 +713,7 @@ impl AtPath { /// /// Fixtures can be found under `tests/fixtures/$util_name/` pub struct TestScenario { - bin_path: PathBuf, + pub bin_path: PathBuf, pub util_name: String, pub fixtures: AtPath, tmpd: Rc,