2014-06-24 19:10:31 +00:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-02-23 18:59:17 +00:00
|
|
|
// no-prefer-dynamic
|
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
// pretty-expanded FIXME #23616
|
|
|
|
|
2015-02-23 18:59:17 +00:00
|
|
|
#![feature(fs, process, env, path, rand)]
|
|
|
|
|
2015-02-13 20:08:05 +00:00
|
|
|
use std::env;
|
2015-02-23 18:59:17 +00:00
|
|
|
use std::fs;
|
|
|
|
use std::process;
|
2015-01-23 01:34:58 +00:00
|
|
|
use std::rand::random;
|
2015-02-23 18:59:17 +00:00
|
|
|
use std::str;
|
2014-06-24 19:10:31 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// If we're the child, make sure we were invoked correctly
|
2015-02-16 14:04:02 +00:00
|
|
|
let args: Vec<String> = env::args().collect();
|
2015-02-02 02:53:25 +00:00
|
|
|
if args.len() > 1 && args[1] == "child" {
|
2015-01-25 09:52:55 +00:00
|
|
|
// FIXME: This should check the whole `args[0]` instead of just
|
|
|
|
// checking that it ends_with the executable name. This
|
|
|
|
// is needed because of Windows, which has a different behavior.
|
|
|
|
// See #15149 for more info.
|
2015-02-16 14:04:02 +00:00
|
|
|
return assert!(args[0].ends_with(&format!("mytest{}", env::consts::EXE_SUFFIX)[]));
|
2014-06-24 19:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test() {
|
2015-01-15 20:49:23 +00:00
|
|
|
// If we're the parent, copy our own binary to a new directory.
|
2015-02-16 14:04:02 +00:00
|
|
|
let my_path = env::current_exe().unwrap();
|
2015-02-23 18:59:17 +00:00
|
|
|
let my_dir = my_path.parent().unwrap();
|
2015-01-15 20:49:23 +00:00
|
|
|
|
2015-01-23 01:34:58 +00:00
|
|
|
let random_u32: u32 = random();
|
2015-02-23 18:59:17 +00:00
|
|
|
let child_dir = my_dir.join(&format!("issue-15149-child-{}", random_u32));
|
|
|
|
fs::create_dir(&child_dir).unwrap();
|
2015-01-15 20:49:23 +00:00
|
|
|
|
2015-02-23 18:59:17 +00:00
|
|
|
let child_path = child_dir.join(&format!("mytest{}",
|
|
|
|
env::consts::EXE_SUFFIX));
|
2015-01-15 20:49:23 +00:00
|
|
|
fs::copy(&my_path, &child_path).unwrap();
|
|
|
|
|
|
|
|
// Append the new directory to our own PATH.
|
2015-02-16 14:04:02 +00:00
|
|
|
let path = {
|
|
|
|
let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap()).collect();
|
2015-02-23 18:59:17 +00:00
|
|
|
paths.push(child_dir.to_path_buf());
|
2015-02-16 14:04:02 +00:00
|
|
|
env::join_paths(paths.iter()).unwrap()
|
|
|
|
};
|
2014-06-24 19:10:31 +00:00
|
|
|
|
2015-02-16 14:04:02 +00:00
|
|
|
let child_output = process::Command::new("mytest").env("PATH", &path)
|
|
|
|
.arg("child")
|
|
|
|
.output().unwrap();
|
2015-01-22 18:54:45 +00:00
|
|
|
|
|
|
|
assert!(child_output.status.success(),
|
|
|
|
format!("child assertion failed\n child stdout:\n {}\n child stderr:\n {}",
|
2015-02-23 18:59:17 +00:00
|
|
|
str::from_utf8(&child_output.stdout).unwrap(),
|
|
|
|
str::from_utf8(&child_output.stderr).unwrap()));
|
2015-01-23 01:34:58 +00:00
|
|
|
|
2015-02-23 18:59:17 +00:00
|
|
|
fs::remove_dir_all(&child_dir).unwrap();
|
2015-01-23 01:34:58 +00:00
|
|
|
|
2014-06-24 19:10:31 +00:00
|
|
|
}
|