Skip to content

Commit 1dd5aaa

Browse files
committed
Use CliTestContext directly in self_update_setup()
1 parent a90ce17 commit 1dd5aaa

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

src/test/mock/clitools.rs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -350,38 +350,37 @@ fn create_local_update_server(self_dist: &Path, exedir: &Path, version: &str) ->
350350
}
351351

352352
pub fn self_update_setup(f: &dyn Fn(&mut Config, &Path), version: &str) {
353-
test(Scenario::SimpleV2, &|config| {
354-
// Create a mock self-update server
353+
let mut cx = CliTestContext::from(Scenario::SimpleV2);
355354

356-
let self_dist_tmp = tempfile::Builder::new()
357-
.prefix("self_dist")
358-
.tempdir_in(&config.test_root_dir)
359-
.unwrap();
360-
let self_dist = self_dist_tmp.path();
361-
362-
let root_url = create_local_update_server(self_dist, &config.exedir, version);
363-
config.rustup_update_root = Some(root_url);
364-
365-
let trip = this_host_triple();
366-
let dist_dir = self_dist.join(format!("archive/{version}/{trip}"));
367-
let dist_exe = dist_dir.join(format!("rustup-init{EXE_SUFFIX}"));
368-
let dist_tmp = dist_dir.join("rustup-init-tmp");
369-
370-
// Modify the exe so it hashes different
371-
// 1) move out of the way the file
372-
fs::rename(&dist_exe, &dist_tmp).unwrap();
373-
// 2) copy it
374-
fs::copy(dist_tmp, &dist_exe).unwrap();
375-
// modify it
376-
let mut dest_file = fs::OpenOptions::new()
377-
.append(true)
378-
.create(true)
379-
.open(dist_exe)
380-
.unwrap();
381-
writeln!(dest_file).unwrap();
355+
// Create a mock self-update server
356+
let self_dist_tmp = tempfile::Builder::new()
357+
.prefix("self_dist")
358+
.tempdir_in(&cx.config.test_root_dir)
359+
.unwrap();
360+
let self_dist = self_dist_tmp.path();
382361

383-
f(config, self_dist);
384-
});
362+
let root_url = create_local_update_server(self_dist, &cx.config.exedir, version);
363+
cx.config.rustup_update_root = Some(root_url);
364+
365+
let trip = this_host_triple();
366+
let dist_dir = self_dist.join(format!("archive/{version}/{trip}"));
367+
let dist_exe = dist_dir.join(format!("rustup-init{EXE_SUFFIX}"));
368+
let dist_tmp = dist_dir.join("rustup-init-tmp");
369+
370+
// Modify the exe so it hashes different
371+
// 1) move out of the way the file
372+
fs::rename(&dist_exe, &dist_tmp).unwrap();
373+
// 2) copy it
374+
fs::copy(dist_tmp, &dist_exe).unwrap();
375+
// modify it
376+
let mut dest_file = fs::OpenOptions::new()
377+
.append(true)
378+
.create(true)
379+
.open(dist_exe)
380+
.unwrap();
381+
writeln!(dest_file).unwrap();
382+
383+
f(&mut cx.config, self_dist);
385384
}
386385

387386
pub fn with_update_server(config: &mut Config, version: &str, f: &dyn Fn(&mut Config)) {

0 commit comments

Comments
 (0)