Skip to content

Commit d1cd4e8

Browse files
committed
Move a flaky process test out of libstd
This test ensures that everything in `env::vars()` is inherited but that's not actually true because other tests may add env vars after we spawn the process, causing the test to be flaky! This commit moves the test to a run-pass test where it can execute in isolation. Along the way this removes a lot of the platform specificity of the test, using iteslf to print the environment instead of a foreign process.
1 parent 0b9f19d commit d1cd4e8

File tree

2 files changed

+25
-36
lines changed

2 files changed

+25
-36
lines changed

src/libstd/process.rs

-36
Original file line numberDiff line numberDiff line change
@@ -1889,42 +1889,6 @@ mod tests {
18891889
cmd
18901890
}
18911891

1892-
#[test]
1893-
fn test_inherit_env() {
1894-
use env;
1895-
1896-
let result = env_cmd().output().unwrap();
1897-
let output = String::from_utf8(result.stdout).unwrap();
1898-
1899-
for (ref k, ref v) in env::vars() {
1900-
// Don't check android RANDOM variable which seems to change
1901-
// whenever the shell runs, and our `env_cmd` is indeed running a
1902-
// shell which means it'll get a different RANDOM than we probably
1903-
// have.
1904-
//
1905-
// Also skip env vars with `-` in the name on android because, well,
1906-
// I'm not sure. It appears though that the `set` command above does
1907-
// not print env vars with `-` in the name, so we just skip them
1908-
// here as we won't find them in the output. Note that most env vars
1909-
// use `_` instead of `-`, but our build system sets a few env vars
1910-
// with `-` in the name.
1911-
if cfg!(target_os = "android") &&
1912-
(*k == "RANDOM" || k.contains("-")) {
1913-
continue
1914-
}
1915-
1916-
// Windows has hidden environment variables whose names start with
1917-
// equals signs (`=`). Those do not show up in the output of the
1918-
// `set` command.
1919-
assert!((cfg!(windows) && k.starts_with("=")) ||
1920-
k.starts_with("DYLD") ||
1921-
output.contains(&format!("{}={}", *k, *v)) ||
1922-
output.contains(&format!("{}='{}'", *k, *v)),
1923-
"output doesn't contain `{}={}`\n{}",
1924-
k, v, output);
1925-
}
1926-
}
1927-
19281892
#[test]
19291893
fn test_override_env() {
19301894
use env;

src/test/run-pass/inherit-env.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ignore-emscripten
2+
// ignore-wasm32
3+
4+
use std::env;
5+
use std::process::Command;
6+
7+
fn main() {
8+
if env::args().nth(1).map(|s| s == "print").unwrap_or(false) {
9+
for (k, v) in env::vars() {
10+
println!("{}={}", k, v);
11+
}
12+
return
13+
}
14+
15+
let me = env::current_exe().unwrap();
16+
let result = Command::new(me).arg("print").output().unwrap();
17+
let output = String::from_utf8(result.stdout).unwrap();
18+
19+
for (k, v) in env::vars() {
20+
assert!(output.contains(&format!("{}={}", k, v)),
21+
"output doesn't contain `{}={}`\n{}",
22+
k, v, output);
23+
}
24+
}
25+

0 commit comments

Comments
 (0)