Skip to content

Commit 1d1c3f4

Browse files
committed
expect_ok takes mutable Config
This is sufficient to test immutable dist dirs. Immutable dist dirs require the ability to run commands with a different config. One nice way to express that requires a mutable borrow or unnecessary interior mutability; this patch builds up sufficient mut borrow capability that we can avoid a borrow checker failure by having just the one mutable borrow.
1 parent f1dd67d commit 1d1c3f4

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

src/cli/self_update/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn restore_path(p: Option<RegValue>) {
3636
}
3737

3838
/// Support testing of code that mutates global path state
39-
pub fn with_saved_path(f: &dyn Fn()) {
39+
pub fn with_saved_path(f: &mut dyn FnMut()) {
4040
// Lock protects concurrent mutation of registry
4141
lazy_static! {
4242
static ref LOCK: Mutex<()> = Mutex::new(());

src/cli/self_update/windows.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ mod tests {
745745
fn windows_path_regkey_type() {
746746
// per issue #261, setting PATH should use REG_EXPAND_SZ.
747747
let tp = Box::new(currentprocess::TestProcess::default());
748-
with_saved_path(&|| {
748+
with_saved_path(&mut || {
749749
currentprocess::with(tp.clone(), || {
750750
let root = RegKey::predef(HKEY_CURRENT_USER);
751751
let environment = root
@@ -775,7 +775,7 @@ mod tests {
775775
// during uninstall the PATH key may end up empty; if so we should
776776
// delete it.
777777
let tp = Box::new(currentprocess::TestProcess::default());
778-
with_saved_path(&|| {
778+
with_saved_path(&mut || {
779779
currentprocess::with(tp.clone(), || {
780780
let root = RegKey::predef(HKEY_CURRENT_USER);
781781
let environment = root
@@ -816,7 +816,7 @@ mod tests {
816816
.collect(),
817817
..Default::default()
818818
});
819-
with_saved_path(&|| {
819+
with_saved_path(&mut || {
820820
currentprocess::with(tp.clone(), || {
821821
let root = RegKey::predef(HKEY_CURRENT_USER);
822822
let environment = root
@@ -845,7 +845,7 @@ mod tests {
845845
fn windows_treat_missing_path_as_empty() {
846846
// during install the PATH key may be missing; treat it as empty
847847
let tp = Box::new(currentprocess::TestProcess::default());
848-
with_saved_path(&|| {
848+
with_saved_path(&mut || {
849849
currentprocess::with(tp.clone(), || {
850850
let root = RegKey::predef(HKEY_CURRENT_USER);
851851
let environment = root

src/env_var.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ mod tests {
5656
vars,
5757
..Default::default()
5858
});
59-
with_saved_path(&|| {
59+
with_saved_path(&mut || {
6060
currentprocess::with(tp.clone(), || {
6161
let mut path_entries = vec![];
6262
let mut cmd = Command::new("test");

tests/cli-inst-interactive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn run_input_with_env(
5353
#[test]
5454
fn update() {
5555
clitools::setup(Scenario::SimpleV2, &|config| {
56-
with_saved_path(&|| {
56+
with_saved_path(&mut || {
5757
run_input(config, &["rustup-init"], "\n\n");
5858
let out = run_input(config, &["rustup-init"], "\n\n");
5959
assert!(out.ok, "stdout:\n{}\nstderr:\n{}", out.stdout, out.stderr);
@@ -116,7 +116,7 @@ Rust is installed now. Great!
116116
#[test]
117117
fn smoke_case_install_with_path_install() {
118118
clitools::setup(Scenario::SimpleV2, &|config| {
119-
with_saved_path(&|| {
119+
with_saved_path(&mut || {
120120
let out = run_input(config, &["rustup-init"], "\n\n");
121121
assert!(out.ok);
122122
assert!(!out

tests/cli-paths.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ mod windows {
360360
/// Smoke test for end-to-end code connectivity of the installer path mgmt on windows.
361361
fn install_uninstall_affect_path() {
362362
clitools::setup(Scenario::Empty, &|config| {
363-
with_saved_path(&|| {
363+
with_saved_path(&mut || {
364364
let path = format!("{:?}", config.cargodir.join("bin").to_string_lossy());
365365

366366
config.expect_ok(&INIT_NONE);
@@ -390,7 +390,7 @@ mod windows {
390390
use winreg::{RegKey, RegValue};
391391

392392
clitools::setup(Scenario::Empty, &|config| {
393-
with_saved_path(&|| {
393+
with_saved_path(&mut || {
394394
// Set up a non unicode PATH
395395
let reg_value = RegValue {
396396
bytes: vec![

tests/cli-self-upd.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn update_setup(f: &dyn Fn(&mut Config, &Path)) {
2525
}
2626

2727
/// Empty dist server, rustup installed with no toolchain
28-
fn setup_empty_installed(f: &dyn Fn(&Config)) {
28+
fn setup_empty_installed(f: &dyn Fn(&mut Config)) {
2929
clitools::setup(Scenario::Empty, &|config| {
3030
config.expect_ok(&[
3131
"rustup-init",
@@ -39,7 +39,7 @@ fn setup_empty_installed(f: &dyn Fn(&Config)) {
3939
}
4040

4141
/// SimpleV3 dist server, rustup installed with default toolchain
42-
fn setup_installed(f: &dyn Fn(&Config)) {
42+
fn setup_installed(f: &dyn Fn(&mut Config)) {
4343
clitools::setup(Scenario::SimpleV2, &|config| {
4444
config.expect_ok(&["rustup-init", "-y", "--no-modify-path"]);
4545
f(config);
@@ -52,7 +52,7 @@ fn setup_installed(f: &dyn Fn(&Config)) {
5252
/// status of the proxies.
5353
fn install_bins_to_cargo_home() {
5454
clitools::setup(Scenario::SimpleV2, &|config| {
55-
with_saved_path(&|| {
55+
with_saved_path(&mut || {
5656
config.expect_ok_contains(
5757
&["rustup-init", "-y"],
5858
for_host!(
@@ -101,7 +101,7 @@ info: default toolchain set to 'stable-{0}'
101101
#[test]
102102
fn install_twice() {
103103
clitools::setup(Scenario::SimpleV2, &|config| {
104-
with_saved_path(&|| {
104+
with_saved_path(&mut || {
105105
config.expect_ok(&["rustup-init", "-y"]);
106106
config.expect_ok(&["rustup-init", "-y"]);
107107
let rustup = config.cargodir.join(format!("bin/rustup{EXE_SUFFIX}"));

tests/mock/clitools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl Config {
329329
}
330330
}
331331

332-
pub fn expect_ok(&self, args: &[&str]) {
332+
pub fn expect_ok(&mut self, args: &[&str]) {
333333
let out = self.run(args[0], &args[1..], &[]);
334334
if !out.ok {
335335
print_command(args, &out);

0 commit comments

Comments
 (0)