2015-02-13 14:08:05 -06:00
|
|
|
use std::env;
|
2015-02-23 12:59:17 -06:00
|
|
|
use std::fs;
|
|
|
|
use std::process;
|
|
|
|
use std::str;
|
2014-06-24 14:10:31 -05:00
|
|
|
|
2023-06-07 11:40:25 -05:00
|
|
|
mod common;
|
2014-06-24 14:10:31 -05:00
|
|
|
|
2023-06-07 11:40:25 -05:00
|
|
|
#[test]
|
|
|
|
fn issue_15149() {
|
2015-01-15 14:49:23 -06:00
|
|
|
// If we're the parent, copy our own binary to a new directory.
|
2015-02-16 08:04:02 -06:00
|
|
|
let my_path = env::current_exe().unwrap();
|
2015-01-15 14:49:23 -06:00
|
|
|
|
2023-06-07 11:40:25 -05:00
|
|
|
let temp = common::tmpdir();
|
|
|
|
let child_dir = temp.join("issue-15140-child");
|
2018-01-22 09:29:24 -06:00
|
|
|
fs::create_dir_all(&child_dir).unwrap();
|
2015-01-15 14:49:23 -06:00
|
|
|
|
2022-03-25 15:46:36 -05:00
|
|
|
let child_path = child_dir.join(&format!("mytest{}", env::consts::EXE_SUFFIX));
|
2015-01-15 14:49:23 -06:00
|
|
|
fs::copy(&my_path, &child_path).unwrap();
|
|
|
|
|
|
|
|
// Append the new directory to our own PATH.
|
2015-02-16 08:04:02 -06:00
|
|
|
let path = {
|
|
|
|
let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap()).collect();
|
2015-02-23 12:59:17 -06:00
|
|
|
paths.push(child_dir.to_path_buf());
|
2015-06-10 11:22:20 -05:00
|
|
|
env::join_paths(paths).unwrap()
|
2015-02-16 08:04:02 -06:00
|
|
|
};
|
2014-06-24 14:10:31 -05:00
|
|
|
|
2022-03-25 15:46:36 -05:00
|
|
|
let child_output =
|
|
|
|
process::Command::new("mytest").env("PATH", &path).arg("child").output().unwrap();
|
2015-01-22 12:54:45 -06:00
|
|
|
|
2022-03-25 15:46:36 -05: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()
|
|
|
|
);
|
2014-06-24 14:10:31 -05:00
|
|
|
}
|