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