Skip to content

Commit ba575f2

Browse files
committed
Implement tests for 11036 cargo changes
1 parent a761572 commit ba575f2

File tree

1 file changed

+172
-2
lines changed

1 file changed

+172
-2
lines changed

tests/testsuite/rustup.rs

Lines changed: 172 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ use std::path::{Path, PathBuf};
1010

1111
use crate::prelude::*;
1212
use crate::utils::cargo_process;
13-
use cargo_test_support::paths::{home, root};
14-
use cargo_test_support::{process, project, str};
13+
use cargo_test_support::install::assert_has_installed_exe;
14+
use cargo_test_support::paths::{cargo_home, home, root};
15+
use cargo_test_support::registry::Package;
16+
use cargo_test_support::{execs, process, project, str};
1517

1618
/// Helper to generate an executable.
1719
fn make_exe(dest: &Path, name: &str, contents: &str, env: &[(&str, PathBuf)]) -> PathBuf {
@@ -315,3 +317,171 @@ custom toolchain rustc running
315317
"#]])
316318
.run();
317319
}
320+
321+
/// Performs a `cargo install` with a non-default toolchain in a simulated
322+
/// rustup environment. The purpose is to verify the warning that is emitted.
323+
#[cargo_test]
324+
fn cargo_install_with_toolchain_source_unset() {
325+
cargo_install_with_toolchain_source(
326+
None,
327+
str![[r#"
328+
[..]/cargo[EXE]` proxy running
329+
[UPDATING] `dummy-registry` index
330+
[DOWNLOADING] crates ...
331+
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
332+
[INSTALLING] foo v0.0.1
333+
[COMPILING] foo v0.0.1
334+
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
335+
[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE]
336+
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
337+
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
338+
339+
"#]],
340+
);
341+
}
342+
343+
#[cargo_test]
344+
fn cargo_install_with_toolchain_source_default() {
345+
cargo_install_with_toolchain_source(
346+
Some("default"),
347+
str![[r#"
348+
[..]/cargo[EXE]` proxy running
349+
[UPDATING] `dummy-registry` index
350+
[DOWNLOADING] crates ...
351+
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
352+
[INSTALLING] foo v0.0.1
353+
[COMPILING] foo v0.0.1
354+
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
355+
[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE]
356+
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
357+
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
358+
359+
"#]],
360+
);
361+
}
362+
363+
#[cargo_test]
364+
fn cargo_install_with_toolchain_source_cli() {
365+
cargo_install_with_toolchain_source(
366+
Some("cli"),
367+
str![[r#"
368+
[..]/cargo[EXE]` proxy running
369+
[UPDATING] `dummy-registry` index
370+
[DOWNLOADING] crates ...
371+
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
372+
[INSTALLING] foo v0.0.1
373+
[COMPILING] foo v0.0.1
374+
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
375+
[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE]
376+
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
377+
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
378+
379+
"#]],
380+
);
381+
}
382+
383+
#[cargo_test]
384+
fn cargo_install_with_toolchain_source_env() {
385+
cargo_install_with_toolchain_source(
386+
Some("env"),
387+
str![[r#"
388+
[..]/cargo[EXE]` proxy running
389+
[UPDATING] `dummy-registry` index
390+
[DOWNLOADING] crates ...
391+
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
392+
[INSTALLING] foo v0.0.1
393+
[COMPILING] foo v0.0.1
394+
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
395+
[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE]
396+
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
397+
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
398+
399+
"#]],
400+
);
401+
}
402+
403+
#[cargo_test]
404+
fn cargo_install_with_toolchain_source_path_override() {
405+
cargo_install_with_toolchain_source(
406+
Some("path-override"),
407+
str![[r#"
408+
[..]/cargo[EXE]` proxy running
409+
[UPDATING] `dummy-registry` index
410+
[DOWNLOADING] crates ...
411+
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
412+
[INSTALLING] foo v0.0.1
413+
[COMPILING] foo v0.0.1
414+
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
415+
[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE]
416+
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
417+
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
418+
419+
"#]],
420+
);
421+
}
422+
423+
#[cargo_test]
424+
fn cargo_install_with_toolchain_source_toolchain_file() {
425+
cargo_install_with_toolchain_source(
426+
Some("toolchain-file"),
427+
str![[r#"
428+
[..]/cargo[EXE]` proxy running
429+
[UPDATING] `dummy-registry` index
430+
[DOWNLOADING] crates ...
431+
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
432+
[INSTALLING] foo v0.0.1
433+
[COMPILING] foo v0.0.1
434+
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
435+
[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE]
436+
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
437+
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
438+
439+
"#]],
440+
);
441+
}
442+
443+
#[cargo_test]
444+
fn cargo_install_with_toolchain_source_unrecognized() {
445+
cargo_install_with_toolchain_source(
446+
Some("unrecognized source"),
447+
str![[r#"
448+
[..]/cargo[EXE]` proxy running
449+
[UPDATING] `dummy-registry` index
450+
[DOWNLOADING] crates ...
451+
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`)
452+
[INSTALLING] foo v0.0.1
453+
[COMPILING] foo v0.0.1
454+
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
455+
[INSTALLING] [ROOT]/home/.cargo/bin/foo[EXE]
456+
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
457+
[WARNING] be sure to add `[ROOT]/home/.cargo/bin` to your PATH to be able to run the installed binaries
458+
459+
"#]],
460+
);
461+
}
462+
463+
fn cargo_install_with_toolchain_source(source: Option<&str>, stderr: impl snapbox::IntoData) {
464+
let mut builder = RustupEnvironmentBuilder::new();
465+
builder.call_cargo_under_test();
466+
builder.env("RUSTUP_TOOLCHAIN", "test-toolchain");
467+
if let Some(source) = source {
468+
builder.env("RUSTUP_TOOLCHAIN_SOURCE", source);
469+
};
470+
let RustupEnvironment {
471+
cargo_bin,
472+
rustup_home: _,
473+
cargo_toolchain_exe: _,
474+
} = builder.build();
475+
476+
Package::new("foo", "0.0.1")
477+
.file("src/main.rs", "fn main() {{}}")
478+
.publish();
479+
480+
let mut p = process(cargo_bin.join("cargo"));
481+
p.arg_line("install foo");
482+
execs()
483+
.with_process_builder(p)
484+
.with_stderr_data(stderr)
485+
.run();
486+
assert_has_installed_exe(cargo_home(), "foo");
487+
}

0 commit comments

Comments
 (0)