]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-13304.rs
Auto merge of #45359 - arielb1:escaping-borrow, r=eddyb
[rust.git] / src / test / run-pass / issue-13304.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-emscripten no processes
12
13 #![feature(io, process_capture)]
14
15 use std::env;
16 use std::io::prelude::*;
17 use std::io;
18 use std::process::{Command, Stdio};
19 use std::str;
20
21 fn main() {
22     let args: Vec<String> = env::args().collect();
23     if args.len() > 1 && args[1] == "child" {
24         child();
25     } else {
26         parent();
27     }
28 }
29
30 fn parent() {
31     let args: Vec<String> = env::args().collect();
32     let mut p = Command::new(&args[0]).arg("child")
33                         .stdout(Stdio::piped())
34                         .stdin(Stdio::piped())
35                         .spawn().unwrap();
36     p.stdin.as_mut().unwrap().write_all(b"test1\ntest2\ntest3").unwrap();
37     let out = p.wait_with_output().unwrap();
38     assert!(out.status.success());
39     let s = str::from_utf8(&out.stdout).unwrap();
40     assert_eq!(s, "test1\ntest2\ntest3\n");
41 }
42
43 fn child() {
44     let mut stdin = io::stdin();
45     for line in stdin.lock().lines() {
46         println!("{}", line.unwrap());
47     }
48 }