Skip to content

Commit eb8be9d

Browse files
committed
add tests
1 parent 852f3b0 commit eb8be9d

File tree

1 file changed

+218
-0
lines changed

1 file changed

+218
-0
lines changed

tests/testsuite/doc.rs

+218
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,36 @@ fn doc_target() {
777777
.is_file());
778778
}
779779

780+
#[cargo_test]
781+
fn doc_target_and_open() {
782+
const TARGET: &str = "i686-unknown-linux-gnu";
783+
784+
let p = project()
785+
.file(
786+
"src/lib.rs",
787+
"
788+
/// test
789+
pub fn foo() {}
790+
",
791+
)
792+
.build();
793+
794+
p.cargo("doc --verbose --open --target")
795+
.arg(TARGET)
796+
.env("BROWSER", tools::echo())
797+
.with_stderr_contains("[..] Documenting foo v0.0.1 ([..])")
798+
.with_stderr_contains(&format!(
799+
"[..] Opening [..]/target/{}/doc/foo/index.html",
800+
TARGET
801+
))
802+
.run();
803+
assert!(p.root().join(&format!("target/{}/doc", TARGET)).is_dir());
804+
assert!(p
805+
.root()
806+
.join(&format!("target/{}/doc/foo/index.html", TARGET))
807+
.is_file());
808+
}
809+
780810
#[cargo_test]
781811
fn target_specific_not_documented() {
782812
let p = project()
@@ -1306,6 +1336,194 @@ fn doc_workspace_open_help_message() {
13061336
.run();
13071337
}
13081338

1339+
#[cargo_test(nightly, reason = "-Zper-package-target is unstable")]
1340+
fn doc_workspace_open_first_one_built_for_host() {
1341+
let p = project()
1342+
.file(
1343+
"Cargo.toml",
1344+
r#"
1345+
[workspace]
1346+
members = ["foo", "bar"]
1347+
"#,
1348+
)
1349+
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
1350+
.file("foo/src/lib.rs", "")
1351+
.file(
1352+
"bar/Cargo.toml",
1353+
r#"
1354+
cargo-features = ["per-package-target"]
1355+
[package]
1356+
name = "bar"
1357+
version = "0.1.0"
1358+
forced-target = "i686-unknown-linux-gnu"
1359+
"#,
1360+
)
1361+
.file("bar/src/lib.rs", "")
1362+
.build();
1363+
1364+
p.cargo("doc --workspace --open")
1365+
.masquerade_as_nightly_cargo(&["per-package-target"])
1366+
.env("BROWSER", tools::echo())
1367+
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
1368+
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
1369+
.with_stderr_contains("[..] Opening [..]/foo/index.html")
1370+
.run();
1371+
}
1372+
1373+
#[cargo_test(nightly, reason = "-Zper-package-target is unstable")]
1374+
fn doc_workspace_open_first_one_when_no_one_built_for_host() {
1375+
const TARGET: &str = "i686-unknown-linux-gnu";
1376+
1377+
let p = project()
1378+
.file(
1379+
"Cargo.toml",
1380+
r#"
1381+
[workspace]
1382+
members = ["foo", "bar"]
1383+
"#,
1384+
)
1385+
.file(
1386+
"foo/Cargo.toml",
1387+
&format!(
1388+
r#"
1389+
cargo-features = ["per-package-target"]
1390+
[package]
1391+
name = "foo"
1392+
version = "0.1.0"
1393+
forced-target = "{}"
1394+
"#,
1395+
TARGET
1396+
),
1397+
)
1398+
.file("foo/src/lib.rs", "")
1399+
.file(
1400+
"bar/Cargo.toml",
1401+
&format!(
1402+
r#"
1403+
cargo-features = ["per-package-target"]
1404+
[package]
1405+
name = "bar"
1406+
version = "0.1.0"
1407+
forced-target = "{}"
1408+
"#,
1409+
TARGET
1410+
),
1411+
)
1412+
.file("bar/src/lib.rs", "")
1413+
.build();
1414+
1415+
p.cargo("doc --workspace --open")
1416+
.masquerade_as_nightly_cargo(&["per-package-target"])
1417+
.env("BROWSER", tools::echo())
1418+
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
1419+
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
1420+
.with_stderr_contains(&format!(
1421+
"[..] Opening [..]/target/{}/doc/bar/index.html",
1422+
TARGET
1423+
))
1424+
.run();
1425+
}
1426+
1427+
#[cargo_test(nightly, reason = "-Zper-package-target is unstable")]
1428+
fn doc_workspace_open_first_one_built_for_target() {
1429+
const TARGET: &str = "i686-unknown-linux-gnu";
1430+
1431+
let p = project()
1432+
.file(
1433+
"Cargo.toml",
1434+
r#"
1435+
[workspace]
1436+
members = ["foo", "bar"]
1437+
"#,
1438+
)
1439+
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
1440+
.file("foo/src/lib.rs", "")
1441+
.file(
1442+
"bar/Cargo.toml",
1443+
&format!(
1444+
r#"
1445+
cargo-features = ["per-package-target"]
1446+
[package]
1447+
name = "bar"
1448+
version = "0.1.0"
1449+
forced-target = "{}"
1450+
"#,
1451+
TARGET
1452+
),
1453+
)
1454+
.file("bar/src/lib.rs", "")
1455+
.build();
1456+
1457+
p.cargo("doc --workspace --open --target")
1458+
.arg(TARGET)
1459+
.masquerade_as_nightly_cargo(&["per-package-target"])
1460+
.env("BROWSER", tools::echo())
1461+
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
1462+
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
1463+
.with_stderr_contains(&format!(
1464+
"[..] Opening [..]/target/{}/doc/bar/index.html",
1465+
TARGET
1466+
))
1467+
.run();
1468+
}
1469+
1470+
#[cargo_test(nightly, reason = "-Zper-package-target is unstable")]
1471+
fn doc_workspace_open_first_one_when_no_one_built_for_target() {
1472+
const TARGET: &str = "i686-unknown-linux-gnu";
1473+
1474+
let p = project()
1475+
.file(
1476+
"Cargo.toml",
1477+
r#"
1478+
[workspace]
1479+
members = ["foo", "bar"]
1480+
"#,
1481+
)
1482+
.file(
1483+
"foo/Cargo.toml",
1484+
&format!(
1485+
r#"
1486+
cargo-features = ["per-package-target"]
1487+
[package]
1488+
name = "foo"
1489+
version = "0.1.0"
1490+
forced-target = "{}"
1491+
"#,
1492+
TARGET
1493+
),
1494+
)
1495+
.file("foo/src/lib.rs", "")
1496+
.file(
1497+
"bar/Cargo.toml",
1498+
&format!(
1499+
r#"
1500+
cargo-features = ["per-package-target"]
1501+
[package]
1502+
name = "bar"
1503+
version = "0.1.0"
1504+
forced-target = "{}"
1505+
"#,
1506+
TARGET
1507+
),
1508+
)
1509+
.file("bar/src/lib.rs", "")
1510+
.build();
1511+
1512+
// We don't build for host, so we should open the first one built for TARGET.
1513+
let host_target = rustc_host();
1514+
p.cargo("doc --workspace --open --target")
1515+
.arg(host_target)
1516+
.masquerade_as_nightly_cargo(&["per-package-target"])
1517+
.env("BROWSER", tools::echo())
1518+
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
1519+
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
1520+
.with_stderr_contains(&format!(
1521+
"[..] Opening [..]/target/{}/doc/bar/index.html",
1522+
TARGET
1523+
))
1524+
.run();
1525+
}
1526+
13091527
#[cargo_test(nightly, reason = "-Zextern-html-root-url is unstable")]
13101528
fn doc_extern_map_local() {
13111529
let p = project()

0 commit comments

Comments
 (0)