File: process_spawning.rs

package info (click to toggle)
rustc 1.86.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid
  • size: 913,560 kB
  • sloc: xml: 158,127; python: 35,921; javascript: 19,689; sh: 19,600; cpp: 18,906; ansic: 13,124; asm: 4,376; makefile: 708; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (37 lines) | stat: -rw-r--r-- 1,238 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#![cfg(not(target_env = "sgx"))]

use std::{env, fs, process, str};

mod common;

#[test]
// Process spawning not supported by Miri, Emscripten and wasi
#[cfg_attr(any(miri, target_os = "emscripten", target_os = "wasi"), ignore)]
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();

    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()
    };

    let child_output =
        process::Command::new("mytest").env("PATH", &path).arg("child").output().unwrap();

    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()
    );
}