1 #![cfg(feature = "process")] 2 #![warn(rust_2018_idioms)] 3 // This tests test the behavior of `process::Command::spawn` when it is used 4 // outside runtime, and when `process::Child::wait ` is used in a different 5 // runtime from which `process::Command::spawn` is used. 6 #![cfg(all(unix, not(target_os = "freebsd"), not(miri)))] 7 8 use std::process::Stdio; 9 use tokio::{process::Command, runtime::Runtime}; 10 11 #[test] process_spawned_and_wait_in_different_runtime()12fn process_spawned_and_wait_in_different_runtime() { 13 let mut child = Runtime::new().unwrap().block_on(async { 14 Command::new("true") 15 .stdin(Stdio::piped()) 16 .stdout(Stdio::null()) 17 .spawn() 18 .unwrap() 19 }); 20 Runtime::new().unwrap().block_on(async { 21 let _ = child.wait().await.unwrap(); 22 }); 23 } 24 25 #[test] 26 #[should_panic( 27 expected = "there is no reactor running, must be called from the context of a Tokio 1.x runtime" 28 )] process_spawned_outside_runtime()29fn process_spawned_outside_runtime() { 30 let _ = Command::new("true") 31 .stdin(Stdio::piped()) 32 .stdout(Stdio::null()) 33 .spawn(); 34 } 35