Skip to content
Myr

Update testenv to support errors that don't fail

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by DJRHails · committed by David Peter · parent 4f4591b · Browse files · 2 files+29 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+29 added−13 removed

  • tests:+29 added−13 removed

2 files+29 added−13 removed

modified:tests/testenv/mod.rs+25 added-9 removed
238 unmodified lines
239 panic!(format_output_error(args, &expected, &actual));240 }241 }242243 /// Assert that calling *fd* with the specified arguments produces the expected error,244 /// and does not succeed.245 pub fn assert_failure_with_error(&self, args: &[&str], expected: &str) {246 let status = self.assert_error_subdirectory(".", args, expected);247 if status.success() {248 panic!("error '{}' did not occur.", expected);249 }250 }251252 /// Assert that calling *fd* with the specified arguments produces the expected error.244 pub fn assert_error(&self, args: &[&str], expected: &str) {253 pub fn assert_error(&self, args: &[&str], expected: &str) -> process::ExitStatus {254 self.assert_error_subdirectory(".", args, expected)255 }256257 /// Assert that calling *fd* in the specified path under the root working directory,258 /// and with the specified arguments produces an error with the expected message.250 fn assert_error_subdirectory<P: AsRef<Path>>(&self, path: P, args: &[&str], expected: &str) {259 fn assert_error_subdirectory<P: AsRef<Path>>(&self, path: P, args: &[&str], expected: &str) -> process::ExitStatus {260 // Setup *fd* command.261 let mut cmd = process::Command::new(&self.fd_exe);262 cmd.current_dir(self.temp_dir.path().join(path));263 cmd.arg("--no-global-ignore-file").args(args);264265 // Run *fd*.266 let output = cmd.output().expect("fd output");267259 // Check for exit status.260 if output.status.success() {261 panic!("error '{}' did not occur.", expected);262 }268269270 // Compare actual output to expected output.265 let actual = String::from_utf8_lossy(&output.stderr);266 if !actual.starts_with(expected) {267 panic!(format_output_error(args, &expected, &actual));271 // Normalize both expected and actual output.272 let expected_error = normalize_output(expected, true, self.normalize_line);273 let actual_err = normalize_output(274 &String::from_utf8_lossy(&output.stderr),275 false,276 self.normalize_line,277 );278279 // Compare actual output to expected output.280 if !actual_err.trim_start().starts_with(&expected_error) {281 panic!(format_output_error(args, &expected_error, &actual_err));282 }283284 return output.status;285 }286}
modified:tests/tests.rs+4 added-4 removed
1236 unmodified lines
1237 &["no_match", "--exec-batch", "echo", "Matched: ", "{/}"],1238 "",1239 );12401241 te.assert_error(1241 te.assert_failure_with_error(1242 &["foo", "--exec-batch", "echo", "{}", "{}"],1243 "[fd error]: Only one placeholder allowed for batch commands",1244 );12451246 te.assert_error(1246 te.assert_failure_with_error(1247 &["foo", "--exec-batch", "echo", "{/}", ";", "-x", "echo"],1248 "error: The argument '--exec <cmd>' cannot be used with '--exec-batch <cmd>'",1249 );12501251 te.assert_error(1251 te.assert_failure_with_error(1252 &["foo", "--exec-batch"],1253 "error: The argument '--exec-batch <cmd>' requires a value but none was supplied",1254 );12551256 te.assert_error(1256 te.assert_failure_with_error(1257 &["foo", "--exec-batch", "echo {}"],1258 "[fd error]: First argument of exec-batch is expected to be a fixed executable",1259 );1260 }
338 unmodified lines