]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-fulldeps/issue-15149.rs
rustc: Load the `rustc_trans` crate at runtime
[rust.git] / src / test / run-pass-fulldeps / issue-15149.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // no-prefer-dynamic
12 // ignore-cross-compile
13
14 use std::env;
15 use std::fs;
16 use std::process;
17 use std::str;
18 use std::path::PathBuf;
19
20 fn main() {
21     // If we're the child, make sure we were invoked correctly
22     let args: Vec<String> = env::args().collect();
23     if args.len() > 1 && args[1] == "child" {
24         // FIXME: This should check the whole `args[0]` instead of just
25         // checking that it ends_with the executable name. This
26         // is needed because of Windows, which has a different behavior.
27         // See #15149 for more info.
28         return assert!(args[0].ends_with(&format!("mytest{}",
29                                                   env::consts::EXE_SUFFIX)));
30     }
31
32     test();
33 }
34
35 fn test() {
36     // If we're the parent, copy our own binary to a new directory.
37     let my_path = env::current_exe().unwrap();
38     let my_dir  = my_path.parent().unwrap();
39
40     let child_dir = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap());
41     let child_dir = child_dir.join("issue-15140-child");
42     fs::create_dir_all(&child_dir).unwrap();
43
44     let child_path = child_dir.join(&format!("mytest{}",
45                                              env::consts::EXE_SUFFIX));
46     fs::copy(&my_path, &child_path).unwrap();
47
48     // Append the new directory to our own PATH.
49     let path = {
50         let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap()).collect();
51         paths.push(child_dir.to_path_buf());
52         env::join_paths(paths).unwrap()
53     };
54
55     let child_output = process::Command::new("mytest").env("PATH", &path)
56                                                       .arg("child")
57                                                       .output().unwrap();
58
59     assert!(child_output.status.success(),
60             format!("child assertion failed\n child stdout:\n {}\n child stderr:\n {}",
61                     str::from_utf8(&child_output.stdout).unwrap(),
62                     str::from_utf8(&child_output.stderr).unwrap()));
63 }