|
| 1 | +// Copyright 2015 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 | +use std::env; |
| 12 | +use std::io; |
| 13 | +use std::io::{Read, Write}; |
| 14 | +use std::process::{Command, Stdio}; |
| 15 | + |
| 16 | +fn main(){ |
| 17 | + if env::args().count() > 1 && env::args().nth(1) == Some("child".to_string()) { |
| 18 | + child() |
| 19 | + } else { |
| 20 | + let mut p = Command::new(env::args().nth(0).unwrap()) |
| 21 | + .arg("child") |
| 22 | + .stdin(Stdio::piped()) |
| 23 | + .stdout(Stdio::piped()) |
| 24 | + .stderr(Stdio::inherit()) |
| 25 | + .spawn().unwrap(); |
| 26 | + { |
| 27 | + let mut buf = [0; 1]; |
| 28 | + assert!(p.stdout.as_mut().unwrap().read(&mut buf).unwrap() >= 1); |
| 29 | + assert_eq!(buf[0], b'>'); |
| 30 | + assert!(p.stdin.as_mut().unwrap().write(b"abcd\n").unwrap() >= 1); |
| 31 | + } |
| 32 | + // FIXME(#25572): timeout and fail on timeout |
| 33 | + assert!(p.wait().unwrap().success()); |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +fn child(){ |
| 38 | + let stdout = io::stdout(); |
| 39 | + let lstdout = stdout.lock(); |
| 40 | + let mut stdin = io::stdin(); |
| 41 | + print!(">"); |
| 42 | + let mut letter = [0; 1]; |
| 43 | + stdin.read(&mut letter).unwrap(); |
| 44 | +} |
0 commit comments