diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-08-03 14:50:51 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-08-03 15:09:00 -0700 |
| commit | 4ae6c835cb69332e982babcfca1a4e5657ec8bbd (patch) | |
| tree | 3c0a0618f8ff22673529bb412bdf72194d1407f0 /src/test/stdtest | |
| parent | e33de59e47c5076a89eadeb38f4934f58a3618a6 (diff) | |
| download | rust-4ae6c835cb69332e982babcfca1a4e5657ec8bbd.tar.gz rust-4ae6c835cb69332e982babcfca1a4e5657ec8bbd.zip | |
Add some hacks to get stdin piping working more correctly in windows
The way pipes work in windows is not the same as unix, though I'm not entirely clear on the differences. This patch changes the windows pipe method to return non-inheritable fds, and the windows rust_run_program method to duplicate them before spawning the new process. This allows make-check-pretty to work on windows.
Diffstat (limited to 'src/test/stdtest')
| -rw-r--r-- | src/test/stdtest/run.rs | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/test/stdtest/run.rs b/src/test/stdtest/run.rs index 8ba4c6a80ec..2adfbbe173e 100644 --- a/src/test/stdtest/run.rs +++ b/src/test/stdtest/run.rs @@ -1,5 +1,9 @@ use std; import std::run; +import std::os; +import std::io; +import std::option; +import std::str; // Regression test for memory leaks #[cfg(target_os = "linux")] @@ -15,4 +19,49 @@ fn test_leaks() { #[cfg(target_os = "win32")] #[test] #[ignore] -fn test_leaks() { } \ No newline at end of file +fn test_leaks() { } + +#[test] +fn test_pipes() { + let pipe_in = os::pipe(); + let pipe_out = os::pipe(); + let pipe_err = os::pipe(); + + let pid = run::spawn_process("cat", [], + pipe_in.in, pipe_out.out, pipe_err.out); + os::libc::close(pipe_in.in); + os::libc::close(pipe_out.out); + os::libc::close(pipe_err.out); + + if pid == -1 { fail; } + let expected = "test"; + writeclose(pipe_in.out, expected); + let actual = readclose(pipe_out.in); + readclose(pipe_err.in); + os::waitpid(pid); + + log expected; + log actual; + assert expected == actual; + + fn writeclose(fd: int, s: &str) { + let writer = io::new_writer( + io::fd_buf_writer(fd, option::none)); + writer.write_str(s); + + os::libc::close(fd); + } + + fn readclose(fd: int) -> str { + // Copied from run::program_output + let file = os::fd_FILE(fd); + let reader = io::new_reader(io::FILE_buf_reader(file, option::none)); + let buf = ""; + while !reader.eof() { + let bytes = reader.read_bytes(4096u); + buf += str::unsafe_from_bytes(bytes); + } + os::libc::fclose(file); + ret buf; + } +} \ No newline at end of file |
