Skip to content

Commit 8353396

Browse files
committed
add unit test for config and integration test with cargo --list
1 parent 754b79c commit 8353396

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/testsuite/cargo_command.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,32 @@ fn list_command_looks_at_path() {
104104
);
105105
}
106106

107+
#[cfg(windows)]
108+
#[cargo_test]
109+
fn list_command_looks_at_path_case_mismatch() {
110+
let proj = project()
111+
.executable(Path::new("path-test").join("cargo-1"), "")
112+
.build();
113+
114+
let mut path = path();
115+
path.push(proj.root().join("path-test"));
116+
let path = env::join_paths(path.iter()).unwrap();
117+
118+
// See issue #11814: Environment variable names are case-insensitive on Windows.
119+
// We need to check that having "Path" instead of "PATH" is okay.
120+
let output = cargo_process("-v --list")
121+
.env("Path", &path)
122+
.env_remove("PATH")
123+
.exec_with_output()
124+
.unwrap();
125+
let output = str::from_utf8(&output.stdout).unwrap();
126+
assert!(
127+
output.contains("\n 1 "),
128+
"missing 1: {}",
129+
output
130+
);
131+
}
132+
107133
#[cargo_test]
108134
fn list_command_handles_known_external_commands() {
109135
let p = project()

tests/testsuite/config.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,31 @@ f1 = 123
211211
assert_eq!(s, S { f1: Some(456) });
212212
}
213213

214+
#[cfg(windows)]
215+
#[cargo_test]
216+
fn environment_variable_casing() {
217+
// Issue #11814: Environment variable names are case-insensitive on Windows.
218+
let config = ConfigBuilder::new()
219+
.env("Path", "abc")
220+
.env("Two-Words", "abc")
221+
.env("two_words", "def")
222+
.build();
223+
224+
let var = config.get_env("PATH").unwrap();
225+
assert_eq!(var, String::from("abc"));
226+
227+
let var = config.get_env("path").unwrap();
228+
assert_eq!(var, String::from("abc"));
229+
230+
let var = config.get_env("TWO-WORDS").unwrap();
231+
assert_eq!(var, String::from("abc"));
232+
233+
// Make sure that we can still distinguish between dashes and underscores
234+
// in variable names.
235+
let var = config.get_env("Two_Words").unwrap();
236+
assert_eq!(var, String::from("def"));
237+
}
238+
214239
#[cargo_test]
215240
fn config_works_with_extension() {
216241
write_config_toml(

0 commit comments

Comments
 (0)