2014-06-24 14:10:31 -05: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 12:59:17 -06:00
|
|
|
// no-prefer-dynamic
|
2015-04-22 17:20:57 -05:00
|
|
|
// ignore-cross-compile
|
2015-02-23 12:59:17 -06:00
|
|
|
|
2015-04-10 13:12:43 -05:00
|
|
|
#![feature(rustc_private)]
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2015-04-10 13:12:43 -05:00
|
|
|
extern crate rustc_back;
|
2015-02-23 12:59:17 -06:00
|
|
|
|
2015-02-13 14:08:05 -06:00
|
|
|
use std::env;
|
2015-02-23 12:59:17 -06:00
|
|
|
use std::fs;
|
|
|
|
use std::process;
|
|
|
|
use std::str;
|
2015-04-10 13:12:43 -05:00
|
|
|
use rustc_back::tempdir::TempDir;
|
2014-06-24 14:10:31 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// If we're the child, make sure we were invoked correctly
|
2015-02-16 08:04:02 -06:00
|
|
|
let args: Vec<String> = env::args().collect();
|
2015-02-01 20:53:25 -06:00
|
|
|
if args.len() > 1 && args[1] == "child" {
|
2015-01-25 03:52:55 -06: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-04-10 13:12:43 -05:00
|
|
|
return assert!(args[0].ends_with(&format!("mytest{}",
|
|
|
|
env::consts::EXE_SUFFIX)));
|
2014-06-24 14:10:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
test();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test() {
|
2015-01-15 14:49:23 -06:00
|
|
|
// If we're the parent, copy our own binary to a new directory.
|
2015-02-16 08:04:02 -06:00
|
|
|
let my_path = env::current_exe().unwrap();
|
2015-02-23 12:59:17 -06:00
|
|
|
let my_dir = my_path.parent().unwrap();
|
2015-01-15 14:49:23 -06:00
|
|
|
|
2015-04-10 13:12:43 -05:00
|
|
|
let child_dir = TempDir::new_in(&my_dir, "issue-15140-child").unwrap();
|
|
|
|
let child_dir = child_dir.path();
|
2015-01-15 14:49:23 -06:00
|
|
|
|
2015-02-23 12:59:17 -06:00
|
|
|
let child_path = child_dir.join(&format!("mytest{}",
|
|
|
|
env::consts::EXE_SUFFIX));
|
2015-01-15 14:49:23 -06:00
|
|
|
fs::copy(&my_path, &child_path).unwrap();
|
|
|
|
|
|
|
|
// Append the new directory to our own PATH.
|
2015-02-16 08:04:02 -06:00
|
|
|
let path = {
|
|
|
|
let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap()).collect();
|
2015-02-23 12:59:17 -06:00
|
|
|
paths.push(child_dir.to_path_buf());
|
2015-02-16 08:04:02 -06:00
|
|
|
env::join_paths(paths.iter()).unwrap()
|
|
|
|
};
|
2014-06-24 14:10:31 -05:00
|
|
|
|
2015-02-16 08:04:02 -06:00
|
|
|
let child_output = process::Command::new("mytest").env("PATH", &path)
|
|
|
|
.arg("child")
|
|
|
|
.output().unwrap();
|
2015-01-22 12:54:45 -06:00
|
|
|
|
|
|
|
assert!(child_output.status.success(),
|
|
|
|
format!("child assertion failed\n child stdout:\n {}\n child stderr:\n {}",
|
2015-02-23 12:59:17 -06:00
|
|
|
str::from_utf8(&child_output.stdout).unwrap(),
|
|
|
|
str::from_utf8(&child_output.stderr).unwrap()));
|
2015-01-22 19:34:58 -06:00
|
|
|
|
2015-05-19 12:37:17 -05:00
|
|
|
let res = fs::remove_dir_all(&child_dir);
|
|
|
|
if res.is_err() {
|
|
|
|
// On Windows deleting just executed mytest.exe can fail because it's still locked
|
|
|
|
std::thread::sleep_ms(1000);
|
|
|
|
fs::remove_dir_all(&child_dir).unwrap();
|
|
|
|
}
|
2014-06-24 14:10:31 -05:00
|
|
|
}
|