2019-07-26 21:54:25 +00:00
|
|
|
// run-pass
|
|
|
|
|
2018-09-17 09:18:35 +00:00
|
|
|
#![allow(unused_variables)]
|
2015-02-23 18:59:17 +00:00
|
|
|
// no-prefer-dynamic
|
2015-04-22 22:20:57 +00:00
|
|
|
// ignore-cross-compile
|
2015-02-23 18:59:17 +00:00
|
|
|
|
2015-02-13 20:08:05 +00:00
|
|
|
use std::env;
|
2022-03-25 20:46:36 +00:00
|
|
|
use std::ffi::OsStr;
|
2015-02-23 18:59:17 +00:00
|
|
|
use std::fs;
|
2022-03-25 20:46:36 +00:00
|
|
|
use std::path::PathBuf;
|
2015-02-23 18:59:17 +00:00
|
|
|
use std::process;
|
|
|
|
use std::str;
|
2014-06-24 19:10:31 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// If we're the child, make sure we were invoked correctly
|
2015-02-16 14:04:02 +00:00
|
|
|
let args: Vec<String> = env::args().collect();
|
2015-02-02 02:53:25 +00:00
|
|
|
if args.len() > 1 && args[1] == "child" {
|
2015-01-25 09:52:55 +00: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 20:46:36 +00:00
|
|
|
let my_path = env::current_exe().unwrap();
|
|
|
|
return assert_eq!(my_path.file_stem(), Some(OsStr::new("mytest")));
|
2014-06-24 19:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test() {
|
2015-01-15 20:49:23 +00:00
|
|
|
// If we're the parent, copy our own binary to a new directory.
|
2015-02-16 14:04:02 +00:00
|
|
|
let my_path = env::current_exe().unwrap();
|
2022-03-25 20:46:36 +00:00
|
|
|
let my_dir = my_path.parent().unwrap();
|
2015-01-15 20:49:23 +00:00
|
|
|
|
2018-01-22 15:29:24 +00: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 20:49:23 +00:00
|
|
|
|
2022-03-25 20:46:36 +00:00
|
|
|
let child_path = child_dir.join(&format!("mytest{}", env::consts::EXE_SUFFIX));
|
2015-01-15 20:49:23 +00:00
|
|
|
fs::copy(&my_path, &child_path).unwrap();
|
|
|
|
|
|
|
|
// Append the new directory to our own PATH.
|
2015-02-16 14:04:02 +00:00
|
|
|
let path = {
|
|
|
|
let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap()).collect();
|
2015-02-23 18:59:17 +00:00
|
|
|
paths.push(child_dir.to_path_buf());
|
2015-06-10 16:22:20 +00:00
|
|
|
env::join_paths(paths).unwrap()
|
2015-02-16 14:04:02 +00:00
|
|
|
};
|
2014-06-24 19:10:31 +00:00
|
|
|
|
2022-03-25 20:46:36 +00:00
|
|
|
let child_output =
|
|
|
|
process::Command::new("mytest").env("PATH", &path).arg("child").output().unwrap();
|
2015-01-22 18:54:45 +00:00
|
|
|
|
2022-03-25 20:46:36 +00: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 19:10:31 +00:00
|
|
|
}
|