Skip to content

Commit 5b36ca2

Browse files
authored
Merge pull request #3227 from rbtcollins/config-mutable
Config mutable
2 parents eef953c + 1d1c3f4 commit 5b36ca2

File tree

11 files changed

+58
-68
lines changed

11 files changed

+58
-68
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-exact.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fn remove_override_with_path() {
364364
.prefix("rustup-test")
365365
.tempdir()
366366
.unwrap();
367-
config.change_dir(dir.path(), || {
367+
config.change_dir(dir.path(), &|config| {
368368
config.expect_ok(&["rustup", "override", "add", "nightly"]);
369369
});
370370
config.expect_ok_ex(
@@ -395,7 +395,7 @@ fn remove_override_with_path_deleted() {
395395
.tempdir()
396396
.unwrap();
397397
let path = std::fs::canonicalize(dir.path()).unwrap();
398-
config.change_dir(&path, || {
398+
config.change_dir(&path, &|config| {
399399
config.expect_ok(&["rustup", "override", "add", "nightly"]);
400400
});
401401
path
@@ -429,7 +429,7 @@ fn remove_override_nonexistent() {
429429
.tempdir()
430430
.unwrap();
431431
let path = std::fs::canonicalize(dir.path()).unwrap();
432-
config.change_dir(&path, || {
432+
config.change_dir(&path, &|config| {
433433
config.expect_ok(&["rustup", "override", "add", "nightly"]);
434434
});
435435
path
@@ -483,7 +483,7 @@ fn list_overrides_with_nonexistent() {
483483
.prefix("rustup-test")
484484
.tempdir()
485485
.unwrap();
486-
config.change_dir(dir.path(), || {
486+
config.change_dir(dir.path(), &|config| {
487487
config.expect_ok(&["rustup", "override", "add", "nightly"]);
488488
});
489489
std::fs::canonicalize(dir.path()).unwrap()

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-rustup.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ macro_rules! for_host_and_home {
1818
};
1919
}
2020

21-
pub fn setup(f: &dyn Fn(&Config)) {
21+
pub fn setup(f: &dyn Fn(&mut Config)) {
2222
clitools::setup(Scenario::ArchivesV2, &|config| {
2323
f(config);
2424
});
@@ -851,7 +851,7 @@ fn show_toolchain_version_nested_file_override() {
851851
let subdir = cwd.join("foo");
852852

853853
fs::create_dir_all(&subdir).unwrap();
854-
config.change_dir(&subdir, &|| {
854+
config.change_dir(&subdir, &|config| {
855855
config.expect_ok_ex(
856856
&["rustup", "show"],
857857
&format!(
@@ -932,15 +932,16 @@ fn override_set_unset_with_path() {
932932
cwd_str = &cwd_str[4..];
933933
}
934934

935-
config.change_dir(&config.emptydir, &|| {
935+
let emptydir = tempfile::tempdir().unwrap();
936+
config.change_dir(emptydir.path(), &|config| {
936937
config.expect_ok(&["rustup", "override", "set", "nightly", "--path", cwd_str]);
937938
});
938939
config.expect_ok_ex(
939940
&["rustup", "override", "list"],
940941
&format!("{}\tnightly-{}\n", cwd_str, this_host_triple()),
941942
r"",
942943
);
943-
config.change_dir(&config.emptydir, &|| {
944+
config.change_dir(emptydir.path(), &|config| {
944945
config.expect_ok(&["rustup", "override", "unset", "--path", cwd_str]);
945946
});
946947
config.expect_ok_ex(&["rustup", "override", "list"], "no overrides\n", r"");
@@ -1417,7 +1418,7 @@ fn file_override_path_relative() {
14171418
// Change into an ephemeral dir so that we test that the path is relative to the override
14181419
let ephemeral = config.current_dir().join("ephemeral");
14191420
fs::create_dir_all(&ephemeral).unwrap();
1420-
config.change_dir(&ephemeral, || {
1421+
config.change_dir(&ephemeral, &|config| {
14211422
config.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-2");
14221423
});
14231424
});
@@ -1505,7 +1506,7 @@ fn file_override_subdir() {
15051506

15061507
let subdir = cwd.join("subdir");
15071508
fs::create_dir_all(&subdir).unwrap();
1508-
config.change_dir(&subdir, &|| {
1509+
config.change_dir(&subdir, &|config| {
15091510
config.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-2");
15101511
});
15111512
});
@@ -1708,7 +1709,7 @@ fn close_file_override_beats_far_directory_override() {
17081709
let toolchain_file = subdir.join("rust-toolchain");
17091710
raw::write_file(&toolchain_file, "nightly").unwrap();
17101711

1711-
config.change_dir(&subdir, &|| {
1712+
config.change_dir(&subdir, &|config| {
17121713
config.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-2");
17131714
});
17141715
});

tests/cli-self-upd.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ use crate::mock::dist::calc_hash;
2020

2121
const TEST_VERSION: &str = "1.1.1";
2222

23-
pub fn update_setup(f: &dyn Fn(&Config, &Path)) {
23+
pub fn update_setup(f: &dyn Fn(&mut Config, &Path)) {
2424
self_update_setup(f, TEST_VERSION)
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/cli-v1.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn remove_default_toolchain_autoinstalls() {
147147
fn remove_override_toolchain_err_handling() {
148148
setup(&|config| {
149149
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
150-
config.change_dir(tempdir.path(), &|| {
150+
config.change_dir(tempdir.path(), &|config| {
151151
config.expect_ok(&["rustup", "default", "nightly"]);
152152
config.expect_ok(&["rustup", "override", "add", "beta"]);
153153
config.expect_ok(&["rustup", "toolchain", "remove", "beta"]);
@@ -222,7 +222,7 @@ fn override_overrides_default() {
222222
setup(&|config| {
223223
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
224224
config.expect_ok(&["rustup", "default", "nightly"]);
225-
config.change_dir(tempdir.path(), &|| {
225+
config.change_dir(tempdir.path(), &|config| {
226226
config.expect_ok(&["rustup", "override", "add", "beta"]);
227227
config.expect_stdout_ok(&["rustc", "--version"], "hash-beta-1.2.0");
228228
});
@@ -236,19 +236,19 @@ fn multiple_overrides() {
236236
let tempdir2 = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
237237

238238
config.expect_ok(&["rustup", "default", "nightly"]);
239-
config.change_dir(tempdir1.path(), &|| {
239+
config.change_dir(tempdir1.path(), &|config| {
240240
config.expect_ok(&["rustup", "override", "add", "beta"]);
241241
});
242-
config.change_dir(tempdir2.path(), &|| {
242+
config.change_dir(tempdir2.path(), &|config| {
243243
config.expect_ok(&["rustup", "override", "add", "stable"]);
244244
});
245245

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

248-
config.change_dir(tempdir1.path(), &|| {
248+
config.change_dir(tempdir1.path(), &|config| {
249249
config.expect_stdout_ok(&["rustc", "--version"], "hash-beta-1.2.0");
250250
});
251-
config.change_dir(tempdir2.path(), &|| {
251+
config.change_dir(tempdir2.path(), &|config| {
252252
config.expect_stdout_ok(&["rustc", "--version"], "hash-stable-1.1.0");
253253
});
254254
});
@@ -258,7 +258,7 @@ fn multiple_overrides() {
258258
fn change_override() {
259259
setup(&|config| {
260260
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
261-
config.change_dir(tempdir.path(), &|| {
261+
config.change_dir(tempdir.path(), &|config| {
262262
config.expect_ok(&["rustup", "override", "add", "nightly"]);
263263
config.expect_ok(&["rustup", "override", "add", "beta"]);
264264
config.expect_stdout_ok(&["rustc", "--version"], "hash-beta-1.2.0");
@@ -270,7 +270,7 @@ fn change_override() {
270270
fn remove_override_no_default() {
271271
setup(&|config| {
272272
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
273-
config.change_dir(tempdir.path(), &|| {
273+
config.change_dir(tempdir.path(), &|config| {
274274
config.expect_ok(&["rustup", "override", "add", "nightly"]);
275275
config.expect_ok(&["rustup", "override", "remove"]);
276276
config.expect_err(
@@ -285,7 +285,7 @@ fn remove_override_no_default() {
285285
fn remove_override_with_default() {
286286
setup(&|config| {
287287
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
288-
config.change_dir(tempdir.path(), &|| {
288+
config.change_dir(tempdir.path(), &|config| {
289289
config.expect_ok(&["rustup", "default", "nightly"]);
290290
config.expect_ok(&["rustup", "override", "add", "beta"]);
291291
config.expect_ok(&["rustup", "override", "remove"]);
@@ -300,18 +300,18 @@ fn remove_override_with_multiple_overrides() {
300300
let tempdir1 = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
301301
let tempdir2 = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
302302
config.expect_ok(&["rustup", "default", "nightly"]);
303-
config.change_dir(tempdir1.path(), &|| {
303+
config.change_dir(tempdir1.path(), &|config| {
304304
config.expect_ok(&["rustup", "override", "add", "beta"]);
305305
});
306-
config.change_dir(tempdir2.path(), &|| {
306+
config.change_dir(tempdir2.path(), &|config| {
307307
config.expect_ok(&["rustup", "override", "add", "stable"]);
308308
});
309309
config.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-2");
310-
config.change_dir(tempdir1.path(), &|| {
310+
config.change_dir(tempdir1.path(), &|config| {
311311
config.expect_ok(&["rustup", "override", "remove"]);
312312
config.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-2");
313313
});
314-
config.change_dir(tempdir2.path(), &|| {
314+
config.change_dir(tempdir2.path(), &|config| {
315315
config.expect_stdout_ok(&["rustc", "--version"], "hash-stable-1.1.0");
316316
});
317317
});

0 commit comments

Comments
 (0)