Skip to content

Commit 2f02956

Browse files
committed
Integration tests
1 parent a082771 commit 2f02956

File tree

4 files changed

+100
-28
lines changed

4 files changed

+100
-28
lines changed

src/rustup-mock/src/clitools.rs

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,14 @@ pub fn run(config: &Config, name: &str, args: &[&str], env: &[(&str, &str)]) ->
334334
fn create_mock_dist_server(path: &Path, s: Scenario) {
335335
let mut chans = Vec::new();
336336
if s == Scenario::Full || s == Scenario::ArchivesV1 || s == Scenario::ArchivesV2 {
337-
let c1 = build_mock_channel(s, "nightly", "2015-01-01", "1.2.0", "hash-n-1");
338-
let c2 = build_mock_channel(s, "beta", "2015-01-01", "1.1.0", "hash-b-1");
339-
let c3 = build_mock_channel(s, "stable", "2015-01-01", "1.0.0", "hash-s-1");
337+
let c1 = build_mock_channel(s, "nightly", "2015-01-01", "1.2.0", "hash-n-1", false);
338+
let c2 = build_mock_channel(s, "beta", "2015-01-01", "1.1.0", "hash-b-1", false);
339+
let c3 = build_mock_channel(s, "stable", "2015-01-01", "1.0.0", "hash-s-1", false);
340340
chans.extend(vec![c1, c2, c3]);
341341
}
342-
let c4 = build_mock_channel(s, "nightly", "2015-01-02", "1.3.0", "hash-n-2");
343-
let c5 = build_mock_channel(s, "beta", "2015-01-02", "1.2.0", "hash-b-2");
344-
let c6 = build_mock_channel(s, "stable", "2015-01-02", "1.1.0", "hash-s-2");
342+
let c4 = build_mock_channel(s, "nightly", "2015-01-02", "1.3.0", "hash-n-2", true);
343+
let c5 = build_mock_channel(s, "beta", "2015-01-02", "1.2.0", "hash-b-2", false);
344+
let c6 = build_mock_channel(s, "stable", "2015-01-02", "1.1.0", "hash-s-2", false);
345345
chans.extend(vec![c4, c5, c6]);
346346

347347
let ref vs = match s {
@@ -383,13 +383,12 @@ fn create_mock_dist_server(path: &Path, s: Scenario) {
383383
}
384384

385385
fn build_mock_channel(s: Scenario, channel: &str, date: &str,
386-
version: &'static str, version_hash: &str) -> MockChannel {
386+
version: &'static str, version_hash: &str, rename_rls: bool) -> MockChannel {
387387
// Build the mock installers
388388
let ref host_triple = this_host_triple();
389389
let std = build_mock_std_installer(host_triple);
390390
let rustc = build_mock_rustc_installer(host_triple, version, version_hash);
391391
let cargo = build_mock_cargo_installer(version, version_hash);
392-
let rls = build_mock_rls_installer(version, version_hash);
393392
let rust_docs = build_mock_rust_doc_installer();
394393
let rust = build_combined_installer(&[&std, &rustc, &cargo, &rust_docs]);
395394
let cross_std1 = build_mock_cross_std_installer(CROSS_ARCH1, date);
@@ -403,18 +402,26 @@ fn build_mock_channel(s: Scenario, channel: &str, date: &str,
403402
(cross_std1, CROSS_ARCH1.to_string()),
404403
(cross_std2, CROSS_ARCH2.to_string())]),
405404
("rustc", vec![(rustc, host_triple.clone())]),
406-
("cargo", vec![(cargo, host_triple.clone())]),
407-
("rls", vec![(rls, host_triple.clone())]),
408-
("rust-docs", vec![(rust_docs, host_triple.clone())]),
409-
("rust-src", vec![(rust_src, "*".to_string())]),
410-
("rust-analysis", vec![(rust_analysis, "*".to_string())]),
411-
("rust", vec![(rust, host_triple.clone())])];
405+
("cargo", vec![(cargo, host_triple.clone())])];
406+
407+
if rename_rls {
408+
let rls = build_mock_rls_installer(version, version_hash, false);
409+
all.push(("rls", vec![(rls, host_triple.clone())]));
410+
} else {
411+
let rls_preview = build_mock_rls_installer(version, version_hash, true);
412+
all.push(("rls-preview", vec![(rls_preview, host_triple.clone())]));
413+
}
414+
415+
let more = vec![("rust-docs", vec![(rust_docs, host_triple.clone())]),
416+
("rust-src", vec![(rust_src, "*".to_string())]),
417+
("rust-analysis", vec![(rust_analysis, "*".to_string())]),
418+
("rust", vec![(rust, host_triple.clone())])];
419+
all.extend(more);
412420

413421
if s == Scenario::MultiHost {
414422
let std = build_mock_std_installer(MULTI_ARCH1);
415423
let rustc = build_mock_rustc_installer(MULTI_ARCH1, version, version_hash);
416424
let cargo = build_mock_cargo_installer(version, version_hash);
417-
let rls = build_mock_rls_installer(version, version_hash);
418425
let rust_docs = build_mock_rust_doc_installer();
419426
let rust = build_combined_installer(&[&std, &rustc, &cargo, &rust_docs]);
420427
let cross_std1 = build_mock_cross_std_installer(CROSS_ARCH1, date);
@@ -426,9 +433,18 @@ fn build_mock_channel(s: Scenario, channel: &str, date: &str,
426433
(cross_std1, CROSS_ARCH1.to_string()),
427434
(cross_std2, CROSS_ARCH2.to_string())]),
428435
("rustc", vec![(rustc, triple.clone())]),
429-
("cargo", vec![(cargo, triple.clone())]),
430-
("rls", vec![(rls, triple.clone())]),
431-
("rust-docs", vec![(rust_docs, triple.clone())]),
436+
("cargo", vec![(cargo, triple.clone())])];
437+
all.extend(more);
438+
439+
if rename_rls {
440+
let rls = build_mock_rls_installer(version, version_hash, false);
441+
all.push(("rls", vec![(rls, triple.clone())]));
442+
} else {
443+
let rls_preview = build_mock_rls_installer(version, version_hash, true);
444+
all.push(("rls-preview", vec![(rls_preview, triple.clone())]));
445+
}
446+
447+
let more = vec![("rust-docs", vec![(rust_docs, triple.clone())]),
432448
("rust-src", vec![(rust_src, "*".to_string())]),
433449
("rust", vec![(rust, triple.clone())])];
434450

@@ -475,10 +491,17 @@ fn build_mock_channel(s: Scenario, channel: &str, date: &str,
475491
name: "rust-docs".to_string(),
476492
target: target.to_string()
477493
});
478-
target_pkg.extensions.push(MockComponent {
479-
name: "rls".to_string(),
480-
target: target.to_string()
481-
});
494+
if rename_rls {
495+
target_pkg.extensions.push(MockComponent {
496+
name: "rls".to_string(),
497+
target: target.to_string()
498+
});
499+
} else {
500+
target_pkg.extensions.push(MockComponent {
501+
name: "rls-preview".to_string(),
502+
target: target.to_string()
503+
});
504+
}
482505
target_pkg.extensions.push(MockComponent {
483506
name: "rust-std".to_string(),
484507
target: CROSS_ARCH1.to_string(),
@@ -498,11 +521,16 @@ fn build_mock_channel(s: Scenario, channel: &str, date: &str,
498521
}
499522
}
500523

524+
let mut renames = HashMap::new();
525+
if rename_rls {
526+
renames.insert("rls-preview".to_owned(), "rls".to_owned());
527+
}
528+
501529
MockChannel {
502530
name: channel.to_string(),
503531
date: date.to_string(),
504532
packages: packages,
505-
renames: HashMap::new(),
533+
renames,
506534
}
507535
}
508536

@@ -580,10 +608,15 @@ fn build_mock_cargo_installer(version: &str, version_hash: &str) -> MockInstalle
580608
}
581609
}
582610

583-
fn build_mock_rls_installer(version: &str, version_hash: &str) -> MockInstallerBuilder {
611+
fn build_mock_rls_installer(version: &str, version_hash: &str, preview: bool) -> MockInstallerBuilder {
612+
let name = if preview {
613+
"rls-preview"
614+
} else {
615+
"rls"
616+
};
584617
MockInstallerBuilder {
585618
components: vec![MockComponentBuilder {
586-
name: "rls".to_string(),
619+
name: name.to_string(),
587620
files: mock_bin("rls", version, version_hash),
588621
}],
589622
}

src/rustup-mock/src/dist.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ impl MockDistServer {
321321
}
322322
toml_manifest.insert(String::from("pkg"), toml::Value::Table(toml_packages));
323323

324+
let mut toml_renames = toml::Table::new();
325+
for (from, to) in &channel.renames {
326+
let mut toml_rename = toml::Table::new();
327+
toml_rename.insert(String::from("to"), toml::Value::String(to.to_owned()));
328+
toml_renames.insert(from.to_owned(), toml::Value::Table(toml_rename));
329+
}
330+
toml_manifest.insert(String::from("rename"), toml::Value::Table(toml_renames));
331+
324332
let manifest_name = format!("dist/channel-rust-{}", channel.name);
325333
let ref manifest_path = self.path.join(format!("{}.toml", manifest_name));
326334
write_file(manifest_path, &toml::encode_str(&toml_manifest));

tests/cli-misc.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern crate tempdir;
1010
use rustup_mock::clitools::{self, Config, Scenario,
1111
expect_stdout_ok, expect_stderr_ok, expect_ok_ex,
1212
expect_ok, expect_err, expect_timeout_ok,
13-
run, this_host_triple};
13+
run, this_host_triple, set_current_dist_date};
1414
use rustup_utils::{raw, utils};
1515

1616
use std::ops::Add;
@@ -415,7 +415,8 @@ fn telemetry_cleanup_removes_old_files() {
415415
fn rls_exists_in_toolchain() {
416416
setup(&|config| {
417417
expect_ok(config, &["rustup", "default", "stable"]);
418-
expect_ok(config, &["rustup", "component", "add", "rls"]);
418+
expect_ok(config, &["rustup", "component", "add", "rls-preview"]);
419+
419420
assert!(config.exedir.join(format!("rls{}", EXE_SUFFIX)).exists());
420421
expect_ok(config, &["rls", "--version"]);
421422
});
@@ -433,6 +434,36 @@ fn rls_does_not_exist_in_toolchain() {
433434
});
434435
}
435436

437+
#[test]
438+
fn rename_rls_before() {
439+
clitools::setup(Scenario::ArchivesV2, &|config| {
440+
set_current_dist_date(config, "2015-01-01");
441+
expect_ok(config, &["rustup", "default", "nightly"]);
442+
expect_ok(config, &["rustup", "component", "add", "rls-preview"]);
443+
444+
set_current_dist_date(config, "2015-01-02");
445+
expect_ok(config, &["rustup", "update", "--no-self-update"]);
446+
447+
assert!(config.exedir.join(format!("rls{}", EXE_SUFFIX)).exists());
448+
expect_ok(config, &["rls", "--version"]);
449+
});
450+
}
451+
452+
#[test]
453+
fn rename_rls_after() {
454+
clitools::setup(Scenario::ArchivesV2, &|config| {
455+
set_current_dist_date(config, "2015-01-01");
456+
expect_ok(config, &["rustup", "default", "nightly"]);
457+
458+
set_current_dist_date(config, "2015-01-02");
459+
expect_ok(config, &["rustup", "update", "--no-self-update"]);
460+
expect_ok(config, &["rustup", "component", "add", "rls"]);
461+
462+
assert!(config.exedir.join(format!("rls{}", EXE_SUFFIX)).exists());
463+
expect_ok(config, &["rls", "--version"]);
464+
});
465+
}
466+
436467
#[test]
437468
fn install_stops_if_rustc_exists() {
438469
let temp_dir = TempDir::new("fakebin").unwrap();

tests/cli-self-upd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ fn rls_proxy_set_up_after_install() {
12341234
expect_err(config, &["rls", "--version"],
12351235
&format!("toolchain 'stable-{}' does not have the binary `rls{}`",
12361236
this_host_triple(), EXE_SUFFIX));
1237-
expect_ok(config, &["rustup", "component", "add", "rls"]);
1237+
expect_ok(config, &["rustup", "component", "add", "rls-preview"]);
12381238
expect_ok(config, &["rls", "--version"]);
12391239
});
12401240
}

0 commit comments

Comments
 (0)