]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/sigpipe-should-be-ignored.rs
Rollup merge of #61499 - varkor:issue-53457, r=oli-obk
[rust.git] / src / test / run-pass / sigpipe-should-be-ignored.rs
1 #![allow(unused_must_use)]
2 // Be sure that when a SIGPIPE would have been received that the entire process
3 // doesn't die in a ball of fire, but rather it's gracefully handled.
4
5 // ignore-cloudabi no processes
6 // ignore-emscripten no processes
7 // ignore-sgx no processes
8
9 use std::env;
10 use std::io::prelude::*;
11 use std::io;
12 use std::process::{Command, Stdio};
13
14 fn test() {
15     let _ = io::stdin().read_line(&mut String::new());
16     io::stdout().write(&[1]);
17     assert!(io::stdout().flush().is_err());
18 }
19
20 fn main() {
21     let args: Vec<String> = env::args().collect();
22     if args.len() > 1 && args[1] == "test" {
23         return test();
24     }
25
26     let mut p = Command::new(&args[0])
27                         .stdout(Stdio::piped())
28                         .stdin(Stdio::piped())
29                         .arg("test").spawn().unwrap();
30     drop(p.stdout.take());
31     assert!(p.wait().unwrap().success());
32 }