1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(rustc_private)]
16 use std::io::{Read, Write};
21 fn switch_stdout_to(file: File) {
22 use std::os::unix::prelude::*;
25 fn dup2(old: i32, new: i32) -> i32;
29 assert_eq!(dup2(file.as_raw_fd(), 1), 1);
34 fn switch_stdout_to(file: File) {
35 use std::os::windows::prelude::*;
38 fn SetStdHandle(nStdHandle: u32, handle: *mut u8) -> i32;
41 const STD_OUTPUT_HANDLE: u32 = (-11i32) as u32;
44 let rc = SetStdHandle(STD_OUTPUT_HANDLE,
45 file.into_raw_handle() as *mut _);
51 let td = TempDir::new("foo").unwrap();
52 let path = td.path().join("bar");
53 let f = File::create(&path).unwrap();
56 std::io::stdout().flush().unwrap();
59 std::io::stdout().flush().unwrap();
61 let mut contents = String::new();
62 File::open(&path).unwrap().read_to_string(&mut contents).unwrap();
63 assert_eq!(contents, "bar\n");