4 // The test copies itself into a subdirectory with a non-ASCII name and then
5 // runs it as a child process within the subdirectory. The parent process
6 // also adds an environment variable and an argument, both containing
7 // non-ASCII characters. The child process ensures all the strings are
10 // ignore-emscripten no processes
11 // ignore-sgx no processes
12 // ignore-fuchsia Filesystem manipulation privileged
14 use std::io::prelude::*;
17 use std::process::Command;
22 let my_args = env::args().collect::<Vec<_>>();
23 let my_cwd = env::current_dir().unwrap();
24 let my_env = env::vars().collect::<Vec<_>>();
25 let my_path = env::current_exe().unwrap();
26 let my_dir = my_path.parent().unwrap();
27 let my_ext = my_path.extension().and_then(|s| s.to_str()).unwrap_or("");
29 // some non-ASCII characters
30 let blah = "\u{3c0}\u{42f}\u{97f3}\u{e6}\u{221e}";
32 let child_name = "child";
33 let child_dir = format!("process-spawn-with-unicode-params-{}", blah);
35 // parameters sent to child / expected to be received from parent
37 let cwd = my_dir.join(&child_dir);
38 let env = ("RUST_TEST_PROC_SPAWN_UNICODE".to_string(), blah.to_string());
40 // am I the parent or the child?
41 if my_args.len() == 1 { // parent
43 let child_filestem = Path::new(child_name);
44 let child_filename = child_filestem.with_extension(my_ext);
45 let child_path = cwd.join(&child_filename);
47 // make a separate directory for the child
48 let _ = fs::create_dir(&cwd);
49 fs::copy(&my_path, &child_path).unwrap();
52 let p = Command::new(&child_path)
56 .spawn().unwrap().wait_with_output().unwrap();
59 io::stdout().write_all(&p.stdout).unwrap();
60 io::stderr().write_all(&p.stderr).unwrap();
62 // make sure the child succeeded
63 assert!(p.status.success());
67 // check working directory (don't try to compare with `cwd` here!)
68 assert!(my_cwd.ends_with(&child_dir));
71 assert_eq!(&*my_args[1], arg);
73 // check environment variable
74 assert!(my_env.contains(&env));