Skip to content

Commit

Permalink
Add test to ensure resolution of #3483
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Oct 10, 2023
1 parent 2946b70 commit d8f5c14
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/test/mock/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,17 @@ impl Config {
}
}

#[track_caller]
pub fn expect_stdout_ok_with_env(&self, args: &[&str], env: &[(&str, &str)], expected: &str) {
let out = self.run(args[0], &args[1..], env);
if !out.ok || !out.stdout.contains(expected) {
print_command(args, &out);
println!("expected.ok: true");
print_indented("expected.stdout.contains", expected);
panic!();
}
}

#[track_caller]
pub fn expect_not_stdout_ok(&self, args: &[&str], expected: &str) {
let out = self.run(args[0], &args[1..], &[]);
Expand Down
121 changes: 121 additions & 0 deletions tests/suite/cli_rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2376,6 +2376,127 @@ fn only_toml_in_rust_toolchain_toml() {
});
}

/// Checks that `rust-toolchain.toml` configs can be overridden by `rustup override set`.
/// See: <https://github.com/rust-lang/rustup/issues/3483>
#[test]
fn rust_toolchain_toml_with_rustup_override() {
test(&|config| {
config.with_scenario(Scenario::SimpleV2, &|config| {
config.expect_err(
&["rustc", "--version"],
"rustup could not choose a version of rustc to run",
);

config.expect_ok(&["rustup", "override", "set", "beta"]);

let cwd = config.current_dir();
let toolchain_file = cwd.join("rust-toolchain.toml");
raw::write_file(
&toolchain_file,
r#"
[toolchain]
channel = "nightly"
components = [ "rls" ]
"#,
)
.unwrap();

let beta = "hash-beta-1.2.0";
config.expect_stdout_ok(&["rustc", "--version"], beta);
config.expect_stdout_ok(&["rls", "--version"], beta);
})
});
}

/// Checks that `rust-toolchain.toml` configs can override `rustup override set` at different directories.
/// See: <https://github.com/rust-lang/rustup/issues/3483>
#[test]
fn rust_toolchain_toml_with_rustup_override_parent_dir() {
test(&|config| {
config.with_scenario(Scenario::SimpleV2, &|config| {
config.expect_err(
&["rustc", "--version"],
"rustup could not choose a version of rustc to run",
);

// "." -> nightly
config.expect_ok(&["rustup", "override", "set", "nightly"]);

// "./inner" -> beta + rls
let inner = &config.current_dir().join("inner");
std::fs::create_dir(inner).unwrap();
config.change_dir(inner, &|config| {
let cwd = config.current_dir();
let toolchain_file = cwd.join("rust-toolchain.toml");
raw::write_file(
&toolchain_file,
r#"
[toolchain]
channel = "beta"
components = [ "rls" ]
"#,
)
.unwrap();

let beta = "hash-beta-1.2.0";
config.expect_stdout_ok(&["rustc", "--version"], beta);
config.expect_stdout_ok(&["rls", "--version"], beta);
});

// "./inner" -> beta + rls
// "./inner/inner" -> (beta + rls) | stable = stable + rls
let inner2 = &inner.join("inner");
std::fs::create_dir(inner2).unwrap();
config.change_dir(inner2, &|config| {
config.expect_ok(&["rustup", "override", "set", "stable"]);

let stable = "hash-stable-1.1.0";
config.expect_stdout_ok(&["rustc", "--version"], stable);
config.expect_stdout_ok(&["rls", "--version"], stable);
});

// "." -> nightly, no rls
let nightly = "hash-nightly-2";
config.expect_stdout_ok(&["rustc", "--version"], nightly);
config.expect_component_not_executable("rls");
})
});
}

/// Checks that `rust-toolchain.toml` configs can be overridden by `RUSTUP_TOOLCHAIN`.
/// See: <https://github.com/rust-lang/rustup/issues/3483>
#[test]
fn rust_toolchain_toml_with_rustup_toolchain() {
test(&|config| {
config.with_scenario(Scenario::SimpleV2, &|config| {
config.expect_err(
&["rustc", "--version"],
"rustup could not choose a version of rustc to run",
);

let cwd = config.current_dir();
let toolchain_file = cwd.join("rust-toolchain.toml");
raw::write_file(
&toolchain_file,
r#"
[toolchain]
channel = "nightly"
components = [ "rls" ]
"#,
)
.unwrap();

let env = &[("RUSTUP_TOOLCHAIN", "beta")];
let beta = "hash-beta-1.2.0";
config.expect_stdout_ok_with_env(&["rustc", "--version"], env, beta);
config.expect_stdout_ok_with_env(&["rls", "--version"], env, beta);

// At this point, `nightly` is still NOT installed.
config.expect_not_stderr_ok(&["rustup", "toolchain", "list"], "nightly");
})
});
}

/// Checks that a warning occurs if both `rust-toolchain` and `rust-toolchain.toml` files exist
#[test]
fn warn_on_duplicate_rust_toolchain_file() {
Expand Down

0 comments on commit d8f5c14

Please sign in to comment.