]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/windows/process/tests.rs
Auto merge of #86663 - fee1-dead:use-rustdoc-css, r=GuillaumeGomez
[rust.git] / library / std / src / sys / windows / process / tests.rs
1 use super::make_command_line;
2 use crate::env;
3 use crate::ffi::{OsStr, OsString};
4 use crate::process::Command;
5
6 #[test]
7 fn test_make_command_line() {
8     fn test_wrapper(prog: &str, args: &[&str], force_quotes: bool) -> String {
9         let command_line = &make_command_line(
10             OsStr::new(prog),
11             &args.iter().map(|a| OsString::from(a)).collect::<Vec<OsString>>(),
12             force_quotes,
13         )
14         .unwrap();
15         String::from_utf16(command_line).unwrap()
16     }
17
18     assert_eq!(test_wrapper("prog", &["aaa", "bbb", "ccc"], false), "\"prog\" aaa bbb ccc");
19
20     assert_eq!(
21         test_wrapper("C:\\Program Files\\blah\\blah.exe", &["aaa"], false),
22         "\"C:\\Program Files\\blah\\blah.exe\" aaa"
23     );
24     assert_eq!(
25         test_wrapper("C:\\Program Files\\blah\\blah.exe", &["aaa", "v*"], false),
26         "\"C:\\Program Files\\blah\\blah.exe\" aaa v*"
27     );
28     assert_eq!(
29         test_wrapper("C:\\Program Files\\blah\\blah.exe", &["aaa", "v*"], true),
30         "\"C:\\Program Files\\blah\\blah.exe\" \"aaa\" \"v*\""
31     );
32     assert_eq!(
33         test_wrapper("C:\\Program Files\\test", &["aa\"bb"], false),
34         "\"C:\\Program Files\\test\" aa\\\"bb"
35     );
36     assert_eq!(test_wrapper("echo", &["a b c"], false), "\"echo\" \"a b c\"");
37     assert_eq!(
38         test_wrapper("echo", &["\" \\\" \\", "\\"], false),
39         "\"echo\" \"\\\" \\\\\\\" \\\\\" \\"
40     );
41     assert_eq!(
42         test_wrapper("\u{03c0}\u{042f}\u{97f3}\u{00e6}\u{221e}", &[], false),
43         "\"\u{03c0}\u{042f}\u{97f3}\u{00e6}\u{221e}\""
44     );
45 }
46
47 // On Windows, environment args are case preserving but comparisons are case-insensitive.
48 // See: #85242
49 #[test]
50 fn windows_env_unicode_case() {
51     let test_cases = [
52         ("ä", "Ä"),
53         ("ß", "SS"),
54         ("Ä", "Ö"),
55         ("Ä", "Ö"),
56         ("I", "İ"),
57         ("I", "i"),
58         ("I", "ı"),
59         ("i", "I"),
60         ("i", "İ"),
61         ("i", "ı"),
62         ("İ", "I"),
63         ("İ", "i"),
64         ("İ", "ı"),
65         ("ı", "I"),
66         ("ı", "i"),
67         ("ı", "İ"),
68         ("ä", "Ä"),
69         ("ß", "SS"),
70         ("Ä", "Ö"),
71         ("Ä", "Ö"),
72         ("I", "İ"),
73         ("I", "i"),
74         ("I", "ı"),
75         ("i", "I"),
76         ("i", "İ"),
77         ("i", "ı"),
78         ("İ", "I"),
79         ("İ", "i"),
80         ("İ", "ı"),
81         ("ı", "I"),
82         ("ı", "i"),
83         ("ı", "İ"),
84     ];
85     // Test that `cmd.env` matches `env::set_var` when setting two strings that
86     // may (or may not) be case-folded when compared.
87     for (a, b) in test_cases.iter() {
88         let mut cmd = Command::new("cmd");
89         cmd.env(a, "1");
90         cmd.env(b, "2");
91         env::set_var(a, "1");
92         env::set_var(b, "2");
93
94         for (key, value) in cmd.get_envs() {
95             assert_eq!(
96                 env::var(key).ok(),
97                 value.map(|s| s.to_string_lossy().into_owned()),
98                 "command environment mismatch: {} {}",
99                 a,
100                 b
101             );
102         }
103     }
104 }