Skip to content

Commit dcf0f9d

Browse files
committed
tests
This adds a new test and removes test `update_removes_components_that_dont_exist` Historically, this test was added before the check that aborts update on missing components (which is tested by the new test in the previous commit, as well as elsewhere), so I think this test was only testing a bug. Note that the new behaviour is the same as the ancient behviour when the user uses `--force`
1 parent 5544880 commit dcf0f9d

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/rustup-dist/tests/dist.rs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,27 @@ fn update_from_dist(dist_server: &Url,
393393
download_cfg: &DownloadCfg,
394394
temp_cfg: &temp::Cfg) -> Result<UpdateStatus> {
395395

396+
update_from_dist_(
397+
dist_server,
398+
toolchain,
399+
prefix,
400+
add,
401+
remove,
402+
download_cfg,
403+
temp_cfg,
404+
false,
405+
)
406+
}
407+
408+
fn update_from_dist_(dist_server: &Url,
409+
toolchain: &ToolchainDesc,
410+
prefix: &InstallPrefix,
411+
add: &[Component],
412+
remove: &[Component],
413+
download_cfg: &DownloadCfg,
414+
temp_cfg: &temp::Cfg,
415+
force_update: bool) -> Result<UpdateStatus> {
416+
396417
// Download the dist manifest and place it into the installation prefix
397418
let ref manifest_url = try!(make_manifest_url(dist_server, toolchain));
398419
let manifest_file = try!(temp_cfg.new_file());
@@ -412,7 +433,7 @@ fn update_from_dist(dist_server: &Url,
412433
manifestation.update(
413434
&manifest,
414435
changes,
415-
false,
436+
force_update,
416437
download_cfg,
417438
download_cfg.notify_handler.clone(),
418439
)
@@ -520,8 +541,8 @@ fn upgrade() {
520541
}
521542

522543
#[test]
523-
fn update_removes_components_that_dont_exist() {
524-
// On day 1 install the 'bonus' component, on day 2 its no londer a component
544+
fn force_update() {
545+
// On day 1 install the 'bonus' component, on day 2 its no longer a component
525546
let edit = &|date: &str, pkg: &mut MockPackage| {
526547
if date == "2016-02-01" {
527548
let mut tpkg = pkg.targets.iter_mut().find(|p| p.target == "x86_64-apple-darwin").unwrap();
@@ -531,12 +552,22 @@ fn update_removes_components_that_dont_exist() {
531552
});
532553
}
533554
};
555+
534556
setup(Some(edit), false, &|url, toolchain, prefix, download_cfg, temp_cfg| {
535557
change_channel_date(url, "nightly", "2016-02-01");
558+
// Update with bonus.
536559
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap();
537560
assert!(utils::path_exists(&prefix.path().join("bin/bonus")));
538561
change_channel_date(url, "nightly", "2016-02-02");
539-
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap();
562+
563+
// Update without bonus, should fail.
564+
let err = update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap_err();
565+
match *err.kind() {
566+
ErrorKind::RequestedComponentsUnavailable(..) => {},
567+
_ => panic!()
568+
}
569+
// Force update without bonus, should succeed, but bonus binary will be missing.
570+
update_from_dist_(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg, true).unwrap();
540571
assert!(!utils::path_exists(&prefix.path().join("bin/bonus")));
541572
});
542573
}

tests/cli-rustup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ fn toolchain_update_is_like_update_except_that_bare_install_is_an_error() {
752752
fn proxy_toolchain_shorthand() {
753753
setup(&|config| {
754754
expect_ok(config, &["rustup", "default", "stable"]);
755-
expect_ok(config, &["rustup", "toolchain", "update" , "nightly"]);
755+
expect_ok(config, &["rustup", "toolchain", "update", "nightly"]);
756756
expect_stdout_ok(config, &["rustc", "--version"], "hash-s-2");
757757
expect_stdout_ok(config, &["rustc", "+stable", "--version"], "hash-s-2");
758758
expect_stdout_ok(config, &["rustc", "+nightly", "--version"], "hash-n-2");

0 commit comments

Comments
 (0)