Skip to content

Commit 15157b7

Browse files
committed
Test optimisation: cli-self-upd
Running more tests in parallel permits faster test execution on multi-core machines, shaving 2m off the test suite for cli-self-upd for me.
1 parent 17904c1 commit 15157b7

File tree

1 file changed

+98
-70
lines changed

1 file changed

+98
-70
lines changed

tests/cli-self-upd.rs

Lines changed: 98 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,31 @@ pub fn update_setup(f: &dyn Fn(&Config, &Path)) {
7070
});
7171
}
7272

73+
/// Empty dist server, rustup installed with no toolchain
74+
fn setup_empty_installed(f: &dyn Fn(&Config)) {
75+
clitools::setup(Scenario::Empty, &|config| {
76+
expect_ok(
77+
config,
78+
&[
79+
"rustup-init",
80+
"-y",
81+
"--no-modify-path",
82+
"--default-toolchain",
83+
"none",
84+
],
85+
);
86+
f(config);
87+
})
88+
}
89+
90+
/// SimpleV3 dist server, rustup installed with default toolchain
91+
fn setup_installed(f: &dyn Fn(&Config)) {
92+
clitools::setup(Scenario::SimpleV2, &|config| {
93+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
94+
f(config);
95+
})
96+
}
97+
7398
fn output_release_file(dist_dir: &Path, schema: &str, version: &str) {
7499
let contents = format!(
75100
r#"
@@ -179,17 +204,7 @@ fn install_creates_cargo_home() {
179204
/// Functional test needed here - we need to do the full dance where we start
180205
/// with rustup.exe and end up deleting that exe itself.
181206
fn uninstall_deletes_bins() {
182-
clitools::setup(Scenario::Empty, &|config| {
183-
expect_ok(
184-
config,
185-
&[
186-
"rustup-init",
187-
"-y",
188-
"--no-modify-path",
189-
"--default-toolchain",
190-
"none",
191-
],
192-
);
207+
setup_empty_installed(&|config| {
193208
// no-modify-path isn't needed here, as the test-dir-path isn't present
194209
// in the registry, so the no-change code path will be triggered.
195210
expect_ok(config, &["rustup", "self", "uninstall", "-y"]);
@@ -212,8 +227,7 @@ fn uninstall_deletes_bins() {
212227

213228
#[test]
214229
fn uninstall_works_if_some_bins_dont_exist() {
215-
setup(&|config| {
216-
expect_ok(config, &["rustup-init", "-y"]);
230+
setup_empty_installed(&|config| {
217231
let rustup = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX));
218232
let rustc = config.cargodir.join(&format!("bin/rustc{}", EXE_SUFFIX));
219233
let rustdoc = config.cargodir.join(&format!("bin/rustdoc{}", EXE_SUFFIX));
@@ -239,36 +253,31 @@ fn uninstall_works_if_some_bins_dont_exist() {
239253

240254
#[test]
241255
fn uninstall_deletes_rustup_home() {
242-
setup(&|config| {
243-
expect_ok(config, &["rustup-init", "-y"]);
244-
expect_ok(config, &["rustup", "default", "nightly"]);
256+
setup_empty_installed(&|config| {
245257
expect_ok(config, &["rustup", "self", "uninstall", "-y"]);
246258
assert!(!config.rustupdir.has("."));
247259
});
248260
}
249261

250262
#[test]
251263
fn uninstall_works_if_rustup_home_doesnt_exist() {
252-
setup(&|config| {
253-
expect_ok(config, &["rustup-init", "-y"]);
264+
setup_empty_installed(&|config| {
254265
config.rustupdir.remove().unwrap();
255266
expect_ok(config, &["rustup", "self", "uninstall", "-y"]);
256267
});
257268
}
258269

259270
#[test]
260271
fn uninstall_deletes_cargo_home() {
261-
setup(&|config| {
262-
expect_ok(config, &["rustup-init", "-y"]);
272+
setup_empty_installed(&|config| {
263273
expect_ok(config, &["rustup", "self", "uninstall", "-y"]);
264274
assert!(!config.cargodir.exists());
265275
});
266276
}
267277

268278
#[test]
269279
fn uninstall_fails_if_not_installed() {
270-
setup(&|config| {
271-
expect_ok(config, &["rustup-init", "-y"]);
280+
setup_empty_installed(&|config| {
272281
let rustup = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX));
273282
fs::remove_file(&rustup).unwrap();
274283
expect_err(
@@ -285,8 +294,7 @@ fn uninstall_fails_if_not_installed() {
285294
#[test]
286295
#[cfg_attr(target_os = "macos", ignore)] // FIXME #1515
287296
fn uninstall_self_delete_works() {
288-
setup(&|config| {
289-
expect_ok(config, &["rustup-init", "-y"]);
297+
setup_empty_installed(&|config| {
290298
let rustup = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX));
291299
let mut cmd = Command::new(rustup.clone());
292300
cmd.args(&["self", "uninstall", "-y"]);
@@ -321,8 +329,7 @@ fn uninstall_doesnt_leave_gc_file() {
321329
use std::thread;
322330
use std::time::Duration;
323331

324-
setup(&|config| {
325-
expect_ok(config, &["rustup-init", "-y"]);
332+
setup_empty_installed(&|config| {
326333
expect_ok(config, &["rustup", "self", "uninstall", "-y"]);
327334

328335
// The gc removal happens after rustup terminates. Give it a moment.
@@ -622,92 +629,115 @@ fn rustup_still_works_after_update() {
622629
});
623630
}
624631

625-
// There's a race condition between the updater replacing
626-
// the rustup binary and tool hardlinks and subsequent
627-
// invocations of rustup and rustc (on windows).
628-
#[test]
629-
#[ignore]
630-
fn update_stress_test() {}
631-
632632
// The installer used to be called rustup-setup. For compatibility it
633633
// still needs to work in that mode.
634634
#[test]
635-
#[cfg(not(windows))]
636635
fn as_rustup_setup() {
637-
update_setup(&|config, _| {
636+
clitools::setup(Scenario::Empty, &|config| {
638637
let init = config.exedir.join(format!("rustup-init{}", EXE_SUFFIX));
639638
let setup = config.exedir.join(format!("rustup-setup{}", EXE_SUFFIX));
640639
fs::copy(&init, &setup).unwrap();
641-
expect_ok(config, &["rustup-setup", "-y"]);
640+
expect_ok(
641+
config,
642+
&[
643+
"rustup-setup",
644+
"-y",
645+
"--no-modify-path",
646+
"--default-toolchain",
647+
"none",
648+
],
649+
);
642650
});
643651
}
644652

645653
#[test]
646654
fn reinstall_exact() {
647-
setup(&|config| {
648-
expect_ok(config, &["rustup-init", "-y"]);
655+
setup_empty_installed(&|config| {
649656
expect_stderr_ok(
650657
config,
651-
&["rustup-init", "-y", "--no-update-default-toolchain"],
658+
&[
659+
"rustup-init",
660+
"-y",
661+
"--no-update-default-toolchain",
662+
"--no-modify-path",
663+
],
652664
r"info: updating existing rustup installation - leaving toolchains alone",
653665
);
654666
});
655667
}
656668

657669
#[test]
658670
fn reinstall_specifying_toolchain() {
659-
setup(&|config| {
660-
expect_ok(config, &["rustup-init", "-y"]);
671+
setup_installed(&|config| {
661672
expect_stdout_ok(
662673
config,
663-
&["rustup-init", "-y", "--default-toolchain=stable"],
674+
&[
675+
"rustup-init",
676+
"-y",
677+
"--default-toolchain=stable",
678+
"--no-modify-path",
679+
],
664680
for_host!(r"stable-{0} unchanged - 1.1.0"),
665681
);
666682
});
667683
}
668684

669685
#[test]
670686
fn reinstall_specifying_component() {
671-
setup(&|config| {
672-
expect_ok(config, &["rustup-init", "-y", "--component=rls"]);
687+
setup_installed(&|config| {
688+
expect_ok(config, &["rustup", "component", "add", "rls"]);
673689
expect_stdout_ok(
674690
config,
675-
&["rustup-init", "-y", "--default-toolchain=stable"],
691+
&[
692+
"rustup-init",
693+
"-y",
694+
"--default-toolchain=stable",
695+
"--no-modify-path",
696+
],
676697
for_host!(r"stable-{0} unchanged - 1.1.0"),
677698
);
678699
});
679700
}
680701

681702
#[test]
682703
fn reinstall_specifying_different_toolchain() {
683-
setup(&|config| {
684-
expect_ok(config, &["rustup-init", "-y"]);
704+
clitools::setup(Scenario::SimpleV2, &|config| {
685705
expect_stderr_ok(
686706
config,
687-
&["rustup-init", "-y", "--default-toolchain=nightly"],
707+
&[
708+
"rustup-init",
709+
"-y",
710+
"--default-toolchain=nightly",
711+
"--no-modify-path",
712+
],
688713
for_host!(r"info: default toolchain set to 'nightly-{0}'"),
689714
);
690715
});
691716
}
692717

693718
#[test]
694719
fn install_sets_up_stable_unless_a_different_default_is_requested() {
695-
setup(&|config| {
720+
clitools::setup(Scenario::SimpleV2, &|config| {
696721
expect_ok(
697722
config,
698-
&["rustup-init", "-y", "--default-toolchain", "nightly"],
723+
&[
724+
"rustup-init",
725+
"-y",
726+
"--default-toolchain",
727+
"nightly",
728+
"--no-modify-path",
729+
],
699730
);
700731
expect_stdout_ok(config, &["rustc", "--version"], "hash-nightly-2");
701732
});
702733
}
703734

704735
#[test]
705736
fn install_sets_up_stable_unless_there_is_already_a_default() {
706-
setup(&|config| {
707-
expect_ok(config, &["rustup-init", "-y"]);
737+
setup_installed(&|config| {
708738
expect_ok(config, &["rustup", "default", "nightly"]);
709739
expect_ok(config, &["rustup", "toolchain", "remove", "stable"]);
710-
expect_ok(config, &["rustup-init", "-y"]);
740+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
711741
expect_stdout_ok(config, &["rustc", "--version"], "hash-nightly-2");
712742
expect_err(
713743
config,
@@ -719,10 +749,10 @@ fn install_sets_up_stable_unless_there_is_already_a_default() {
719749

720750
#[test]
721751
fn readline_no_stdin() {
722-
setup(&|config| {
752+
clitools::setup(Scenario::SimpleV2, &|config| {
723753
expect_err(
724754
config,
725-
&["rustup-init"],
755+
&["rustup-init", "--no-modify-path"],
726756
"unable to read from stdin for confirmation",
727757
);
728758
});
@@ -732,43 +762,40 @@ fn readline_no_stdin() {
732762
fn rustup_init_works_with_weird_names() {
733763
// Browsers often rename bins to e.g. rustup-init(2).exe.
734764

735-
setup(&|config| {
765+
clitools::setup(Scenario::SimpleV2, &|config| {
736766
let old = config.exedir.join(&format!("rustup-init{}", EXE_SUFFIX));
737767
let new = config.exedir.join(&format!("rustup-init(2){}", EXE_SUFFIX));
738768
utils::rename_file("test", &old, &new, &|_: Notification<'_>| {}).unwrap();
739-
expect_ok(config, &["rustup-init(2)", "-y"]);
769+
expect_ok(config, &["rustup-init(2)", "-y", "--no-modify-path"]);
740770
let rustup = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX));
741771
assert!(rustup.exists());
742772
});
743773
}
744774

745-
#[test]
746-
#[ignore] // untestable
747-
fn install_but_rustup_is_installed() {}
748-
749-
#[test]
750-
#[ignore] // untestable
751-
fn install_but_rustc_is_installed() {}
752-
753775
#[test]
754776
fn install_but_rustup_sh_is_installed() {
755-
setup(&|config| {
777+
clitools::setup(Scenario::Empty, &|config| {
756778
let rustup_dir = config.homedir.join(".rustup");
757779
fs::create_dir_all(&rustup_dir).unwrap();
758780
let version_file = rustup_dir.join("rustup-version");
759781
raw::write_file(&version_file, "").unwrap();
760782
expect_stderr_ok(
761783
config,
762-
&["rustup-init", "-y"],
784+
&[
785+
"rustup-init",
786+
"-y",
787+
"--default-toolchain",
788+
"none",
789+
"--no-modify-path",
790+
],
763791
"cannot install while rustup.sh is installed",
764792
);
765793
});
766794
}
767795

768796
#[test]
769797
fn rls_proxy_set_up_after_install() {
770-
setup(&|config| {
771-
expect_ok(config, &["rustup-init", "-y"]);
798+
setup_installed(&|config| {
772799
expect_err(
773800
config,
774801
&["rls", "--version"],
@@ -852,7 +879,7 @@ fn update_installs_clippy_cargo_and() {
852879

853880
#[test]
854881
fn install_with_components_and_targets() {
855-
setup(&|config| {
882+
clitools::setup(Scenario::SimpleV2, &|config| {
856883
expect_ok(
857884
config,
858885
&[
@@ -864,6 +891,7 @@ fn install_with_components_and_targets() {
864891
"rls",
865892
"-t",
866893
clitools::CROSS_ARCH1,
894+
"--no-modify-path",
867895
],
868896
);
869897
expect_stdout_ok(

0 commit comments

Comments
 (0)