]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-fulldeps/issue-15149.rs
Auto merge of #61735 - eddyb:must-use-life, r=oli-obk
[rust.git] / src / test / run-pass-fulldeps / issue-15149.rs
1 #![allow(unused_variables)]
2 // no-prefer-dynamic
3 // ignore-cross-compile
4
5 use std::env;
6 use std::fs;
7 use std::process;
8 use std::str;
9 use std::path::PathBuf;
10
11 fn main() {
12     // If we're the child, make sure we were invoked correctly
13     let args: Vec<String> = env::args().collect();
14     if args.len() > 1 && args[1] == "child" {
15         // FIXME: This should check the whole `args[0]` instead of just
16         // checking that it ends_with the executable name. This
17         // is needed because of Windows, which has a different behavior.
18         // See #15149 for more info.
19         return assert!(args[0].ends_with(&format!("mytest{}",
20                                                   env::consts::EXE_SUFFIX)));
21     }
22
23     test();
24 }
25
26 fn test() {
27     // If we're the parent, copy our own binary to a new directory.
28     let my_path = env::current_exe().unwrap();
29     let my_dir  = my_path.parent().unwrap();
30
31     let child_dir = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap());
32     let child_dir = child_dir.join("issue-15140-child");
33     fs::create_dir_all(&child_dir).unwrap();
34
35     let child_path = child_dir.join(&format!("mytest{}",
36                                              env::consts::EXE_SUFFIX));
37     fs::copy(&my_path, &child_path).unwrap();
38
39     // Append the new directory to our own PATH.
40     let path = {
41         let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap()).collect();
42         paths.push(child_dir.to_path_buf());
43         env::join_paths(paths).unwrap()
44     };
45
46     let child_output = process::Command::new("mytest").env("PATH", &path)
47                                                       .arg("child")
48                                                       .output().unwrap();
49
50     assert!(child_output.status.success(),
51             format!("child assertion failed\n child stdout:\n {}\n child stderr:\n {}",
52                     str::from_utf8(&child_output.stdout).unwrap(),
53                     str::from_utf8(&child_output.stderr).unwrap()));
54 }