]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-15149.rs
doc: remove incomplete sentence
[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 use std::io::{TempDir, Command, fs};
12 use std::os;
13 use std::task::TaskBuilder;
14
15 fn main() {
16     // If we're the child, make sure we were invoked correctly
17     let args = os::args();
18     if args.len() > 1 && args[1].as_slice() == "child" {
19         return assert_eq!(args[0].as_slice(), "mytest");
20     }
21
22     test();
23 }
24
25 fn test() {
26     // If we're the parent, copy our own binary to a tempr directory, and then
27     // make it executable.
28     let dir = TempDir::new("mytest").unwrap();
29     let me = os::self_exe_name().unwrap();
30     let dest = dir.path().join(format!("mytest{}", os::consts::EXE_SUFFIX));
31     fs::copy(&me, &dest).unwrap();
32
33     // Append the temp directory to our own PATH.
34     let mut path = os::split_paths(os::getenv("PATH").unwrap_or(String::new()));
35     path.push(dir.path().clone());
36     let path = os::join_paths(path.as_slice()).unwrap();
37
38     Command::new("mytest").env("PATH", path.as_slice())
39                           .arg("child")
40                           .spawn().unwrap();
41 }