Created
May 5, 2021 21:31
-
-
Save danhhz/264b7219b0bc64156ff1c829f3e1ba9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[cfg(test)] | |
mod tests { | |
use std::process::Command; | |
use std::time::Duration; | |
use std::{env, thread}; | |
#[test] | |
fn child_process_hack() { | |
let in_child = env::args().any(|x| x == "child_process_hack"); | |
if !in_child { | |
return; | |
} | |
eprintln!("hello from child: {:?}", env::args().collect::<Vec<_>>()); | |
thread::sleep(Duration::from_secs(u64::MAX)); | |
} | |
#[test] | |
fn it_works() { | |
let args = env::args().collect::<Vec<_>>(); | |
eprintln!("hello from parent: {:?}", args); | |
let mut child_args = args[1..] | |
.iter() | |
.filter(|x| x.starts_with("--")) | |
.collect::<Vec<_>>(); | |
let foo = "child_process_hack".to_string(); | |
child_args.push(&foo); | |
// TODO: Maybe hook up the child's stdout so all the lines are prefixed | |
// or something. | |
let mut child = Command::new(&args[0]) | |
.args(&child_args) | |
.spawn() | |
.expect("WIP"); | |
thread::sleep(Duration::from_secs(5)); | |
child.kill().expect("WIP"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment