Add tests originally written by @alexmaco in #309
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by David Peter · parent 7e3c69c · Browse files · 2 files·+69 added−0 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+69 added−0 removed
- tests:+69 added−0 removed
Provenance
- Commit
ea21df3- Tree
b860f7f- Author
sharkdp <davidpeter@web.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
7e3c69c
2 files changed+69 added−0 removed
modified:tests/testenv/mod.rs+23 added
206 unmodified lines207 pub fn assert_output(&self, args: &[&str], expected: &str) {208 self.assert_output_subdirectory(".", args, expected)209 }210 211+ /// Similar to assert_output, but able to handle non-utf8 output212+ pub fn assert_output_raw(&self, args: &[&str], expected: &[u8]) {213+ let actual = self.raw_output_subdirectory(".", args);214+ assert_eq!(expected, actual.as_ref());215+ }216+217 /// Assert that calling *fd* in the specified path under the root working directory,218 /// and with the specified arguments produces the expected output.219 pub fn assert_output_subdirectory<P: AsRef<Path>>(220 &self,16 unmodified lines237 panic!(format_output_error(args, &expected, &actual));238 }239 }240 241+ fn raw_output_subdirectory<P: AsRef<Path>>(&self, path: P, args: &[&str]) -> Box<[u8]> {242+ // Setup *fd* command.243+ let mut cmd = process::Command::new(&self.fd_exe);244+ cmd.current_dir(self.temp_dir.path().join(path));245+ cmd.args(args);246+247+ // Run *fd*.248+ let output = cmd.output().expect("fd output");249+250+ // Check for exit status.251+ if !output.status.success() {252+ panic!(format_exit_error(args, &output));253+ }254+255+ output.stdout.into_boxed_slice()256+ }257+258 /// Assert that calling *fd* with the specified arguments produces the expected error.259 pub fn assert_error(&self, args: &[&str], expected: &str) {260 self.assert_error_subdirectory(".", args, expected)261 }24 unmodified linesmodified:tests/tests.rs+46 added
1462 unmodified lines1463 let stdout = stdout.trim();1464 let stdout = stdout.replace(&std::path::MAIN_SEPARATOR.to_string(), "/");1465 assert!(stdout == "one/two/C.Foo2" || stdout == "one/two/c.foo");1466 }1467+1468+/// Filenames with non-utf8 paths are passed to the executed program unchanged1469+///1470+/// Note:1471+/// - the test is disabled on Darwin/OSX, since it coerces file names to UTF-8,1472+/// even when the requested file name is not valid UTF-8.1473+/// - the test is currently disabled on Windows because I'm not sure how to create1474+/// invalid UTF-8 files on Windows1475+#[cfg(all(unix, not(target_os = "macos")))]1476+#[test]1477+fn test_exec_invalid_utf8() {1478+ use std::ffi::OsStr;1479+ use std::os::unix::ffi::OsStrExt;1480+1481+ let dirs = &["test1"];1482+ let files = &[];1483+ let te = TestEnv::new(dirs, files);1484+1485+ fs::File::create(1486+ te.test_root()1487+ .join(OsStr::from_bytes(b"test1/test_\xFEinvalid.txt")),1488+ )1489+ .unwrap();1490+1491+ te.assert_output_raw(1492+ &["", "test1/", "--exec", "echo", "{}"],1493+ b"test1/test_\xFEinvalid.txt\n",1494+ );1495+1496+ te.assert_output_raw(1497+ &["", "test1/", "--exec", "echo", "{/}"],1498+ b"test_\xFEinvalid.txt\n",1499+ );1500+1501+ te.assert_output_raw(&["", "test1/", "--exec", "echo", "{//}"], b"test1\n");1502+1503+ te.assert_output_raw(1504+ &["", "test1/", "--exec", "echo", "{.}"],1505+ b"test1/test_\xFEinvalid\n",1506+ );1507+1508+ te.assert_output_raw(1509+ &["", "test1/", "--exec", "echo", "{/.}"],1510+ b"test_\xFEinvalid\n",1511+ );1512+}