]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/try-wait.rs
Unignore u128 test for stage 0,1
[rust.git] / src / test / run-pass / try-wait.rs
1 // Copyright 2017 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-emscripten
12
13 #![feature(process_try_wait)]
14
15 use std::env;
16 use std::io;
17 use std::process::Command;
18 use std::thread;
19 use std::time::Duration;
20
21 fn main() {
22     let args = env::args().collect::<Vec<_>>();
23     if args.len() != 1 {
24         match &args[1][..] {
25             "sleep" => thread::sleep(Duration::new(1_000, 0)),
26             _ => {}
27         }
28         return
29     }
30
31     let mut me = Command::new(env::current_exe().unwrap())
32                          .arg("sleep")
33                          .spawn()
34                          .unwrap();
35     let err = me.try_wait().unwrap_err();
36     assert_eq!(err.kind(), io::ErrorKind::WouldBlock);
37     let err = me.try_wait().unwrap_err();
38     assert_eq!(err.kind(), io::ErrorKind::WouldBlock);
39
40     me.kill().unwrap();
41     me.wait().unwrap();
42
43     let status = me.try_wait().unwrap();
44     assert!(!status.success());
45     let status = me.try_wait().unwrap();
46     assert!(!status.success());
47
48     let mut me = Command::new(env::current_exe().unwrap())
49                          .arg("return-quickly")
50                          .spawn()
51                          .unwrap();
52     loop {
53         match me.try_wait() {
54             Ok(res) => {
55                 assert!(res.success());
56                 break
57             }
58             Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
59                 thread::sleep(Duration::from_millis(1));
60             }
61             Err(e) => panic!("error in try_wait: {}", e),
62         }
63     }
64
65     let status = me.try_wait().unwrap();
66     assert!(status.success());
67 }