2019-07-26 16:54:25 -05:00
|
|
|
// run-pass
|
|
|
|
|
2018-09-17 04:18:35 -05:00
|
|
|
#![allow(unused_variables)]
|
2015-02-23 12:59:17 -06:00
|
|
|
// no-prefer-dynamic
|
2015-04-22 17:20:57 -05:00
|
|
|
// ignore-cross-compile
|
2015-02-23 12:59:17 -06:00
|
|
|
|
2015-02-13 14:08:05 -06:00
|
|
|
use std::env;
|
2022-03-25 15:46:36 -05:00
|
|
|
use std::ffi::OsStr;
|
2015-02-23 12:59:17 -06:00
|
|
|
use std::fs;
|
2022-03-25 15:46:36 -05:00
|
|
|
use std::path::PathBuf;
|
2015-02-23 12:59:17 -06:00
|
|
|
use std::process;
|
|
|
|
use std::str;
|
2014-06-24 14:10:31 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// If we're the child, make sure we were invoked correctly
|
2015-02-16 08:04:02 -06:00
|
|
|
let args: Vec<String> = env::args().collect();
|
2015-02-01 20:53:25 -06:00
|
|
|
if args.len() > 1 && args[1] == "child" {
|
2015-01-25 03:52:55 -06:00
|
|
|
// FIXME: This should check the whole `args[0]` instead of just
|
|
|
|
// checking that it ends_with the executable name. This
|
|
|
|
// is needed because of Windows, which has a different behavior.
|
|
|
|
// See #15149 for more info.
|
2022-03-25 15:46:36 -05:00
|
|
|
let my_path = env::current_exe().unwrap();
|
|
|
|
return assert_eq!(my_path.file_stem(), Some(OsStr::new("mytest")));
|
2014-06-24 14:10:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
test();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test() {
|
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();
|
2022-03-25 15:46:36 -05:00
|
|
|
let my_dir = my_path.parent().unwrap();
|
2015-01-15 14:49:23 -06:00
|
|
|
|
2018-01-22 09:29:24 -06:00
|
|
|
let child_dir = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap());
|
|
|
|
let child_dir = child_dir.join("issue-15140-child");
|
|
|
|
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
|
|
|
}
|