rust/library/std/tests/process_spawning.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
1.1 KiB
Rust
Raw Normal View History

2024-01-11 20:04:48 +08:00
#![cfg(not(target_env = "sgx"))]
use std::{env, fs, process, str};
mod common;
#[test]
#[cfg_attr(miri, ignore)] // Process spawning not supported by Miri
fn issue_15149() {
// If we're the parent, copy our own binary to a new directory.
let my_path = env::current_exe().unwrap();
let temp = common::tmpdir();
let child_dir = temp.join("issue-15140-child");
fs::create_dir_all(&child_dir).unwrap();
2022-03-26 04:46:36 +08:00
let child_path = child_dir.join(&format!("mytest{}", env::consts::EXE_SUFFIX));
fs::copy(&my_path, &child_path).unwrap();
// Append the new directory to our own PATH.
let path = {
let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap()).collect();
paths.push(child_dir.to_path_buf());
env::join_paths(paths).unwrap()
};
2022-03-26 04:46:36 +08:00
let child_output =
process::Command::new("mytest").env("PATH", &path).arg("child").output().unwrap();
2022-03-26 04:46:36 +08:00
assert!(
child_output.status.success(),
"child assertion failed\n child stdout:\n {}\n child stderr:\n {}",
str::from_utf8(&child_output.stdout).unwrap(),
str::from_utf8(&child_output.stderr).unwrap()
);
}