Skip to content

Commit a386ddd

Browse files
committed
Add test cases
1 parent 5feba51 commit a386ddd

File tree

1 file changed

+61
-16
lines changed

1 file changed

+61
-16
lines changed

tests/testsuite/rustup.rs

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -311,39 +311,84 @@ custom toolchain rustc running
311311
/// Performs a `cargo install` with a non-default toolchain in a simulated
312312
/// rustup environment. The purpose is to verify the warning that is emitted.
313313
#[cargo_test]
314-
fn cargo_install_with_non_default_toolchain() {
314+
fn cargo_install_with_toolchain_source_unset() {
315+
cargo_install_with_toolchain_source(None, false);
316+
}
317+
318+
#[cargo_test]
319+
fn cargo_install_with_toolchain_source_default() {
320+
cargo_install_with_toolchain_source(Some("default"), false);
321+
}
322+
323+
#[cargo_test]
324+
fn cargo_install_with_toolchain_source_cli() {
325+
cargo_install_with_toolchain_source(Some("cli"), false);
326+
}
327+
328+
#[cargo_test]
329+
fn cargo_install_with_toolchain_source_env() {
330+
cargo_install_with_toolchain_source(Some("env"), true);
331+
}
332+
333+
#[cargo_test]
334+
fn cargo_install_with_toolchain_source_path_override() {
335+
cargo_install_with_toolchain_source(Some("path-override"), true);
336+
}
337+
338+
#[cargo_test]
339+
fn cargo_install_with_toolchain_source_toolchain_file() {
340+
cargo_install_with_toolchain_source(Some("toolchain-file"), true);
341+
}
342+
343+
#[cargo_test]
344+
fn cargo_install_with_toolchain_source_invalid() {
345+
cargo_install_with_toolchain_source(Some("invalid"), false);
346+
}
347+
348+
fn cargo_install_with_toolchain_source(source: Option<&str>, should_warn: bool) {
349+
let mut builder = RustupEnvironmentBuilder::new();
350+
builder.call_cargo_under_test();
351+
builder.env("RUSTUP_TOOLCHAIN", "test-toolchain");
352+
if let Some(source) = source {
353+
builder.env("RUSTUP_TOOLCHAIN_SOURCE", source);
354+
};
315355
let RustupEnvironment {
316356
cargo_bin,
317357
rustup_home: _,
318358
cargo_toolchain_exe: _,
319-
} = RustupEnvironmentBuilder::new()
320-
.call_cargo_under_test()
321-
.env("RUSTUP_TOOLCHAIN_SOURCE", "env")
322-
.env("RUSTUP_TOOLCHAIN", "test-toolchain")
323-
.build();
359+
} = builder.build();
324360

325361
pkg("foo", "0.0.1");
326362

327363
let mut p = process(cargo_bin.join("cargo"));
328364
p.arg_line("install foo");
329-
execs()
330-
.with_process_builder(p)
331-
.with_stderr_data(str![[r#"
332-
`[..]/cargo[EXE]` proxy running
365+
let maybe_warning = if should_warn {
366+
format!(
367+
r#"[WARNING] using non-default toolchain `test-toolchain` overridden by {}
368+
|
369+
= [HELP] use `cargo +stable install` if you meant to use the stable toolchain.
370+
"#,
371+
source.unwrap()
372+
)
373+
} else {
374+
String::new()
375+
};
376+
let stderr = format!(
377+
r#"`[..]/cargo[EXE]` proxy running
333378
[UPDATING] `dummy-registry` index
334379
[DOWNLOADING] crates ...
335380
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
336381
[INSTALLING] foo v0.0.1
337-
[WARNING] using non-default toolchain `test-toolchain` overridden by env
338-
|
339-
= [HELP] use `cargo +stable install` if you meant to use the stable toolchain.
340-
[COMPILING] foo v0.0.1
382+
{maybe_warning}[COMPILING] foo v0.0.1
341383
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
342384
[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE]
343385
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
344386
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
345-
346-
"#]])
387+
"#
388+
);
389+
execs()
390+
.with_process_builder(p)
391+
.with_stderr_data(stderr)
347392
.run();
348393
assert_has_installed_exe(cargo_home(), "foo");
349394
}

0 commit comments

Comments
 (0)