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-04-22 22:20:57 +00:00
|
|
|
// ignore-cross-compile
|
2015-02-23 18:59:17 +00:00
|
|
|
|
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;
|
|
|
|
use std::str;
|
2018-01-22 15:29:24 +00:00
|
|
|
use std::path::PathBuf;
|
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-04-10 18:12:43 +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
|
|
|
|
2018-01-22 15:29:24 +00:00
|
|
|
let child_dir = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap());
|
|
|
|
let child_dir = child_dir.join("issue-15140-child");
|
|
|
|
fs::create_dir_all(&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-06-10 16:22:20 +00:00
|
|
|
env::join_paths(paths).unwrap()
|
2015-02-16 14:04:02 +00:00
|
|
|
};
|
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()));
|
2014-06-24 19:10:31 +00:00
|
|
|
}
|