]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-13304.rs
complete openbsd support for `std::env`
[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-fast
12
13 use std::os;
14 use std::old_io;
15 use std::str;
16
17 fn main() {
18     let args = os::args();
19     let args = args.as_slice();
20     if args.len() > 1 && args[1].as_slice() == "child" {
21         child();
22     } else {
23         parent();
24     }
25 }
26
27 fn parent() {
28     let args = os::args();
29     let args = args.as_slice();
30     let mut p = old_io::process::Command::new(args[0].as_slice())
31                                      .arg("child").spawn().unwrap();
32     p.stdin.as_mut().unwrap().write_str("test1\ntest2\ntest3").unwrap();
33     let out = p.wait_with_output().unwrap();
34     assert!(out.status.success());
35     let s = str::from_utf8(out.output.as_slice()).unwrap();
36     assert_eq!(s, "test1\n\ntest2\n\ntest3\n");
37 }
38
39 fn child() {
40     for line in old_io::stdin().lock().lines() {
41         println!("{}", line.unwrap());
42     }
43 }