3 #![allow(unused_variables)]
5 // ignore-cross-compile
10 use std::path::PathBuf;
15 // If we're the child, make sure we were invoked correctly
16 let args: Vec<String> = env::args().collect();
17 if args.len() > 1 && args[1] == "child" {
18 // FIXME: This should check the whole `args[0]` instead of just
19 // checking that it ends_with the executable name. This
20 // is needed because of Windows, which has a different behavior.
21 // See #15149 for more info.
22 let my_path = env::current_exe().unwrap();
23 return assert_eq!(my_path.file_stem(), Some(OsStr::new("mytest")));
30 // If we're the parent, copy our own binary to a new directory.
31 let my_path = env::current_exe().unwrap();
32 let my_dir = my_path.parent().unwrap();
34 let child_dir = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap());
35 let child_dir = child_dir.join("issue-15140-child");
36 fs::create_dir_all(&child_dir).unwrap();
38 let child_path = child_dir.join(&format!("mytest{}", env::consts::EXE_SUFFIX));
39 fs::copy(&my_path, &child_path).unwrap();
41 // Append the new directory to our own PATH.
43 let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap()).collect();
44 paths.push(child_dir.to_path_buf());
45 env::join_paths(paths).unwrap()
49 process::Command::new("mytest").env("PATH", &path).arg("child").output().unwrap();
52 child_output.status.success(),
53 "child assertion failed\n child stdout:\n {}\n child stderr:\n {}",
54 str::from_utf8(&child_output.stdout).unwrap(),
55 str::from_utf8(&child_output.stderr).unwrap()