]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-15149.rs
auto merge of #16428 : mdinger/rust/sort_attributes, r=cmr
[rust.git] / src / test / run-pass / 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 #![feature(phase)]
12 extern crate native;
13 #[phase(plugin)]
14 extern crate green;
15
16 use native::NativeTaskBuilder;
17 use std::io::{TempDir, Command, fs};
18 use std::os;
19 use std::task::TaskBuilder;
20
21 green_start!(main)
22
23 fn main() {
24     // If we're the child, make sure we were invoked correctly
25     let args = os::args();
26     if args.len() > 1 && args.get(1).as_slice() == "child" {
27         return assert_eq!(args.get(0).as_slice(), "mytest");
28     }
29
30     test();
31     let (tx, rx) = channel();
32     TaskBuilder::new().native().spawn(proc() {
33         tx.send(test());
34     });
35     rx.recv();
36 }
37
38 fn test() {
39     // If we're the parent, copy our own binary to a tempr directory, and then
40     // make it executable.
41     let dir = TempDir::new("mytest").unwrap();
42     let me = os::self_exe_name().unwrap();
43     let dest = dir.path().join(format!("mytest{}", os::consts::EXE_SUFFIX));
44     fs::copy(&me, &dest).unwrap();
45
46     // Append the temp directory to our own PATH.
47     let mut path = os::split_paths(os::getenv("PATH").unwrap_or(String::new()));
48     path.push(dir.path().clone());
49     let path = os::join_paths(path.as_slice()).unwrap();
50
51     Command::new("mytest").env("PATH", path.as_slice())
52                           .arg("child")
53                           .spawn().unwrap();
54 }