Skip to content

Commit c052016

Browse files
committed
Clear RUSTUP_* environment variables in test_env
1 parent a71d838 commit c052016

File tree

4 files changed

+59
-25
lines changed

4 files changed

+59
-25
lines changed

crates/cargo-test-support/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,11 @@ pub trait TestEnvCommandExt: Sized {
13831383
self = self.env_remove(&k);
13841384
}
13851385
}
1386+
for (k, _v) in env::vars() {
1387+
if k.starts_with("RUSTUP_") {
1388+
self = self.env_remove(&k);
1389+
}
1390+
}
13861391
if env::var_os("RUSTUP_TOOLCHAIN").is_some() {
13871392
// Override the PATH to avoid executing the rustup wrapper thousands
13881393
// of times. This makes the testsuite run substantially faster.

tests/testsuite/cargo_alias_config.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,17 @@ fn builtin_alias_shadowing_external_subcommand() {
151151
paths.push(p.root());
152152
let path = env::join_paths(paths).unwrap();
153153

154-
p.cargo("t")
155-
.env("PATH", &path)
156-
.with_stderr_data(str![[r#"
154+
let mut process = p.cargo("t");
155+
process.env("PATH", &path).with_stderr_data(str![[r#"
157156
[COMPILING] foo v0.5.0 ([ROOT]/foo)
158157
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
159158
[RUNNING] unittests src/main.rs (target/debug/deps/foo-[HASH][EXE])
160159
161-
"#]])
162-
.run();
160+
"#]]);
161+
if let Some(val) = env::var_os("RUSTUP_HOME") {
162+
process.env("RUSTUP_HOME", val);
163+
}
164+
process.run();
163165
}
164166

165167
#[cargo_test]
@@ -181,7 +183,8 @@ fn alias_shadowing_external_subcommand() {
181183
paths.push(echo.target_debug_dir());
182184
let path = env::join_paths(paths).unwrap();
183185

184-
p.cargo("echo")
186+
let mut process = p.cargo("echo");
187+
process
185188
.env("PATH", &path)
186189
.with_stderr_data(str![[r#"
187190
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
@@ -190,8 +193,11 @@ fn alias_shadowing_external_subcommand() {
190193
[COMPILING] foo v0.5.0 ([ROOT]/foo)
191194
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
192195
193-
"#]])
194-
.run();
196+
"#]]);
197+
if let Some(val) = env::var_os("RUSTUP_HOME") {
198+
process.env("RUSTUP_HOME", val);
199+
}
200+
process.run();
195201
}
196202

197203
#[cargo_test]

tests/testsuite/install.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ fn multiple_pkgs_path_set() {
280280
let mut path = path();
281281
path.push(paths::cargo_home().join("bin"));
282282
let new_path = env::join_paths(path).unwrap();
283-
cargo_process("install foo bar baz")
283+
let mut process = cargo_process("install foo bar baz");
284+
process
284285
.env("PATH", new_path)
285286
.with_status(101)
286287
.with_stderr_data(str![[r#"
@@ -303,8 +304,11 @@ fn multiple_pkgs_path_set() {
303304
[SUMMARY] Successfully installed foo, bar! Failed to install baz (see error(s) above).
304305
[ERROR] some crates failed to install
305306
306-
"#]])
307-
.run();
307+
"#]]);
308+
if let Some(val) = env::var_os("RUSTUP_HOME") {
309+
process.env("RUSTUP_HOME", val);
310+
}
311+
process.run();
308312
assert_has_installed_exe(paths::cargo_home(), "foo");
309313
assert_has_installed_exe(paths::cargo_home(), "bar");
310314

@@ -645,8 +649,11 @@ fn relative_install_location_with_path_set() {
645649
[INSTALLING] [ROOT]/foo/t1/bin/foo[EXE]
646650
[INSTALLED] package `foo v0.0.1 ([ROOT]/foo)` (executable `foo[EXE]`)
647651
648-
"#]])
649-
.run();
652+
"#]]);
653+
if let Some(val) = env::var_os("RUSTUP_HOME") {
654+
cmd.env("RUSTUP_HOME", val);
655+
}
656+
cmd.run();
650657

651658
assert_has_installed_exe(&project_t1, "foo");
652659
}

tests/testsuite/jobserver.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ test-runner:
196196
.arg("run")
197197
.arg("-j2")
198198
.run();
199-
p.process(make)
199+
let mut process = p.process(make);
200+
process
200201
.env("PATH", path)
201202
.env("CARGO", cargo_exe())
202203
.arg("run-runner")
@@ -206,14 +207,18 @@ test-runner:
206207
[RUNNING] `runner target/debug/cargo-jobserver-check[EXE]`
207208
this is a runner
208209
209-
"#]])
210-
.run();
210+
"#]]);
211+
if let Some(val) = env::var_os("RUSTUP_HOME") {
212+
process.env("RUSTUP_HOME", val);
213+
}
214+
process.run();
211215
p.process(make)
212216
.env("CARGO", cargo_exe())
213217
.arg("test")
214218
.arg("-j2")
215219
.run();
216-
p.process(make)
220+
let mut process = p.process(make);
221+
process
217222
.env("PATH", path)
218223
.env("CARGO", cargo_exe())
219224
.arg("test-runner")
@@ -223,8 +228,11 @@ this is a runner
223228
[RUNNING] unittests src/lib.rs (target/debug/deps/cargo_jobserver_check-[HASH][EXE])
224229
this is a runner
225230
226-
"#]])
227-
.run();
231+
"#]]);
232+
if let Some(val) = env::var_os("RUSTUP_HOME") {
233+
process.env("RUSTUP_HOME", val);
234+
}
235+
process.run();
228236

229237
// but not from `-j` flag
230238
p.cargo("run -j2")
@@ -238,7 +246,8 @@ this is a runner
238246
239247
"#]])
240248
.run();
241-
p.cargo("run -j2")
249+
let mut process = p.cargo("run -j2");
250+
process
242251
.env("PATH", path)
243252
.arg("--config")
244253
.arg(config_value)
@@ -251,13 +260,17 @@ this is a runner
251260
[..]no jobserver from env[..]
252261
...
253262
254-
"#]])
255-
.run();
263+
"#]]);
264+
if let Some(val) = env::var_os("RUSTUP_HOME") {
265+
process.env("RUSTUP_HOME", val);
266+
}
267+
process.run();
256268
p.cargo("test -j2")
257269
.with_status(101)
258270
.with_stdout_data("...\n[..]no jobserver from env[..]\n...")
259271
.run();
260-
p.cargo("test -j2")
272+
let mut process = p.cargo("test -j2");
273+
process
261274
.env("PATH", path)
262275
.arg("--config")
263276
.arg(config_value)
@@ -269,8 +282,11 @@ this is a runner
269282
...
270283
271284
"#]])
272-
.with_stdout_data("...\n[..]no jobserver from env[..]\n...")
273-
.run();
285+
.with_stdout_data("...\n[..]no jobserver from env[..]\n...");
286+
if let Some(val) = env::var_os("RUSTUP_HOME") {
287+
process.env("RUSTUP_HOME", val);
288+
}
289+
process.run();
274290
}
275291

276292
#[cargo_test]

0 commit comments

Comments
 (0)