]> git.lizzy.rs Git - rust.git/blob - tests/ui/process/try-wait.rs
Rollup merge of #104965 - zacklukem:p-option-as_ref-docs, r=scottmcm
[rust.git] / tests / ui / process / try-wait.rs
1 // run-pass
2
3 #![allow(stable_features)]
4 // ignore-emscripten no processes
5 // ignore-sgx no processes
6
7 #![feature(process_try_wait)]
8
9 use std::env;
10 use std::process::Command;
11 use std::thread;
12 use std::time::Duration;
13
14 fn main() {
15     let args = env::args().collect::<Vec<_>>();
16     if args.len() != 1 {
17         match &args[1][..] {
18             "sleep" => thread::sleep(Duration::new(1_000, 0)),
19             _ => {}
20         }
21         return
22     }
23
24     let mut me = Command::new(env::current_exe().unwrap())
25                          .arg("sleep")
26                          .spawn()
27                          .unwrap();
28     let maybe_status = me.try_wait().unwrap();
29     assert!(maybe_status.is_none());
30     let maybe_status = me.try_wait().unwrap();
31     assert!(maybe_status.is_none());
32
33     me.kill().unwrap();
34     me.wait().unwrap();
35
36     let status = me.try_wait().unwrap().unwrap();
37     assert!(!status.success());
38     let status = me.try_wait().unwrap().unwrap();
39     assert!(!status.success());
40
41     let mut me = Command::new(env::current_exe().unwrap())
42                          .arg("return-quickly")
43                          .spawn()
44                          .unwrap();
45     loop {
46         match me.try_wait() {
47             Ok(Some(res)) => {
48                 assert!(res.success());
49                 break
50             }
51             Ok(None) => {
52                 thread::sleep(Duration::from_millis(1));
53             }
54             Err(e) => panic!("error in try_wait: {}", e),
55         }
56     }
57
58     let status = me.try_wait().unwrap().unwrap();
59     assert!(status.success());
60 }