Skip to content

Commit a082771

Browse files
committed
Tests for renaming
1 parent ef04f0c commit a082771

File tree

5 files changed

+172
-26
lines changed

5 files changed

+172
-26
lines changed

src/rustup-dist/src/manifestation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,9 @@ fn build_update_component_lists(
443443

444444
// Add extensions that are already installed
445445
for existing_component in &starting_list {
446-
let is_extension = rust_target_package.extensions.contains(existing_component);
447446
let is_removed = changes.remove_extensions.contains(existing_component);
448447

449-
if is_extension && !is_removed {
448+
if !is_removed {
450449
// If there is a rename in the (new) manifest, then we uninstall the component with the
451450
// old name and install a component with the new name
452451
if new_manifest.renames.contains_key(&existing_component.pkg) {

src/rustup-dist/tests/channel-rust-nightly-example2.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
manifest-version = "2"
22
date = "2016-03-04"
33

4+
[rename.cargo-old]
5+
to = "cargo"
6+
47
[pkg.cargo]
58
version = "0.9.0-nightly (34269d0 2016-02-18)"
69

src/rustup-dist/tests/dist.rs

Lines changed: 165 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use rustup_dist::manifestation::{Manifestation, UpdateStatus, Changes};
2727
use rustup_dist::manifest::{Manifest, Component};
2828
use url::Url;
2929
use std::cell::Cell;
30+
use std::collections::HashMap;
3031
use std::fs;
3132
use std::path::Path;
3233
use std::sync::Arc;
@@ -41,7 +42,7 @@ pub fn create_mock_dist_server(path: &Path,
4142
channels: vec![
4243
create_mock_channel("nightly", "2016-02-01", edit),
4344
create_mock_channel("nightly", "2016-02-02", edit),
44-
]
45+
]
4546
}
4647
}
4748

@@ -183,26 +184,7 @@ pub fn create_mock_channel(channel: &str, date: &str,
183184

184185
// An extra package that can be used as a component of the other packages
185186
// for various tests
186-
let bonus_pkg = MockPackage {
187-
name: "bonus",
188-
version: "1.0.0",
189-
targets: vec![
190-
MockTargetedPackage {
191-
target: "x86_64-apple-darwin".to_string(),
192-
available: true,
193-
components: vec![],
194-
extensions: vec![],
195-
installer: MockInstallerBuilder {
196-
components: vec![MockComponentBuilder {
197-
name: "bonus-x86_64-apple-darwin".to_string(),
198-
files: vec![
199-
MockFile::new_arc("bin/bonus", contents.clone()),
200-
],
201-
}],
202-
}
203-
},
204-
]
205-
};
187+
let bonus_pkg = bonus_component("bonus", contents.clone());
206188

207189
let mut rust_pkg = rust_pkg;
208190
if let Some(edit) = edit {
@@ -217,7 +199,31 @@ pub fn create_mock_channel(channel: &str, date: &str,
217199
rustc_pkg,
218200
std_pkg,
219201
bonus_pkg,
220-
]
202+
],
203+
renames: HashMap::new(),
204+
}
205+
}
206+
207+
fn bonus_component(name: &'static str, contents: Arc<Vec<u8>>) -> MockPackage {
208+
MockPackage {
209+
name: name,
210+
version: "1.0.0",
211+
targets: vec![
212+
MockTargetedPackage {
213+
target: "x86_64-apple-darwin".to_string(),
214+
available: true,
215+
components: vec![],
216+
extensions: vec![],
217+
installer: MockInstallerBuilder {
218+
components: vec![MockComponentBuilder {
219+
name: format!("{}-x86_64-apple-darwin", name),
220+
files: vec![
221+
MockFile::new_arc(&*format!("bin/{}", name), contents),
222+
],
223+
}],
224+
}
225+
},
226+
]
221227
}
222228
}
223229

@@ -240,6 +246,134 @@ fn mock_dist_server_smoke_test() {
240246
assert!(utils::path_exists(path.join("dist/channel-rust-nightly.toml.sha256")));
241247
}
242248

249+
// Test that a standard rename works - the component is installed with the old name, then renamed
250+
// the next day to the new name.
251+
#[test]
252+
fn rename_component() {
253+
let dist_tempdir = TempDir::new("rustup").unwrap();
254+
let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap();
255+
256+
let edit_1 = &|_: &str, pkg: &mut MockPackage| {
257+
let tpkg = pkg.targets.iter_mut().find(|p| p.target == "x86_64-apple-darwin").unwrap();
258+
tpkg.components.push(MockComponent {
259+
name: "bonus".to_string(),
260+
target: "x86_64-apple-darwin".to_string(),
261+
});
262+
};
263+
let edit_2 = &|_: &str, pkg: &mut MockPackage| {
264+
let tpkg = pkg.targets.iter_mut().find(|p| p.target == "x86_64-apple-darwin").unwrap();
265+
tpkg.components.push(MockComponent {
266+
name: "bobo".to_string(),
267+
target: "x86_64-apple-darwin".to_string(),
268+
});
269+
};
270+
271+
let date_2 = "2016-02-02";
272+
let mut channel_2 = create_mock_channel("nightly", date_2, Some(edit_2));
273+
channel_2.packages[3] = bonus_component("bobo", Arc::new(date_2.as_bytes().to_vec()));
274+
channel_2.renames.insert("bonus".to_owned(), "bobo".to_owned());
275+
let mock_dist_server = MockDistServer {
276+
path: dist_tempdir.path().to_owned(),
277+
channels: vec![
278+
create_mock_channel("nightly", "2016-02-01", Some(edit_1)),
279+
channel_2,
280+
]
281+
};
282+
283+
setup_from_dist_server(mock_dist_server, url, false,
284+
&|url, toolchain, prefix, download_cfg, temp_cfg| {
285+
change_channel_date(url, "nightly", "2016-02-01");
286+
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap();
287+
assert!(utils::path_exists(&prefix.path().join("bin/bonus")));
288+
assert!(!utils::path_exists(&prefix.path().join("bin/bobo")));
289+
change_channel_date(url, "nightly", "2016-02-02");
290+
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap();
291+
assert!(!utils::path_exists(&prefix.path().join("bin/bonus")));
292+
assert!(utils::path_exists(&prefix.path().join("bin/bobo")));
293+
});
294+
}
295+
296+
// Test that a rename is ignored if the component with the new name is already installed.
297+
#[test]
298+
fn rename_component_ignore() {
299+
let dist_tempdir = TempDir::new("rustup").unwrap();
300+
let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap();
301+
302+
let edit = &|_: &str, pkg: &mut MockPackage| {
303+
let tpkg = pkg.targets.iter_mut().find(|p| p.target == "x86_64-apple-darwin").unwrap();
304+
tpkg.components.push(MockComponent {
305+
name: "bobo".to_string(),
306+
target: "x86_64-apple-darwin".to_string(),
307+
});
308+
};
309+
310+
let date_1 = "2016-02-01";
311+
let mut channel_1 = create_mock_channel("nightly", date_1, Some(edit));
312+
channel_1.packages[3] = bonus_component("bobo", Arc::new(date_1.as_bytes().to_vec()));
313+
let date_2 = "2016-02-02";
314+
let mut channel_2 = create_mock_channel("nightly", date_2, Some(edit));
315+
channel_2.packages[3] = bonus_component("bobo", Arc::new(date_2.as_bytes().to_vec()));
316+
channel_2.renames.insert("bonus".to_owned(), "bobo".to_owned());
317+
let mock_dist_server = MockDistServer {
318+
path: dist_tempdir.path().to_owned(),
319+
channels: vec![
320+
channel_1,
321+
channel_2,
322+
]
323+
};
324+
325+
setup_from_dist_server(mock_dist_server, url, false,
326+
&|url, toolchain, prefix, download_cfg, temp_cfg| {
327+
change_channel_date(url, "nightly", "2016-02-01");
328+
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap();
329+
assert!(!utils::path_exists(&prefix.path().join("bin/bonus")));
330+
assert!(utils::path_exists(&prefix.path().join("bin/bobo")));
331+
change_channel_date(url, "nightly", "2016-02-02");
332+
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap();
333+
assert!(!utils::path_exists(&prefix.path().join("bin/bonus")));
334+
assert!(utils::path_exists(&prefix.path().join("bin/bobo")));
335+
});
336+
}
337+
338+
// Test that a rename is ignored if the component with the old name was never installed.
339+
#[test]
340+
fn rename_component_new() {
341+
let dist_tempdir = TempDir::new("rustup").unwrap();
342+
let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap();
343+
344+
let edit_2 = &|_: &str, pkg: &mut MockPackage| {
345+
let tpkg = pkg.targets.iter_mut().find(|p| p.target == "x86_64-apple-darwin").unwrap();
346+
tpkg.components.push(MockComponent {
347+
name: "bobo".to_string(),
348+
target: "x86_64-apple-darwin".to_string(),
349+
});
350+
};
351+
352+
let date_2 = "2016-02-02";
353+
let mut channel_2 = create_mock_channel("nightly", date_2, Some(edit_2));
354+
channel_2.packages[3] = bonus_component("bobo", Arc::new(date_2.as_bytes().to_vec()));
355+
channel_2.renames.insert("bonus".to_owned(), "bobo".to_owned());
356+
let mock_dist_server = MockDistServer {
357+
path: dist_tempdir.path().to_owned(),
358+
channels: vec![
359+
create_mock_channel("nightly", "2016-02-01", None),
360+
channel_2,
361+
]
362+
};
363+
364+
setup_from_dist_server(mock_dist_server, url, false,
365+
&|url, toolchain, prefix, download_cfg, temp_cfg| {
366+
change_channel_date(url, "nightly", "2016-02-01");
367+
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap();
368+
assert!(!utils::path_exists(&prefix.path().join("bin/bonus")));
369+
assert!(!utils::path_exists(&prefix.path().join("bin/bobo")));
370+
change_channel_date(url, "nightly", "2016-02-02");
371+
update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap();
372+
assert!(!utils::path_exists(&prefix.path().join("bin/bonus")));
373+
assert!(utils::path_exists(&prefix.path().join("bin/bobo")));
374+
});
375+
}
376+
243377
// Installs or updates a toolchain from a dist server. If an initial
244378
// install then it will be installed with the default components. If
245379
// an upgrade then all the existing components will be upgraded.
@@ -290,7 +424,15 @@ fn uninstall(toolchain: &ToolchainDesc, prefix: &InstallPrefix, temp_cfg: &temp:
290424
fn setup(edit: Option<&Fn(&str, &mut MockPackage)>, enable_xz: bool,
291425
f: &Fn(&Url, &ToolchainDesc, &InstallPrefix, &DownloadCfg, &temp::Cfg)) {
292426
let dist_tempdir = TempDir::new("rustup").unwrap();
293-
create_mock_dist_server(dist_tempdir.path(), edit).write(&[ManifestVersion::V2], enable_xz);
427+
let mock_dist_server = create_mock_dist_server(dist_tempdir.path(), edit);
428+
let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap();
429+
setup_from_dist_server(mock_dist_server, url, enable_xz, f);
430+
}
431+
432+
433+
fn setup_from_dist_server(server: MockDistServer, url: &Url, enable_xz: bool,
434+
f: &Fn(&Url, &ToolchainDesc, &InstallPrefix, &DownloadCfg, &temp::Cfg)) {
435+
server.write(&[ManifestVersion::V2], enable_xz);
294436

295437
let prefix_tempdir = TempDir::new("rustup").unwrap();
296438

@@ -299,7 +441,6 @@ fn setup(edit: Option<&Fn(&str, &mut MockPackage)>, enable_xz: bool,
299441
DEFAULT_DIST_SERVER,
300442
Box::new(|_| ()));
301443

302-
let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap();
303444
let ref toolchain = ToolchainDesc::from_str("nightly-x86_64-apple-darwin").unwrap();
304445
let ref prefix = InstallPrefix::from(prefix_tempdir.path().to_owned());
305446
let ref download_cfg = DownloadCfg {

src/rustup-mock/src/clitools.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! tests/cli-v2.rs
33
44
use std::cell::RefCell;
5+
use std::collections::HashMap;
56
use std::env::consts::EXE_SUFFIX;
67
use std::env;
78
use std::fs::{self, File};
@@ -501,6 +502,7 @@ fn build_mock_channel(s: Scenario, channel: &str, date: &str,
501502
name: channel.to_string(),
502503
date: date.to_string(),
503504
packages: packages,
505+
renames: HashMap::new(),
504506
}
505507
}
506508

src/rustup-mock/src/dist.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub struct MockChannel {
7777
// YYYY-MM-DD
7878
pub date: String,
7979
pub packages: Vec<MockPackage>,
80+
pub renames: HashMap<String, String>,
8081
}
8182

8283
// A single rust-installer package

0 commit comments

Comments
 (0)