Skip to content

Commit 6e19fbe

Browse files
committed
test: turn set_current_dist_date() into a Config method
1 parent fd1d836 commit 6e19fbe

File tree

7 files changed

+60
-65
lines changed

7 files changed

+60
-65
lines changed

src/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub use crate::cli::self_update::{RegistryGuard, RegistryValueId, USER_PATH, get
2929
mod clitools;
3030
pub use clitools::{
3131
CliTestContext, Config, SanitizedOutput, Scenario, SelfUpdateTestContext, output_release_file,
32-
print_command, print_indented, set_current_dist_date,
32+
print_command, print_indented,
3333
};
3434
pub(crate) mod dist;
3535
pub(crate) mod mock;

src/test/clitools.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,14 @@ impl Config {
397397
stderr: out.stderr,
398398
}
399399
}
400+
401+
/// Change the current distribution manifest to a particular date
402+
pub fn set_current_dist_date(&self, date: &str) {
403+
let url = Url::from_file_path(self.distdir.as_ref().unwrap()).unwrap();
404+
for channel in &["nightly", "beta", "stable"] {
405+
change_channel_date(&url, channel, date);
406+
}
407+
}
400408
}
401409

402410
// Describes all the features of the mock dist server.
@@ -975,14 +983,6 @@ version = "{version}"
975983
utils::write_file("release", &file, &contents).unwrap();
976984
}
977985

978-
/// Change the current distribution manifest to a particular date
979-
pub fn set_current_dist_date(config: &Config, date: &str) {
980-
let url = Url::from_file_path(config.distdir.as_ref().unwrap()).unwrap();
981-
for channel in &["nightly", "beta", "stable"] {
982-
change_channel_date(&url, channel, date);
983-
}
984-
}
985-
986986
pub fn print_command(args: &[&str], out: &SanitizedOutput) {
987987
print!("\n>");
988988
for arg in args {

tests/suite/cli_exact.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
44
use rustup::for_host;
55
use rustup::test::{
6-
CROSS_ARCH1, CROSS_ARCH2, CliTestContext, MULTI_ARCH1, Scenario, set_current_dist_date,
7-
this_host_triple,
6+
CROSS_ARCH1, CROSS_ARCH2, CliTestContext, MULTI_ARCH1, Scenario, this_host_triple,
87
};
98

109
#[tokio::test]
@@ -726,7 +725,7 @@ async fn install_by_version_number() {
726725
async fn install_unreleased_component() {
727726
let mut cx = CliTestContext::new(Scenario::MissingComponentMulti).await;
728727
// Initial channel content is host + rls + multiarch-std
729-
set_current_dist_date(&cx.config, "2019-09-12");
728+
cx.config.set_current_dist_date("2019-09-12");
730729
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
731730
cx.config
732731
.expect_ok(&["rustup", "component", "add", "rls"])
@@ -736,7 +735,7 @@ async fn install_unreleased_component() {
736735
.await;
737736

738737
// Next channel variant should have host + rls but not multiarch-std
739-
set_current_dist_date(&cx.config, "2019-09-13");
738+
cx.config.set_current_dist_date("2019-09-13");
740739
cx.config
741740
.expect_ok_ex(
742741
&["rustup", "update", "nightly"],
@@ -759,7 +758,7 @@ info: syncing channel updates for 'nightly-2019-09-12-{0}'
759758
.await;
760759

761760
// Next channel variant should have host + multiarch-std but have rls missing
762-
set_current_dist_date(&cx.config, "2019-09-14");
761+
cx.config.set_current_dist_date("2019-09-14");
763762
cx.config
764763
.expect_ok_ex(
765764
&["rustup", "update", "nightly"],

tests/suite/cli_inst_interactive.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use std::io::Write;
55
use std::process::Stdio;
66

77
use rustup::for_host;
8-
use rustup::test::{
9-
CliTestContext, Config, SanitizedOutput, Scenario, set_current_dist_date, this_host_triple,
10-
};
8+
use rustup::test::{CliTestContext, Config, SanitizedOutput, Scenario, this_host_triple};
119
#[cfg(windows)]
1210
use rustup::test::{RegistryGuard, USER_PATH};
1311
use rustup::utils::raw;
@@ -421,7 +419,7 @@ async fn install_with_components() {
421419
#[tokio::test]
422420
async fn install_forces_and_skips_rls() {
423421
let cx = CliTestContext::new(Scenario::UnavailableRls).await;
424-
set_current_dist_date(&cx.config, "2015-01-01");
422+
cx.config.set_current_dist_date("2015-01-01");
425423

426424
let out = run_input(
427425
&cx.config,

tests/suite/cli_misc.rs

+25-26
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use std::{env::consts::EXE_SUFFIX, path::Path};
77

88
use rustup::for_host;
99
use rustup::test::{
10-
CliTestContext, Config, MULTI_ARCH1, Scenario, print_command, print_indented,
11-
set_current_dist_date, this_host_triple,
10+
CliTestContext, Config, MULTI_ARCH1, Scenario, print_command, print_indented, this_host_triple,
1211
};
1312
use rustup::utils;
1413
use rustup::utils::raw::symlink_dir;
@@ -549,7 +548,7 @@ async fn rls_exists_in_toolchain() {
549548
#[tokio::test]
550549
async fn run_rls_when_not_available_in_toolchain() {
551550
let mut cx = CliTestContext::new(Scenario::UnavailableRls).await;
552-
set_current_dist_date(&cx.config, "2015-01-01");
551+
cx.config.set_current_dist_date("2015-01-01");
553552
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
554553
cx.config.expect_err(
555554
&["rls", "--version"],
@@ -560,7 +559,7 @@ async fn run_rls_when_not_available_in_toolchain() {
560559
),
561560
).await;
562561

563-
set_current_dist_date(&cx.config, "2015-01-02");
562+
cx.config.set_current_dist_date("2015-01-02");
564563
cx.config.expect_ok(&["rustup", "update"]).await;
565564
cx.config
566565
.expect_ok(&["rustup", "component", "add", "rls"])
@@ -603,7 +602,7 @@ async fn run_rls_when_not_installed_for_nightly() {
603602
#[tokio::test]
604603
async fn run_rust_lldb_when_not_in_toolchain() {
605604
let mut cx = CliTestContext::new(Scenario::UnavailableRls).await;
606-
set_current_dist_date(&cx.config, "2015-01-01");
605+
cx.config.set_current_dist_date("2015-01-01");
607606
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
608607
cx.config.expect_err(
609608
&["rust-lldb", "--version"],
@@ -618,13 +617,13 @@ async fn run_rust_lldb_when_not_in_toolchain() {
618617
#[tokio::test]
619618
async fn rename_rls_before() {
620619
let mut cx = CliTestContext::new(Scenario::ArchivesV2).await;
621-
set_current_dist_date(&cx.config, "2015-01-01");
620+
cx.config.set_current_dist_date("2015-01-01");
622621
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
623622
cx.config
624623
.expect_ok(&["rustup", "component", "add", "rls"])
625624
.await;
626625

627-
set_current_dist_date(&cx.config, "2015-01-02");
626+
cx.config.set_current_dist_date("2015-01-02");
628627
cx.config.expect_ok(&["rustup", "update"]).await;
629628

630629
assert!(cx.config.exedir.join(format!("rls{EXE_SUFFIX}")).exists());
@@ -634,10 +633,10 @@ async fn rename_rls_before() {
634633
#[tokio::test]
635634
async fn rename_rls_after() {
636635
let mut cx = CliTestContext::new(Scenario::ArchivesV2).await;
637-
set_current_dist_date(&cx.config, "2015-01-01");
636+
cx.config.set_current_dist_date("2015-01-01");
638637
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
639638

640-
set_current_dist_date(&cx.config, "2015-01-02");
639+
cx.config.set_current_dist_date("2015-01-02");
641640
cx.config.expect_ok(&["rustup", "update"]).await;
642641
cx.config
643642
.expect_ok(&["rustup", "component", "add", "rls-preview"])
@@ -650,10 +649,10 @@ async fn rename_rls_after() {
650649
#[tokio::test]
651650
async fn rename_rls_add_old_name() {
652651
let mut cx = CliTestContext::new(Scenario::ArchivesV2).await;
653-
set_current_dist_date(&cx.config, "2015-01-01");
652+
cx.config.set_current_dist_date("2015-01-01");
654653
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
655654

656-
set_current_dist_date(&cx.config, "2015-01-02");
655+
cx.config.set_current_dist_date("2015-01-02");
657656
cx.config.expect_ok(&["rustup", "update"]).await;
658657
cx.config
659658
.expect_ok(&["rustup", "component", "add", "rls"])
@@ -666,10 +665,10 @@ async fn rename_rls_add_old_name() {
666665
#[tokio::test]
667666
async fn rename_rls_list() {
668667
let mut cx = CliTestContext::new(Scenario::ArchivesV2).await;
669-
set_current_dist_date(&cx.config, "2015-01-01");
668+
cx.config.set_current_dist_date("2015-01-01");
670669
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
671670

672-
set_current_dist_date(&cx.config, "2015-01-02");
671+
cx.config.set_current_dist_date("2015-01-02");
673672
cx.config.expect_ok(&["rustup", "update"]).await;
674673
cx.config
675674
.expect_ok(&["rustup", "component", "add", "rls"])
@@ -683,10 +682,10 @@ async fn rename_rls_list() {
683682
#[tokio::test]
684683
async fn rename_rls_preview_list() {
685684
let mut cx = CliTestContext::new(Scenario::ArchivesV2).await;
686-
set_current_dist_date(&cx.config, "2015-01-01");
685+
cx.config.set_current_dist_date("2015-01-01");
687686
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
688687

689-
set_current_dist_date(&cx.config, "2015-01-02");
688+
cx.config.set_current_dist_date("2015-01-02");
690689
cx.config.expect_ok(&["rustup", "update"]).await;
691690
cx.config
692691
.expect_ok(&["rustup", "component", "add", "rls-preview"])
@@ -700,10 +699,10 @@ async fn rename_rls_preview_list() {
700699
#[tokio::test]
701700
async fn rename_rls_remove() {
702701
let mut cx = CliTestContext::new(Scenario::ArchivesV2).await;
703-
set_current_dist_date(&cx.config, "2015-01-01");
702+
cx.config.set_current_dist_date("2015-01-01");
704703
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
705704

706-
set_current_dist_date(&cx.config, "2015-01-02");
705+
cx.config.set_current_dist_date("2015-01-02");
707706
cx.config.expect_ok(&["rustup", "update"]).await;
708707

709708
cx.config
@@ -780,10 +779,10 @@ async fn tmp_downloads_symlink() {
780779
fs::create_dir(&test_downloads).unwrap();
781780
symlink_dir(&test_downloads, &cx.config.rustupdir.join("downloads")).unwrap();
782781

783-
set_current_dist_date(&cx.config, "2015-01-01");
782+
cx.config.set_current_dist_date("2015-01-01");
784783
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
785784

786-
set_current_dist_date(&cx.config, "2015-01-02");
785+
cx.config.set_current_dist_date("2015-01-02");
787786
cx.config.expect_ok(&["rustup", "update"]).await;
788787

789788
assert!(cx.config.rustupdir.join("tmp").exists());
@@ -833,15 +832,15 @@ info: toolchain 'test' uninstalled
833832
#[tokio::test]
834833
async fn update_unavailable_rustc() {
835834
let mut cx = CliTestContext::new(Scenario::Unavailable).await;
836-
set_current_dist_date(&cx.config, "2015-01-01");
835+
cx.config.set_current_dist_date("2015-01-01");
837836
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
838837

839838
cx.config
840839
.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-1")
841840
.await;
842841

843842
// latest nightly is unavailable
844-
set_current_dist_date(&cx.config, "2015-01-02");
843+
cx.config.set_current_dist_date("2015-01-02");
845844
// update should do nothing
846845
cx.config.expect_ok(&["rustup", "update", "nightly"]).await;
847846
cx.config
@@ -853,7 +852,7 @@ async fn update_unavailable_rustc() {
853852
#[tokio::test]
854853
async fn install_unavailable_platform() {
855854
let cx = CliTestContext::new(Scenario::Unavailable).await;
856-
set_current_dist_date(&cx.config, "2015-01-02");
855+
cx.config.set_current_dist_date("2015-01-02");
857856
// explicit attempt to install should fail
858857
cx.config
859858
.expect_err(
@@ -889,7 +888,7 @@ async fn install_beta_with_tag() {
889888
#[tokio::test]
890889
async fn update_nightly_even_with_incompat() {
891890
let mut cx = CliTestContext::new(Scenario::MissingComponent).await;
892-
set_current_dist_date(&cx.config, "2019-09-12");
891+
cx.config.set_current_dist_date("2019-09-12");
893892
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
894893

895894
cx.config
@@ -901,7 +900,7 @@ async fn update_nightly_even_with_incompat() {
901900
cx.config.expect_component_executable("rls").await;
902901

903902
// latest nightly is now one that does not have RLS
904-
set_current_dist_date(&cx.config, "2019-09-14");
903+
cx.config.set_current_dist_date("2019-09-14");
905904

906905
cx.config.expect_component_executable("rls").await;
907906
// update should bring us to latest nightly that does
@@ -915,7 +914,7 @@ async fn update_nightly_even_with_incompat() {
915914
#[tokio::test]
916915
async fn nightly_backtrack_skips_missing() {
917916
let mut cx = CliTestContext::new(Scenario::MissingNightly).await;
918-
set_current_dist_date(&cx.config, "2019-09-16");
917+
cx.config.set_current_dist_date("2019-09-16");
919918
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
920919

921920
cx.config
@@ -927,7 +926,7 @@ async fn nightly_backtrack_skips_missing() {
927926
cx.config.expect_component_executable("rls").await;
928927

929928
// rls is missing on latest, nightly is missing on second-to-latest
930-
set_current_dist_date(&cx.config, "2019-09-18");
929+
cx.config.set_current_dist_date("2019-09-18");
931930

932931
// update should not change nightly, and should not error
933932
cx.config.expect_ok(&["rustup", "update", "nightly"]).await;

tests/suite/cli_v1.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::fs;
55

66
use rustup::for_host;
7-
use rustup::test::{CliTestContext, Scenario, set_current_dist_date};
7+
use rustup::test::{CliTestContext, Scenario};
88

99
#[tokio::test]
1010
async fn rustc_no_default_toolchain() {
@@ -90,12 +90,12 @@ async fn default_existing_toolchain() {
9090
#[tokio::test]
9191
async fn update_channel() {
9292
let mut cx = CliTestContext::new(Scenario::ArchivesV1).await;
93-
set_current_dist_date(&cx.config, "2015-01-01");
93+
cx.config.set_current_dist_date("2015-01-01");
9494
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
9595
cx.config
9696
.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-1")
9797
.await;
98-
set_current_dist_date(&cx.config, "2015-01-02");
98+
cx.config.set_current_dist_date("2015-01-02");
9999
cx.config.expect_ok(&["rustup", "update", "nightly"]).await;
100100
cx.config
101101
.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-2")
@@ -443,12 +443,12 @@ async fn no_update_on_channel_when_date_has_not_changed() {
443443
#[tokio::test]
444444
async fn update_on_channel_when_date_has_changed() {
445445
let mut cx = CliTestContext::new(Scenario::ArchivesV1).await;
446-
set_current_dist_date(&cx.config, "2015-01-01");
446+
cx.config.set_current_dist_date("2015-01-01");
447447
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
448448
cx.config
449449
.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-1")
450450
.await;
451-
set_current_dist_date(&cx.config, "2015-01-02");
451+
cx.config.set_current_dist_date("2015-01-02");
452452
cx.config.expect_ok(&["rustup", "update", "nightly"]).await;
453453
cx.config
454454
.expect_stdout_ok(&["rustc", "--version"], "hash-nightly-2")

0 commit comments

Comments
 (0)