]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-14456.rs
bfedc52919c0942f29a1e5ce9c8436b31d283224
[rust.git] / src / test / run-pass / issue-14456.rs
1 // Copyright 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.
4 //
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.
10
11 // ignore-cloudabi no processes
12 // ignore-emscripten no processes
13
14 #![feature(io)]
15
16 use std::env;
17 use std::io::prelude::*;
18 use std::io;
19 use std::process::{Command, Stdio};
20
21 fn main() {
22     let args: Vec<String> = env::args().collect();
23     if args.len() > 1 && args[1] == "child" {
24         return child()
25     }
26
27     test();
28 }
29
30 fn child() {
31     writeln!(&mut io::stdout(), "foo").unwrap();
32     writeln!(&mut io::stderr(), "bar").unwrap();
33     let mut stdin = io::stdin();
34     let mut s = String::new();
35     stdin.lock().read_line(&mut s).unwrap();
36     assert_eq!(s.len(), 0);
37 }
38
39 fn test() {
40     let args: Vec<String> = env::args().collect();
41     let mut p = Command::new(&args[0]).arg("child")
42                                      .stdin(Stdio::piped())
43                                      .stdout(Stdio::piped())
44                                      .stderr(Stdio::piped())
45                                      .spawn().unwrap();
46     assert!(p.wait().unwrap().success());
47 }