1#![warn(rust_2018_idioms)]
2#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi cannot run system commands
3
4use tokio::process::Command;
5use tokio_test::assert_ok;
6
7#[tokio::test]
8async fn simple() {
9 let mut cmd;
10
11 if cfg!(windows) {
12 cmd = Command::new("cmd");
13 cmd.arg("/c");
14 } else {
15 cmd = Command::new("sh");
16 cmd.arg("-c");
17 }
18
19 let mut child = cmd.arg("exit 2").spawn().unwrap();
20
21 let id = child.id().expect("missing id");
22 assert!(id > 0);
23
24 let status = assert_ok!(child.wait().await);
25 assert_eq!(status.code(), Some(2));
26
27 // test that the `.wait()` method is fused just like the stdlib
28 let status = assert_ok!(child.wait().await);
29 assert_eq!(status.code(), Some(2));
30
31 // Can't get id after process has exited
32 assert_eq!(child.id(), None);
33 drop(child.kill());
34}
35