diff --git a/src/exec/command.rs b/src/exec/command.rs index 28b899851..3dc6403df 100644 --- a/src/exec/command.rs +++ b/src/exec/command.rs @@ -45,7 +45,7 @@ pub fn execute_command(mut cmd: Command, out_perm: Arc>) { /// Executes a command. #[cfg(all(unix))] pub fn execute_command(mut cmd: Command, out_perm: Arc>) { - use libc::{close, dup2, pipe, STDERR_FILENO, STDOUT_FILENO}; + use libc::{close, dup2, pipe, STDOUT_FILENO}; use std::fs::File; use std::os::unix::process::CommandExt; use std::os::unix::io::FromRawFd; @@ -64,7 +64,6 @@ pub fn execute_command(mut cmd: Command, out_perm: Arc>) { let child = cmd.before_exec(move || unsafe { // Redirect the child's std{out,err} to the write ends of our pipe. dup2(stdout_fds[1], STDOUT_FILENO); - dup2(stderr_fds[1], STDERR_FILENO); // Close all the fds we created here, so EOF will be sent when the program exits. close(stdout_fds[0]); diff --git a/tests/testenv/mod.rs b/tests/testenv/mod.rs index ceed8fee4..60788e8c6 100644 --- a/tests/testenv/mod.rs +++ b/tests/testenv/mod.rs @@ -161,7 +161,12 @@ impl TestEnv { /// Assert that calling *fd* with the specified arguments produces the expected output. pub fn assert_output(&self, args: &[&str], expected: &str) { - self.assert_output_subdirectory(".", args, expected) + self.assert_output_subdirectory(".", args, expected, "") + } + + /// Assert that calling *fd* with the specified arguments produces the expected stderr. + pub fn assert_output_error(&self, args: &[&str], expected: &str) { + self.assert_output_subdirectory(".", args, "", expected) } /// Assert that calling *fd* in the specified path under the root working directory, @@ -170,7 +175,8 @@ impl TestEnv { &self, path: P, args: &[&str], - expected: &str, + expected_stdout: &str, + expected_stderr: &str, ) { // Setup *fd* command. let mut cmd = process::Command::new(&self.fd_exe); @@ -186,12 +192,17 @@ impl TestEnv { } // Normalize both expected and actual output. - let expected = normalize_output(expected, true); - let actual = normalize_output(&String::from_utf8_lossy(&output.stdout), false); + let expected_stdout = normalize_output(expected_stdout, true); + let actual_stdout = normalize_output(&String::from_utf8_lossy(&output.stdout), false); + let expected_stderr = normalize_output(expected_stderr, true); + let actual_stderr = normalize_output(&String::from_utf8_lossy(&output.stderr), false); // Compare actual output to expected output. - if expected != actual { - panic!(format_output_error(args, &expected, &actual)); + if expected_stdout != actual_stdout { + panic!(format_output_error(args, &expected_stdout, &actual_stdout)); + } + if expected_stderr != actual_stderr { + panic!(format_output_error(args, &expected_stderr, &actual_stderr)); } } } diff --git a/tests/tests.rs b/tests/tests.rs index 975a91b2d..497242ea5 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -93,6 +93,7 @@ fn test_explicit_root_path() { ../../one/two/C.Foo2 ../../one/two/three/d.foo ../../one/two/three/directory_foo", + "" ); te.assert_output_subdirectory( @@ -103,6 +104,7 @@ fn test_explicit_root_path() { ../three ../three/d.foo ../three/directory_foo", + "" ); } @@ -505,6 +507,7 @@ fn test_symlink() { {dir}/symlink", dir = &parent_parent ), + "" ); te.assert_output_subdirectory( @@ -519,6 +522,7 @@ fn test_symlink() { dir = if cfg!(windows) { "symlink" } else { "one/two" }, abs_path = &abs_path ), + "" ); te.assert_output( @@ -550,6 +554,7 @@ fn test_symlink() { dir = if cfg!(windows) { "symlink" } else { "one/two" }, abs_path = &abs_path ), + "" ); te.assert_output( @@ -639,6 +644,11 @@ fn test_exec() { ), ); + te.assert_output_error( + &["a.foo", "--exec", "rm", "-i", "{}"], + "rm: remove regular empty file 'a.foo'? ", + ); + te.assert_output( &["foo", "--exec", "echo", "{}"], "a.foo