mirror of
https://github.com/sharkdp/fd
synced 2024-09-04 15:53:20 +00:00
Update testenv to support errors that don't fail
This commit is contained in:
parent
4f4591bfdc
commit
bbf3d0d430
|
@ -240,14 +240,23 @@ impl TestEnv {
|
|||
}
|
||||
}
|
||||
|
||||
/// Assert that calling *fd* with the specified arguments produces the expected error,
|
||||
/// and does not succeed.
|
||||
pub fn assert_failure_with_error(&self, args: &[&str], expected: &str) {
|
||||
let status = self.assert_error_subdirectory(".", args, expected);
|
||||
if status.success() {
|
||||
panic!("error '{}' did not occur.", expected);
|
||||
}
|
||||
}
|
||||
|
||||
/// Assert that calling *fd* with the specified arguments produces the expected error.
|
||||
pub fn assert_error(&self, args: &[&str], expected: &str) {
|
||||
pub fn assert_error(&self, args: &[&str], expected: &str) -> process::ExitStatus {
|
||||
self.assert_error_subdirectory(".", args, expected)
|
||||
}
|
||||
|
||||
/// Assert that calling *fd* in the specified path under the root working directory,
|
||||
/// and with the specified arguments produces an error with the expected message.
|
||||
fn assert_error_subdirectory<P: AsRef<Path>>(&self, path: P, args: &[&str], expected: &str) {
|
||||
fn assert_error_subdirectory<P: AsRef<Path>>(&self, path: P, args: &[&str], expected: &str) -> process::ExitStatus {
|
||||
// Setup *fd* command.
|
||||
let mut cmd = process::Command::new(&self.fd_exe);
|
||||
cmd.current_dir(self.temp_dir.path().join(path));
|
||||
|
@ -256,15 +265,22 @@ impl TestEnv {
|
|||
// Run *fd*.
|
||||
let output = cmd.output().expect("fd output");
|
||||
|
||||
// Check for exit status.
|
||||
if output.status.success() {
|
||||
panic!("error '{}' did not occur.", expected);
|
||||
}
|
||||
|
||||
|
||||
// Compare actual output to expected output.
|
||||
let actual = String::from_utf8_lossy(&output.stderr);
|
||||
if !actual.starts_with(expected) {
|
||||
panic!(format_output_error(args, &expected, &actual));
|
||||
// Normalize both expected and actual output.
|
||||
let expected_error = normalize_output(expected, true, self.normalize_line);
|
||||
let actual_err = normalize_output(
|
||||
&String::from_utf8_lossy(&output.stderr),
|
||||
false,
|
||||
self.normalize_line,
|
||||
);
|
||||
|
||||
// Compare actual output to expected output.
|
||||
if !actual_err.trim_start().starts_with(&expected_error) {
|
||||
panic!(format_output_error(args, &expected_error, &actual_err));
|
||||
}
|
||||
|
||||
return output.status;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1238,22 +1238,22 @@ fn test_exec_batch() {
|
|||
"",
|
||||
);
|
||||
|
||||
te.assert_error(
|
||||
te.assert_failure_with_error(
|
||||
&["foo", "--exec-batch", "echo", "{}", "{}"],
|
||||
"[fd error]: Only one placeholder allowed for batch commands",
|
||||
);
|
||||
|
||||
te.assert_error(
|
||||
te.assert_failure_with_error(
|
||||
&["foo", "--exec-batch", "echo", "{/}", ";", "-x", "echo"],
|
||||
"error: The argument '--exec <cmd>' cannot be used with '--exec-batch <cmd>'",
|
||||
);
|
||||
|
||||
te.assert_error(
|
||||
te.assert_failure_with_error(
|
||||
&["foo", "--exec-batch"],
|
||||
"error: The argument '--exec-batch <cmd>' requires a value but none was supplied",
|
||||
);
|
||||
|
||||
te.assert_error(
|
||||
te.assert_failure_with_error(
|
||||
&["foo", "--exec-batch", "echo {}"],
|
||||
"[fd error]: First argument of exec-batch is expected to be a fixed executable",
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue