Skip to content

Commit

Permalink
Add tests for rust-toolchain.toml files
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-opp committed Feb 7, 2021
1 parent 133dc0b commit e729cf5
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2065,3 +2065,53 @@ warning: If you meant to build software to target that platform, perhaps try `ru
);
});
}

/// Checks that `rust-toolchain.toml` files are considered
#[test]
fn rust_toolchain_toml() {
setup(&|config| {
let cwd = config.current_dir();
let toolchain_file = cwd.join("rust-toolchain.toml");
raw::write_file(&toolchain_file, "[toolchain]\nchannel = \"nightly\"").unwrap();

expect_stdout_ok(config, &["rustc", "--version"], "hash-nightly-2");
});
}

/// Ensures that `rust-toolchain.toml` files (with `.toml` extension) only allow TOML contents
#[test]
fn only_toml_in_rust_toolchain_toml() {
setup(&|config| {
let cwd = config.current_dir();
let toolchain_file = cwd.join("rust-toolchain.toml");
raw::write_file(&toolchain_file, "nightly").unwrap();

expect_err(
config,
&["rustc", "--version"],
"error parsing override file",
);
});
}

/// Checks that a warning occurs if both `rust-toolchain` and `rust-toolchain.toml` files exist
#[test]
fn warn_on_duplicate_rust_toolchain_file() {
setup(&|config| {
let cwd = config.current_dir();
let toolchain_file_1 = cwd.join("rust-toolchain");
raw::write_file(&toolchain_file_1, "stable").unwrap();
let toolchain_file_2 = cwd.join("rust-toolchain.toml");
raw::write_file(&toolchain_file_2, "[toolchain]").unwrap();

expect_stderr_ok(
config,
&["rustc", "--version"],
&format!(
"warning: both `{0}` and `{1}` exist. Using `{0}`",
toolchain_file_1.display(),
toolchain_file_2.display(),
),
);
});
}

0 comments on commit e729cf5

Please sign in to comment.