2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2014-05-07 23:26:16 +00:00
|
|
|
//@ no-prefer-dynamic
|
|
|
|
|
|
|
|
// The test copies itself into a subdirectory with a non-ASCII name and then
|
|
|
|
// runs it as a child process within the subdirectory. The parent process
|
|
|
|
// also adds an environment variable and an argument, both containing
|
|
|
|
// non-ASCII characters. The child process ensures all the strings are
|
|
|
|
// intact.
|
|
|
|
|
2024-03-06 20:44:54 +00:00
|
|
|
//@ ignore-wasm32 no processes
|
2019-04-24 16:26:33 +00:00
|
|
|
//@ ignore-sgx no processes
|
2022-10-13 21:26:52 +00:00
|
|
|
//@ ignore-fuchsia Filesystem manipulation privileged
|
2015-03-18 07:57:29 +00:00
|
|
|
|
2015-02-25 07:27:20 +00:00
|
|
|
use std::io::prelude::*;
|
|
|
|
use std::io;
|
|
|
|
use std::fs;
|
|
|
|
use std::process::Command;
|
2015-02-16 14:04:02 +00:00
|
|
|
use std::env;
|
2015-04-21 02:01:20 +00:00
|
|
|
use std::path::Path;
|
2014-05-07 23:26:16 +00:00
|
|
|
|
|
|
|
fn main() {
|
2015-02-16 14:04:02 +00:00
|
|
|
let my_args = env::args().collect::<Vec<_>>();
|
2015-03-17 20:33:26 +00:00
|
|
|
let my_cwd = env::current_dir().unwrap();
|
2015-02-16 14:04:02 +00:00
|
|
|
let my_env = env::vars().collect::<Vec<_>>();
|
2015-03-17 20:33:26 +00:00
|
|
|
let my_path = env::current_exe().unwrap();
|
2015-02-25 07:27:20 +00:00
|
|
|
let my_dir = my_path.parent().unwrap();
|
|
|
|
let my_ext = my_path.extension().and_then(|s| s.to_str()).unwrap_or("");
|
2014-05-07 23:26:16 +00:00
|
|
|
|
|
|
|
// some non-ASCII characters
|
2015-02-25 07:27:20 +00:00
|
|
|
let blah = "\u{3c0}\u{42f}\u{97f3}\u{e6}\u{221e}";
|
2014-05-07 23:26:16 +00:00
|
|
|
|
|
|
|
let child_name = "child";
|
2014-05-28 03:44:58 +00:00
|
|
|
let child_dir = format!("process-spawn-with-unicode-params-{}", blah);
|
2014-05-07 23:26:16 +00:00
|
|
|
|
|
|
|
// parameters sent to child / expected to be received from parent
|
|
|
|
let arg = blah;
|
2015-02-25 07:27:20 +00:00
|
|
|
let cwd = my_dir.join(&child_dir);
|
2014-05-25 10:17:19 +00:00
|
|
|
let env = ("RUST_TEST_PROC_SPAWN_UNICODE".to_string(), blah.to_string());
|
2014-05-07 23:26:16 +00:00
|
|
|
|
|
|
|
// am I the parent or the child?
|
|
|
|
if my_args.len() == 1 { // parent
|
|
|
|
|
|
|
|
let child_filestem = Path::new(child_name);
|
|
|
|
let child_filename = child_filestem.with_extension(my_ext);
|
2015-02-25 07:27:20 +00:00
|
|
|
let child_path = cwd.join(&child_filename);
|
2014-05-07 23:26:16 +00:00
|
|
|
|
|
|
|
// make a separate directory for the child
|
2015-02-25 07:27:20 +00:00
|
|
|
let _ = fs::create_dir(&cwd);
|
|
|
|
fs::copy(&my_path, &child_path).unwrap();
|
2014-05-07 23:26:16 +00:00
|
|
|
|
|
|
|
// run child
|
2014-05-05 21:33:55 +00:00
|
|
|
let p = Command::new(&child_path)
|
|
|
|
.arg(arg)
|
2015-02-25 07:27:20 +00:00
|
|
|
.current_dir(&cwd)
|
|
|
|
.env(&env.0, &env.1)
|
2014-05-05 21:33:55 +00:00
|
|
|
.spawn().unwrap().wait_with_output().unwrap();
|
2014-05-07 23:26:16 +00:00
|
|
|
|
|
|
|
// display the output
|
2015-02-25 07:27:20 +00:00
|
|
|
io::stdout().write_all(&p.stdout).unwrap();
|
|
|
|
io::stderr().write_all(&p.stderr).unwrap();
|
2014-05-07 23:26:16 +00:00
|
|
|
|
|
|
|
// make sure the child succeeded
|
|
|
|
assert!(p.status.success());
|
|
|
|
|
|
|
|
} else { // child
|
|
|
|
|
|
|
|
// check working directory (don't try to compare with `cwd` here!)
|
2015-02-25 07:27:20 +00:00
|
|
|
assert!(my_cwd.ends_with(&child_dir));
|
2014-05-07 23:26:16 +00:00
|
|
|
|
|
|
|
// check arguments
|
2015-02-02 02:53:25 +00:00
|
|
|
assert_eq!(&*my_args[1], arg);
|
2014-05-07 23:26:16 +00:00
|
|
|
|
|
|
|
// check environment variable
|
|
|
|
assert!(my_env.contains(&env));
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|