1 use super::make_command_line;
4 use crate::ffi::{OsStr, OsString};
5 use crate::process::Command;
9 let command_line = &make_command_line(
10 OsStr::new("quoted exe"),
12 Arg::Regular(OsString::from("quote me")),
13 Arg::Raw(OsString::from("quote me *not*")),
14 Arg::Raw(OsString::from("\t\\")),
15 Arg::Raw(OsString::from("internal \\\"backslash-\"quote")),
16 Arg::Regular(OsString::from("optional-quotes")),
22 String::from_utf16(command_line).unwrap(),
23 "\"quoted exe\" \"quote me\" quote me *not* \t\\ internal \\\"backslash-\"quote optional-quotes"
28 fn test_make_command_line() {
29 fn test_wrapper(prog: &str, args: &[&str], force_quotes: bool) -> String {
30 let command_line = &make_command_line(
32 &args.iter().map(|a| Arg::Regular(OsString::from(a))).collect::<Vec<_>>(),
36 String::from_utf16(command_line).unwrap()
39 assert_eq!(test_wrapper("prog", &["aaa", "bbb", "ccc"], false), "\"prog\" aaa bbb ccc");
41 assert_eq!(test_wrapper("prog", &[r"C:\"], false), r#""prog" C:\"#);
42 assert_eq!(test_wrapper("prog", &[r"2slashes\\"], false), r#""prog" 2slashes\\"#);
43 assert_eq!(test_wrapper("prog", &[r" C:\"], false), r#""prog" " C:\\""#);
44 assert_eq!(test_wrapper("prog", &[r" 2slashes\\"], false), r#""prog" " 2slashes\\\\""#);
47 test_wrapper("C:\\Program Files\\blah\\blah.exe", &["aaa"], false),
48 "\"C:\\Program Files\\blah\\blah.exe\" aaa"
51 test_wrapper("C:\\Program Files\\blah\\blah.exe", &["aaa", "v*"], false),
52 "\"C:\\Program Files\\blah\\blah.exe\" aaa v*"
55 test_wrapper("C:\\Program Files\\blah\\blah.exe", &["aaa", "v*"], true),
56 "\"C:\\Program Files\\blah\\blah.exe\" \"aaa\" \"v*\""
59 test_wrapper("C:\\Program Files\\test", &["aa\"bb"], false),
60 "\"C:\\Program Files\\test\" aa\\\"bb"
62 assert_eq!(test_wrapper("echo", &["a b c"], false), "\"echo\" \"a b c\"");
64 test_wrapper("echo", &["\" \\\" \\", "\\"], false),
65 "\"echo\" \"\\\" \\\\\\\" \\\\\" \\"
68 test_wrapper("\u{03c0}\u{042f}\u{97f3}\u{00e6}\u{221e}", &[], false),
69 "\"\u{03c0}\u{042f}\u{97f3}\u{00e6}\u{221e}\""
73 // On Windows, environment args are case preserving but comparisons are case-insensitive.
76 fn windows_env_unicode_case() {
111 // Test that `cmd.env` matches `env::set_var` when setting two strings that
112 // may (or may not) be case-folded when compared.
113 for (a, b) in test_cases.iter() {
114 let mut cmd = Command::new("cmd");
117 env::set_var(a, "1");
118 env::set_var(b, "2");
120 for (key, value) in cmd.get_envs() {
123 value.map(|s| s.to_string_lossy().into_owned()),
124 "command environment mismatch: {} {}",