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.
|
/// 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)
|
self.assert_error_subdirectory(".", args, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Assert that calling *fd* in the specified path under the root working directory,
|
/// 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.
|
/// 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.
|
// Setup *fd* command.
|
||||||
let mut cmd = process::Command::new(&self.fd_exe);
|
let mut cmd = process::Command::new(&self.fd_exe);
|
||||||
cmd.current_dir(self.temp_dir.path().join(path));
|
cmd.current_dir(self.temp_dir.path().join(path));
|
||||||
|
@ -256,15 +265,22 @@ impl TestEnv {
|
||||||
// Run *fd*.
|
// Run *fd*.
|
||||||
let output = cmd.output().expect("fd output");
|
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.
|
// Compare actual output to expected output.
|
||||||
let actual = String::from_utf8_lossy(&output.stderr);
|
// Normalize both expected and actual output.
|
||||||
if !actual.starts_with(expected) {
|
let expected_error = normalize_output(expected, true, self.normalize_line);
|
||||||
panic!(format_output_error(args, &expected, &actual));
|
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", "{}", "{}"],
|
&["foo", "--exec-batch", "echo", "{}", "{}"],
|
||||||
"[fd error]: Only one placeholder allowed for batch commands",
|
"[fd error]: Only one placeholder allowed for batch commands",
|
||||||
);
|
);
|
||||||
|
|
||||||
te.assert_error(
|
te.assert_failure_with_error(
|
||||||
&["foo", "--exec-batch", "echo", "{/}", ";", "-x", "echo"],
|
&["foo", "--exec-batch", "echo", "{/}", ";", "-x", "echo"],
|
||||||
"error: The argument '--exec <cmd>' cannot be used with '--exec-batch <cmd>'",
|
"error: The argument '--exec <cmd>' cannot be used with '--exec-batch <cmd>'",
|
||||||
);
|
);
|
||||||
|
|
||||||
te.assert_error(
|
te.assert_failure_with_error(
|
||||||
&["foo", "--exec-batch"],
|
&["foo", "--exec-batch"],
|
||||||
"error: The argument '--exec-batch <cmd>' requires a value but none was supplied",
|
"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 {}"],
|
&["foo", "--exec-batch", "echo {}"],
|
||||||
"[fd error]: First argument of exec-batch is expected to be a fixed executable",
|
"[fd error]: First argument of exec-batch is expected to be a fixed executable",
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue