Skip to content

Commit 540ccc6

Browse files
committed
Adding tests to cli-exact suite for rustup check command
1 parent 21549ea commit 540ccc6

File tree

6 files changed

+112
-23
lines changed

6 files changed

+112
-23
lines changed

tests/cli-exact.rs

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
pub mod mock;
55

66
use crate::mock::clitools::{
7-
self, expect_err_ex, expect_ok, expect_ok_ex, this_host_triple, Config, Scenario,
7+
self, expect_err_ex, expect_ok, expect_ok_ex, expect_stdout_ok, set_current_dist_date,
8+
this_host_triple, Config, Scenario,
89
};
910

1011
macro_rules! for_host {
@@ -14,7 +15,7 @@ macro_rules! for_host {
1415
}
1516

1617
fn setup(f: &dyn Fn(&mut Config)) {
17-
clitools::setup(Scenario::SimpleV2, f);
18+
clitools::setup(Scenario::ArchivesV2, f);
1819
}
1920

2021
#[test]
@@ -31,7 +32,7 @@ fn update() {
3132
),
3233
for_host!(
3334
r"info: syncing channel updates for 'nightly-{0}'
34-
info: latest update on 2015-01-02, rust version 1.3.0
35+
info: latest update on 2015-01-02, rust version 1.3.0 (hash-n-2)
3536
info: downloading component 'rustc'
3637
info: downloading component 'cargo'
3738
info: downloading component 'rust-std'
@@ -68,6 +69,89 @@ fn update_again() {
6869
});
6970
}
7071

72+
#[test]
73+
fn check_updates_none() {
74+
setup(&|config| {
75+
set_current_dist_date(config, "2015-01-01");
76+
expect_ok(config, &["rustup", "update", "stable", "--no-self-update"]);
77+
expect_ok(config, &["rustup", "update", "beta", "--no-self-update"]);
78+
expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]);
79+
expect_stdout_ok(
80+
config,
81+
&["rustup", "check"],
82+
for_host!(
83+
r"stable-{0} - Up to date : 1.0.0 (hash-s-1)
84+
beta-{0} - Up to date : 1.1.0 (hash-b-1)
85+
nightly-{0} - Up to date : 1.2.0 (hash-n-1)
86+
"
87+
),
88+
);
89+
})
90+
}
91+
92+
#[test]
93+
fn check_updates_some() {
94+
setup(&|config| {
95+
set_current_dist_date(config, "2015-01-01");
96+
expect_ok(config, &["rustup", "update", "stable", "--no-self-update"]);
97+
expect_ok(config, &["rustup", "update", "beta", "--no-self-update"]);
98+
expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]);
99+
set_current_dist_date(config, "2015-01-02");
100+
expect_stdout_ok(
101+
config,
102+
&["rustup", "check"],
103+
for_host!(
104+
r"stable-{0} - Update available : 1.0.0 (hash-s-1) -> 1.1.0 (hash-s-2)
105+
beta-{0} - Update available : 1.1.0 (hash-b-1) -> 1.2.0 (hash-b-2)
106+
nightly-{0} - Update available : 1.2.0 (hash-n-1) -> 1.3.0 (hash-n-2)
107+
"
108+
),
109+
);
110+
})
111+
}
112+
113+
#[test]
114+
fn check_updates_with_update() {
115+
setup(&|config| {
116+
set_current_dist_date(config, "2015-01-01");
117+
expect_ok(config, &["rustup", "update", "stable", "--no-self-update"]);
118+
expect_ok(config, &["rustup", "update", "beta", "--no-self-update"]);
119+
expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]);
120+
expect_stdout_ok(
121+
config,
122+
&["rustup", "check"],
123+
for_host!(
124+
r"stable-{0} - Up to date : 1.0.0 (hash-s-1)
125+
beta-{0} - Up to date : 1.1.0 (hash-b-1)
126+
nightly-{0} - Up to date : 1.2.0 (hash-n-1)
127+
"
128+
),
129+
);
130+
set_current_dist_date(config, "2015-01-02");
131+
expect_stdout_ok(
132+
config,
133+
&["rustup", "check"],
134+
for_host!(
135+
r"stable-{0} - Update available : 1.0.0 (hash-s-1) -> 1.1.0 (hash-s-2)
136+
beta-{0} - Update available : 1.1.0 (hash-b-1) -> 1.2.0 (hash-b-2)
137+
nightly-{0} - Update available : 1.2.0 (hash-n-1) -> 1.3.0 (hash-n-2)
138+
"
139+
),
140+
);
141+
expect_ok(config, &["rustup", "update", "beta", "--no-self-update"]);
142+
expect_stdout_ok(
143+
config,
144+
&["rustup", "check"],
145+
for_host!(
146+
r"stable-{0} - Update available : 1.0.0 (hash-s-1) -> 1.1.0 (hash-s-2)
147+
beta-{0} - Up to date : 1.2.0 (hash-b-2)
148+
nightly-{0} - Update available : 1.2.0 (hash-n-1) -> 1.3.0 (hash-n-2)
149+
"
150+
),
151+
);
152+
})
153+
}
154+
71155
#[test]
72156
fn default() {
73157
setup(&|config| {
@@ -82,7 +166,7 @@ fn default() {
82166
),
83167
for_host!(
84168
r"info: syncing channel updates for 'nightly-{0}'
85-
info: latest update on 2015-01-02, rust version 1.3.0
169+
info: latest update on 2015-01-02, rust version 1.3.0 (hash-n-2)
86170
info: downloading component 'rustc'
87171
info: downloading component 'cargo'
88172
info: downloading component 'rust-std'
@@ -342,7 +426,7 @@ fn update_invalid_toolchain() {
342426
&["rustup", "update", "nightly-2016-03-1"],
343427
r"",
344428
r"info: syncing channel updates for 'nightly-2016-03-1'
345-
info: latest update on 2015-01-02, rust version 1.3.0
429+
info: latest update on 2015-01-02, rust version 1.3.0 (hash-n-2)
346430
error: target '2016-03-1' not found in channel. Perhaps check https://forge.rust-lang.org/platform-support.html for available targets
347431
",
348432
);
@@ -357,7 +441,7 @@ fn default_invalid_toolchain() {
357441
&["rustup", "default", "nightly-2016-03-1"],
358442
r"",
359443
r"info: syncing channel updates for 'nightly-2016-03-1'
360-
info: latest update on 2015-01-02, rust version 1.3.0
444+
info: latest update on 2015-01-02, rust version 1.3.0 (hash-n-2)
361445
error: target '2016-03-1' not found in channel. Perhaps check https://forge.rust-lang.org/platform-support.html for available targets
362446
",
363447
);

tests/cli-rustup.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn rustup_stable() {
4646
),
4747
for_host!(
4848
r"info: syncing channel updates for 'stable-{0}'
49-
info: latest update on 2015-01-02, rust version 1.1.0
49+
info: latest update on 2015-01-02, rust version 1.1.0 (hash-s-2)
5050
info: downloading component 'rustc'
5151
info: downloading component 'cargo'
5252
info: downloading component 'rust-std'
@@ -108,7 +108,7 @@ fn rustup_all_channels() {
108108
),
109109
for_host!(
110110
r"info: syncing channel updates for 'stable-{0}'
111-
info: latest update on 2015-01-02, rust version 1.1.0
111+
info: latest update on 2015-01-02, rust version 1.1.0 (hash-s-2)
112112
info: downloading component 'rustc'
113113
info: downloading component 'cargo'
114114
info: downloading component 'rust-std'
@@ -122,7 +122,7 @@ info: installing component 'cargo'
122122
info: installing component 'rust-std'
123123
info: installing component 'rust-docs'
124124
info: syncing channel updates for 'beta-{0}'
125-
info: latest update on 2015-01-02, rust version 1.2.0
125+
info: latest update on 2015-01-02, rust version 1.2.0 (hash-b-2)
126126
info: downloading component 'rustc'
127127
info: downloading component 'cargo'
128128
info: downloading component 'rust-std'
@@ -136,7 +136,7 @@ info: installing component 'cargo'
136136
info: installing component 'rust-std'
137137
info: installing component 'rust-docs'
138138
info: syncing channel updates for 'nightly-{0}'
139-
info: latest update on 2015-01-02, rust version 1.3.0
139+
info: latest update on 2015-01-02, rust version 1.3.0 (hash-n-2)
140140
info: downloading component 'rustc'
141141
info: downloading component 'cargo'
142142
info: downloading component 'rust-std'
@@ -177,7 +177,7 @@ fn rustup_some_channels_up_to_date() {
177177
),
178178
for_host!(
179179
r"info: syncing channel updates for 'stable-{0}'
180-
info: latest update on 2015-01-02, rust version 1.1.0
180+
info: latest update on 2015-01-02, rust version 1.1.0 (hash-s-2)
181181
info: downloading component 'rustc'
182182
info: downloading component 'cargo'
183183
info: downloading component 'rust-std'
@@ -192,7 +192,7 @@ info: installing component 'rust-std'
192192
info: installing component 'rust-docs'
193193
info: syncing channel updates for 'beta-{0}'
194194
info: syncing channel updates for 'nightly-{0}'
195-
info: latest update on 2015-01-02, rust version 1.3.0
195+
info: latest update on 2015-01-02, rust version 1.3.0 (hash-n-2)
196196
info: downloading component 'rustc'
197197
info: downloading component 'cargo'
198198
info: downloading component 'rust-std'
@@ -240,7 +240,7 @@ fn default() {
240240
),
241241
for_host!(
242242
r"info: syncing channel updates for 'nightly-{0}'
243-
info: latest update on 2015-01-02, rust version 1.3.0
243+
info: latest update on 2015-01-02, rust version 1.3.0 (hash-n-2)
244244
info: downloading component 'rustc'
245245
info: downloading component 'cargo'
246246
info: downloading component 'rust-std'

tests/cli-self-upd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ fn first_install_exact() {
869869
",
870870
for_host!(
871871
r"info: syncing channel updates for 'stable-{0}'
872-
info: latest update on 2015-01-02, rust version 1.1.0
872+
info: latest update on 2015-01-02, rust version 1.1.0 (hash-s-2)
873873
info: downloading component 'rustc'
874874
info: downloading component 'cargo'
875875
info: downloading component 'rust-std'

tests/dist.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn create_mock_channel(
5050

5151
packages.push(MockPackage {
5252
name: "rust",
53-
version: "1.0.0",
53+
version: "1.0.0".to_string(),
5454
targets: vec![
5555
MockTargetedPackage {
5656
target: "x86_64-apple-darwin".to_string(),
@@ -113,7 +113,7 @@ pub fn create_mock_channel(
113113
let pkg = &bin[4..];
114114
packages.push(MockPackage {
115115
name: pkg,
116-
version: "1.0.0",
116+
version: "1.0.0".to_string(),
117117
targets: vec![
118118
MockTargetedPackage {
119119
target: "x86_64-apple-darwin".to_string(),
@@ -138,7 +138,7 @@ pub fn create_mock_channel(
138138

139139
packages.push(MockPackage {
140140
name: "rust-std",
141-
version: "1.0.0",
141+
version: "1.0.0".to_string(),
142142
targets: vec![
143143
MockTargetedPackage {
144144
target: "x86_64-apple-darwin".to_string(),
@@ -203,7 +203,7 @@ pub fn create_mock_channel(
203203
fn bonus_component(name: &'static str, contents: Arc<Vec<u8>>) -> MockPackage {
204204
MockPackage {
205205
name,
206-
version: "1.0.0",
206+
version: "1.0.0".to_string(),
207207
targets: vec![MockTargetedPackage {
208208
target: "x86_64-apple-darwin".to_string(),
209209
available: true,

tests/mock/clitools.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ fn create_mock_dist_server(path: &Path, s: Scenario) {
485485
chans.extend(vec![c1, c2, c3]);
486486
}
487487
let c4 = if s == Scenario::Unavailable {
488-
build_mock_unavailable_channel("nightly", "2015-01-02", "1.3.0")
488+
build_mock_unavailable_channel("nightly", "2015-01-02", "1.3.0", "hash-n-2")
489489
} else {
490490
build_mock_channel(
491491
s,
@@ -693,7 +693,7 @@ fn build_mock_channel(
693693

694694
MockPackage {
695695
name,
696-
version,
696+
version: format!("{} ({})", version, version_hash),
697697
targets: target_pkgs.collect(),
698698
}
699699
});
@@ -773,7 +773,12 @@ fn build_mock_channel(
773773
}
774774
}
775775

776-
fn build_mock_unavailable_channel(channel: &str, date: &str, version: &'static str) -> MockChannel {
776+
fn build_mock_unavailable_channel(
777+
channel: &str,
778+
date: &str,
779+
version: &str,
780+
version_hash: &str,
781+
) -> MockChannel {
777782
let host_triple = this_host_triple();
778783

779784
let packages = [
@@ -789,7 +794,7 @@ fn build_mock_unavailable_channel(channel: &str, date: &str, version: &'static s
789794
.iter()
790795
.map(|name| MockPackage {
791796
name,
792-
version,
797+
version: format!("{} ({})", version, version_hash),
793798
targets: vec![MockTargetedPackage {
794799
target: host_triple.clone(),
795800
available: false,

tests/mock/dist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub struct MockChannel {
8080
pub struct MockPackage {
8181
// rust, rustc, rust-std-$triple, rust-doc, etc.
8282
pub name: &'static str,
83-
pub version: &'static str,
83+
pub version: String,
8484
pub targets: Vec<MockTargetedPackage>,
8585
}
8686

0 commit comments

Comments
 (0)