]> git.lizzy.rs Git - rust.git/blob - src/test/ui/process/process-spawn-with-unicode-params.rs
Rollup merge of #105843 - compiler-errors:sugg-const, r=lcnr
[rust.git] / src / test / ui / process / process-spawn-with-unicode-params.rs
1 // run-pass
2 // no-prefer-dynamic
3
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
8 // intact.
9
10 // ignore-emscripten no processes
11 // ignore-sgx no processes
12 // ignore-fuchsia Filesystem manipulation privileged
13
14 use std::io::prelude::*;
15 use std::io;
16 use std::fs;
17 use std::process::Command;
18 use std::env;
19 use std::path::Path;
20
21 fn main() {
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("");
28
29     // some non-ASCII characters
30     let blah       = "\u{3c0}\u{42f}\u{97f3}\u{e6}\u{221e}";
31
32     let child_name = "child";
33     let child_dir  = format!("process-spawn-with-unicode-params-{}", blah);
34
35     // parameters sent to child / expected to be received from parent
36     let arg = blah;
37     let cwd = my_dir.join(&child_dir);
38     let env = ("RUST_TEST_PROC_SPAWN_UNICODE".to_string(), blah.to_string());
39
40     // am I the parent or the child?
41     if my_args.len() == 1 {             // parent
42
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);
46
47         // make a separate directory for the child
48         let _ = fs::create_dir(&cwd);
49         fs::copy(&my_path, &child_path).unwrap();
50
51         // run child
52         let p = Command::new(&child_path)
53                         .arg(arg)
54                         .current_dir(&cwd)
55                         .env(&env.0, &env.1)
56                         .spawn().unwrap().wait_with_output().unwrap();
57
58         // display the output
59         io::stdout().write_all(&p.stdout).unwrap();
60         io::stderr().write_all(&p.stderr).unwrap();
61
62         // make sure the child succeeded
63         assert!(p.status.success());
64
65     } else {                            // child
66
67         // check working directory (don't try to compare with `cwd` here!)
68         assert!(my_cwd.ends_with(&child_dir));
69
70         // check arguments
71         assert_eq!(&*my_args[1], arg);
72
73         // check environment variable
74         assert!(my_env.contains(&env));
75
76     };
77 }