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