Skip to content

Commit 1720239

Browse files
committed
Add tests for add/remove components by name with target triple
1 parent 04f5a5e commit 1720239

File tree

1 file changed

+98
-2
lines changed

1 file changed

+98
-2
lines changed

tests/suite/cli_rustup.rs

+98-2
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,63 @@ fn add_component() {
13661366
});
13671367
}
13681368

1369+
#[test]
1370+
fn add_component_by_target_triple() {
1371+
test(&|config| {
1372+
config.with_scenario(Scenario::SimpleV2, &|config| {
1373+
config.expect_ok(&["rustup", "default", "stable"]);
1374+
config.expect_ok(&[
1375+
"rustup",
1376+
"component",
1377+
"add",
1378+
&format!("rust-std-{}", clitools::CROSS_ARCH1),
1379+
]);
1380+
let path = format!(
1381+
"toolchains/stable-{}/lib/rustlib/{}/lib/libstd.rlib",
1382+
this_host_triple(),
1383+
clitools::CROSS_ARCH1
1384+
);
1385+
assert!(config.rustupdir.has(path));
1386+
})
1387+
});
1388+
}
1389+
1390+
#[test]
1391+
fn fail_invalid_component_name() {
1392+
test(&|config| {
1393+
config.with_scenario(Scenario::SimpleV2, &|config| {
1394+
config.expect_ok(&["rustup", "default", "stable"]);
1395+
config.expect_err(
1396+
&[
1397+
"rustup",
1398+
"component",
1399+
"add",
1400+
&format!("dummy-{}", clitools::CROSS_ARCH1),
1401+
],
1402+
&format!("error: toolchain 'stable-{}' does not contain component 'dummy-{}' for target '{}'",this_host_triple(), clitools::CROSS_ARCH1, this_host_triple()),
1403+
);
1404+
})
1405+
});
1406+
}
1407+
1408+
#[test]
1409+
fn fail_invalid_component_target() {
1410+
test(&|config| {
1411+
config.with_scenario(Scenario::SimpleV2, &|config| {
1412+
config.expect_ok(&["rustup", "default", "stable"]);
1413+
config.expect_err(
1414+
&[
1415+
"rustup",
1416+
"component",
1417+
"add",
1418+
"rust-std-invalid-target",
1419+
],
1420+
&format!("error: toolchain 'stable-{}' does not contain component 'rust-std-invalid-target' for target '{}'",this_host_triple(), this_host_triple()),
1421+
);
1422+
})
1423+
});
1424+
}
1425+
13691426
#[test]
13701427
fn remove_component() {
13711428
test(&|config| {
@@ -1383,22 +1440,61 @@ fn remove_component() {
13831440
});
13841441
}
13851442

1443+
#[test]
1444+
fn remove_component_by_target_triple() {
1445+
let component_with_triple = format!("rust-std-{}", clitools::CROSS_ARCH1);
1446+
test(&|config| {
1447+
config.with_scenario(Scenario::SimpleV2, &|config| {
1448+
config.expect_ok(&["rustup", "default", "stable"]);
1449+
config.expect_ok(&["rustup", "component", "add", &component_with_triple]);
1450+
let path = PathBuf::from(format!(
1451+
"toolchains/stable-{}/lib/rustlib/{}/lib/libstd.rlib",
1452+
this_host_triple(),
1453+
clitools::CROSS_ARCH1
1454+
));
1455+
assert!(config.rustupdir.has(&path));
1456+
config.expect_ok(&["rustup", "component", "remove", &component_with_triple]);
1457+
assert!(!config.rustupdir.has(path.parent().unwrap()));
1458+
})
1459+
});
1460+
}
1461+
13861462
#[test]
13871463
fn add_remove_multiple_components() {
13881464
let files = [
13891465
"lib/rustlib/src/rust-src/foo.rs".to_owned(),
13901466
format!("lib/rustlib/{}/analysis/libfoo.json", this_host_triple()),
1467+
format!("lib/rustlib/{}/lib/libstd.rlib", clitools::CROSS_ARCH1),
1468+
format!("lib/rustlib/{}/lib/libstd.rlib", clitools::CROSS_ARCH2),
13911469
];
1470+
let component_with_triple1 = format!("rust-std-{}", clitools::CROSS_ARCH1);
1471+
let component_with_triple2 = format!("rust-std-{}", clitools::CROSS_ARCH2);
13921472

13931473
test(&|config| {
13941474
config.with_scenario(Scenario::SimpleV2, &|config| {
13951475
config.expect_ok(&["rustup", "default", "nightly"]);
1396-
config.expect_ok(&["rustup", "component", "add", "rust-src", "rust-analysis"]);
1476+
config.expect_ok(&[
1477+
"rustup",
1478+
"component",
1479+
"add",
1480+
"rust-src",
1481+
"rust-analysis",
1482+
&component_with_triple1,
1483+
&component_with_triple2,
1484+
]);
13971485
for file in &files {
13981486
let path = format!("toolchains/nightly-{}/{}", this_host_triple(), file);
13991487
assert!(config.rustupdir.has(&path));
14001488
}
1401-
config.expect_ok(&["rustup", "component", "remove", "rust-src", "rust-analysis"]);
1489+
config.expect_ok(&[
1490+
"rustup",
1491+
"component",
1492+
"remove",
1493+
"rust-src",
1494+
"rust-analysis",
1495+
&component_with_triple1,
1496+
&component_with_triple2,
1497+
]);
14021498
for file in &files {
14031499
let path = PathBuf::from(format!(
14041500
"toolchains/nightly-{}/{}",

0 commit comments

Comments
 (0)