5 use std::io::{Read, Write};
6 use std::path::PathBuf;
9 fn switch_stdout_to(file: File) {
10 use std::os::unix::prelude::*;
13 fn dup2(old: i32, new: i32) -> i32;
17 assert_eq!(dup2(file.as_raw_fd(), 1), 1);
22 fn switch_stdout_to(file: File) {
23 use std::os::windows::prelude::*;
26 fn SetStdHandle(nStdHandle: u32, handle: *mut u8) -> i32;
29 const STD_OUTPUT_HANDLE: u32 = (-11i32) as u32;
32 let rc = SetStdHandle(STD_OUTPUT_HANDLE, file.into_raw_handle() as *mut _);
38 let path = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap());
39 let path = path.join("switch-stdout-output");
40 let f = File::create(&path).unwrap();
43 std::io::stdout().flush().unwrap();
46 std::io::stdout().flush().unwrap();
48 let mut contents = String::new();
49 File::open(&path).unwrap().read_to_string(&mut contents).unwrap();
50 assert_eq!(contents, "bar\n");