Skip to content

Commit 8d25c01

Browse files
committed
fix(test/clitools): disable auto-install by default unless required
This also ensures that every test case relying on the `RUSTUP_AUTO_INSTALL` config option is explicitly setting it.
1 parent 7a5cb96 commit 8d25c01

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

src/test/clitools.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ impl Config {
277277
"/bogus-config-file.toml",
278278
);
279279

280+
// Disable auto installation of active toolchain unless explicitly requested
281+
cmd.env("RUSTUP_AUTO_INSTALL", "0");
282+
280283
// Pass `RUSTUP_CI` over to the test process in case it is required downstream
281284
if let Some(ci) = env::var_os("RUSTUP_CI") {
282285
cmd.env("RUSTUP_CI", ci);

tests/suite/cli_misc.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async fn rustc_with_bad_rustup_toolchain_env_var() {
6464
.expect_with_env(["rustc"], [("RUSTUP_TOOLCHAIN", "bogus")])
6565
.await
6666
.with_stderr(snapbox::str![[r#"
67-
error: override toolchain 'bogus' is not installed[..]
67+
error:[..] toolchain 'bogus' is not installed[..]
6868
6969
"#]])
7070
.is_err();
@@ -1381,7 +1381,10 @@ async fn which_asking_uninstalled_toolchain() {
13811381
"#]])
13821382
.is_ok();
13831383
cx.config
1384-
.expect(["rustup", "which", "--toolchain=nightly", "rustc"])
1384+
.expect_with_env(
1385+
["rustup", "which", "--toolchain=nightly", "rustc"],
1386+
[("RUSTUP_AUTO_INSTALL", "1")],
1387+
)
13851388
.await
13861389
.with_stdout(snapbox::str![[r#"
13871390
[..]/toolchains/nightly-[HOST_TRIPLE]/bin/rustc[EXE]
@@ -1512,7 +1515,7 @@ active because: overridden by +toolchain on the command line
15121515
.expect(["rustup", "+foo", "which", "rustc"])
15131516
.await
15141517
.with_stderr(snapbox::str![[r#"
1515-
error: override toolchain 'foo' is not installed: the +toolchain on the command line specifies an uninstalled toolchain
1518+
error:[..] toolchain 'foo' is not installed[..]
15161519
15171520
"#]])
15181521
.is_err();

tests/suite/cli_rustup.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ async fn show_toolchain_override_not_installed() {
12381238
.await
12391239
.is_ok();
12401240
cx.config
1241-
.expect(["rustup", "show"])
1241+
.expect_with_env(["rustup", "show"], [("RUSTUP_AUTO_INSTALL", "1")])
12421242
.await
12431243
.extend_redactions([("[RUSTUP_DIR]", &cx.config.rustupdir.to_string())])
12441244
.with_stdout(snapbox::str![[r#"
@@ -1353,7 +1353,13 @@ installed targets:
13531353
async fn show_toolchain_env_not_installed() {
13541354
let cx = CliTestContext::new(Scenario::SimpleV2).await;
13551355
cx.config
1356-
.expect_with_env(["rustup", "show"], [("RUSTUP_TOOLCHAIN", "nightly")])
1356+
.expect_with_env(
1357+
["rustup", "show"],
1358+
[
1359+
("RUSTUP_TOOLCHAIN", "nightly"),
1360+
("RUSTUP_AUTO_INSTALL", "1"),
1361+
],
1362+
)
13571363
.await
13581364
.extend_redactions([("[RUSTUP_DIR]", &cx.config.rustupdir.to_string())])
13591365
.is_ok()

tests/suite/cli_v1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ async fn remove_override_toolchain_err_handling() {
271271
.await
272272
.is_ok();
273273
cx.config
274-
.expect(["rustc", "--version"])
274+
.expect_with_env(["rustc", "--version"], [("RUSTUP_AUTO_INSTALL", "1")])
275275
.await
276276
.with_stdout(snapbox::str![[r#"
277277
1.2.0 (hash-beta-1.2.0)

tests/suite/cli_v2.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ async fn remove_override_toolchain_err_handling() {
478478
.await
479479
.is_ok();
480480
cx.config
481-
.expect(["rustc", "--version"])
481+
.expect_with_env(["rustc", "--version"], [("RUSTUP_AUTO_INSTALL", "1")])
482482
.await
483483
.with_stdout(snapbox::str![[r#"
484484
1.2.0 (hash-beta-1.2.0)
@@ -511,7 +511,7 @@ async fn file_override_toolchain_err_handling() {
511511
let toolchain_file = cwd.join("rust-toolchain");
512512
rustup::utils::raw::write_file(&toolchain_file, "beta").unwrap();
513513
cx.config
514-
.expect(["rustc", "--version"])
514+
.expect_with_env(["rustc", "--version"], [("RUSTUP_AUTO_INSTALL", "1")])
515515
.await
516516
.with_stdout(snapbox::str![[r#"
517517
1.2.0 (hash-beta-1.2.0)
@@ -553,7 +553,10 @@ error: toolchain 'beta-[HOST_TRIPLE]' is not installed
553553
"#]])
554554
.is_err();
555555
cx.config
556-
.expect(["rustc", "+beta", "--version"])
556+
.expect_with_env(
557+
["rustc", "+beta", "--version"],
558+
[("RUSTUP_AUTO_INSTALL", "1")],
559+
)
557560
.await
558561
.with_stdout(snapbox::str![[r#"
559562
1.2.0 (hash-beta-1.2.0)

0 commit comments

Comments
 (0)