Skip to content

Commit 145eefb

Browse files
ongchirami3l
authored andcommitted
Add tests for add/remove components by name with target triple
1 parent fb91c53 commit 145eefb

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
@@ -1352,6 +1352,63 @@ fn add_component() {
13521352
});
13531353
}
13541354

1355+
#[test]
1356+
fn add_component_by_target_triple() {
1357+
test(&|config| {
1358+
config.with_scenario(Scenario::SimpleV2, &|config| {
1359+
config.expect_ok(&["rustup", "default", "stable"]);
1360+
config.expect_ok(&[
1361+
"rustup",
1362+
"component",
1363+
"add",
1364+
&format!("rust-std-{}", clitools::CROSS_ARCH1),
1365+
]);
1366+
let path = format!(
1367+
"toolchains/stable-{}/lib/rustlib/{}/lib/libstd.rlib",
1368+
this_host_triple(),
1369+
clitools::CROSS_ARCH1
1370+
);
1371+
assert!(config.rustupdir.has(path));
1372+
})
1373+
});
1374+
}
1375+
1376+
#[test]
1377+
fn fail_invalid_component_name() {
1378+
test(&|config| {
1379+
config.with_scenario(Scenario::SimpleV2, &|config| {
1380+
config.expect_ok(&["rustup", "default", "stable"]);
1381+
config.expect_err(
1382+
&[
1383+
"rustup",
1384+
"component",
1385+
"add",
1386+
&format!("dummy-{}", clitools::CROSS_ARCH1),
1387+
],
1388+
&format!("error: toolchain 'stable-{}' does not contain component 'dummy-{}' for target '{}'",this_host_triple(), clitools::CROSS_ARCH1, this_host_triple()),
1389+
);
1390+
})
1391+
});
1392+
}
1393+
1394+
#[test]
1395+
fn fail_invalid_component_target() {
1396+
test(&|config| {
1397+
config.with_scenario(Scenario::SimpleV2, &|config| {
1398+
config.expect_ok(&["rustup", "default", "stable"]);
1399+
config.expect_err(
1400+
&[
1401+
"rustup",
1402+
"component",
1403+
"add",
1404+
"rust-std-invalid-target",
1405+
],
1406+
&format!("error: toolchain 'stable-{}' does not contain component 'rust-std-invalid-target' for target '{}'",this_host_triple(), this_host_triple()),
1407+
);
1408+
})
1409+
});
1410+
}
1411+
13551412
#[test]
13561413
fn remove_component() {
13571414
test(&|config| {
@@ -1369,22 +1426,61 @@ fn remove_component() {
13691426
});
13701427
}
13711428

1429+
#[test]
1430+
fn remove_component_by_target_triple() {
1431+
let component_with_triple = format!("rust-std-{}", clitools::CROSS_ARCH1);
1432+
test(&|config| {
1433+
config.with_scenario(Scenario::SimpleV2, &|config| {
1434+
config.expect_ok(&["rustup", "default", "stable"]);
1435+
config.expect_ok(&["rustup", "component", "add", &component_with_triple]);
1436+
let path = PathBuf::from(format!(
1437+
"toolchains/stable-{}/lib/rustlib/{}/lib/libstd.rlib",
1438+
this_host_triple(),
1439+
clitools::CROSS_ARCH1
1440+
));
1441+
assert!(config.rustupdir.has(&path));
1442+
config.expect_ok(&["rustup", "component", "remove", &component_with_triple]);
1443+
assert!(!config.rustupdir.has(path.parent().unwrap()));
1444+
})
1445+
});
1446+
}
1447+
13721448
#[test]
13731449
fn add_remove_multiple_components() {
13741450
let files = [
13751451
"lib/rustlib/src/rust-src/foo.rs".to_owned(),
13761452
format!("lib/rustlib/{}/analysis/libfoo.json", this_host_triple()),
1453+
format!("lib/rustlib/{}/lib/libstd.rlib", clitools::CROSS_ARCH1),
1454+
format!("lib/rustlib/{}/lib/libstd.rlib", clitools::CROSS_ARCH2),
13771455
];
1456+
let component_with_triple1 = format!("rust-std-{}", clitools::CROSS_ARCH1);
1457+
let component_with_triple2 = format!("rust-std-{}", clitools::CROSS_ARCH2);
13781458

13791459
test(&|config| {
13801460
config.with_scenario(Scenario::SimpleV2, &|config| {
13811461
config.expect_ok(&["rustup", "default", "nightly"]);
1382-
config.expect_ok(&["rustup", "component", "add", "rust-src", "rust-analysis"]);
1462+
config.expect_ok(&[
1463+
"rustup",
1464+
"component",
1465+
"add",
1466+
"rust-src",
1467+
"rust-analysis",
1468+
&component_with_triple1,
1469+
&component_with_triple2,
1470+
]);
13831471
for file in &files {
13841472
let path = format!("toolchains/nightly-{}/{}", this_host_triple(), file);
13851473
assert!(config.rustupdir.has(&path));
13861474
}
1387-
config.expect_ok(&["rustup", "component", "remove", "rust-src", "rust-analysis"]);
1475+
config.expect_ok(&[
1476+
"rustup",
1477+
"component",
1478+
"remove",
1479+
"rust-src",
1480+
"rust-analysis",
1481+
&component_with_triple1,
1482+
&component_with_triple2,
1483+
]);
13881484
for file in &files {
13891485
let path = PathBuf::from(format!(
13901486
"toolchains/nightly-{}/{}",

0 commit comments

Comments
 (0)