Skip to content

Commit

Permalink
tests: fix some failures on windows due to a missing TEMP environment…
Browse files Browse the repository at this point in the history
… variable
  • Loading branch information
gulbanana committed Feb 25, 2024
1 parent 7525fac commit 81f5989
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions cli/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,29 @@ impl TestEnvironment {
cmd.env("SSL_CERT_FILE", "/dev/null");
}

if cfg!(all(windows, target_env = "gnu")) {
// MinGW executables cannot run without `mingw\bin` in the PATH (which we're
// clearing above), so we add it again here.
if let Ok(path_var) = std::env::var("PATH").or_else(|_| std::env::var("Path")) {
// There can be slight variations of this path (e.g. `mingw64\bin`) so we're
// intentionally being lenient here.
let mingw_directories = path_var
.split(';')
.filter(|dir| dir.contains("mingw"))
.join(";");

if !mingw_directories.is_empty() {
cmd.env("PATH", mingw_directories);
}
}

// MinGW uses `TEMP` to create temporary directories, which we need for some
if cfg!(windows) {
// Windows uses `TEMP` to create temporary directories, which we need for some
// tests.
if let Ok(tmp_var) = std::env::var("TEMP") {
cmd.env("TEMP", tmp_var);
}

if cfg!(target_env = "gnu") {
// MinGW executables cannot run without `mingw\bin` in the PATH (which we're
// clearing above), so we add it again here.
if let Ok(path_var) = std::env::var("PATH").or_else(|_| std::env::var("Path")) {
// There can be slight variations of this path (e.g. `mingw64\bin`) so we're
// intentionally being lenient here.
let mingw_directories = path_var
.split(';')
.filter(|dir| dir.contains("mingw"))
.join(";");

if !mingw_directories.is_empty() {
cmd.env("PATH", mingw_directories);
}
}
}
}

cmd
Expand Down

0 comments on commit 81f5989

Please sign in to comment.