|
3 | 3 | use cargo::core::compiler::RustDocFingerprint;
|
4 | 4 | use cargo_test_support::paths::CargoPathExt;
|
5 | 5 | use cargo_test_support::registry::Package;
|
6 |
| -use cargo_test_support::{basic_lib_manifest, basic_manifest, git, project}; |
| 6 | +use cargo_test_support::{basic_lib_manifest, basic_manifest, cross_compile, git, project}; |
7 | 7 | use cargo_test_support::{rustc_host, symlink_supported, tools};
|
8 | 8 | use std::fs;
|
9 | 9 | use std::str;
|
@@ -777,6 +777,29 @@ fn doc_target() {
|
777 | 777 | .is_file());
|
778 | 778 | }
|
779 | 779 |
|
| 780 | +#[cargo_test] |
| 781 | +fn doc_and_open() { |
| 782 | + let p = project() |
| 783 | + .file( |
| 784 | + "src/lib.rs", |
| 785 | + " |
| 786 | + /// test |
| 787 | + pub fn foo() {} |
| 788 | + ", |
| 789 | + ) |
| 790 | + .build(); |
| 791 | + |
| 792 | + p.cargo("doc --verbose --open --target") |
| 793 | + .arg(rustc_host()) |
| 794 | + .env("BROWSER", tools::echo()) |
| 795 | + .with_stderr_contains("[..] Documenting foo v0.0.1 ([..])") |
| 796 | + .with_stderr_contains(&format!( |
| 797 | + "[..] Opening [..]/target/{}/doc/foo/index.html", |
| 798 | + rustc_host() |
| 799 | + )) |
| 800 | + .run(); |
| 801 | +} |
| 802 | + |
780 | 803 | #[cargo_test]
|
781 | 804 | fn target_specific_not_documented() {
|
782 | 805 | let p = project()
|
@@ -1206,6 +1229,90 @@ fn doc_virtual_manifest_one_project() {
|
1206 | 1229 | .run();
|
1207 | 1230 | }
|
1208 | 1231 |
|
| 1232 | +#[cargo_test] |
| 1233 | +fn doc_and_open_virtual_manifest_one_project() { |
| 1234 | + if cross_compile::disabled() { |
| 1235 | + return; |
| 1236 | + } |
| 1237 | + let target = cross_compile::alternate(); |
| 1238 | + let p = project() |
| 1239 | + .file( |
| 1240 | + "Cargo.toml", |
| 1241 | + r#" |
| 1242 | + [workspace] |
| 1243 | + members = ["foo", "bar"] |
| 1244 | + "#, |
| 1245 | + ) |
| 1246 | + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) |
| 1247 | + .file("foo/src/lib.rs", "") |
| 1248 | + .file( |
| 1249 | + "bar/Cargo.toml", |
| 1250 | + &format!( |
| 1251 | + r#" |
| 1252 | + cargo-features = ["per-package-target"] |
| 1253 | + [package] |
| 1254 | + name = "bar" |
| 1255 | + version = "0.1.0" |
| 1256 | + forced-target = "{}" |
| 1257 | + "#, |
| 1258 | + target |
| 1259 | + ), |
| 1260 | + ) |
| 1261 | + .file("bar/src/lib.rs", "") |
| 1262 | + .build(); |
| 1263 | + |
| 1264 | + p.cargo("doc -p bar --open") |
| 1265 | + .masquerade_as_nightly_cargo(&["per-package-target"]) |
| 1266 | + .env("BROWSER", tools::echo()) |
| 1267 | + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") |
| 1268 | + .with_stderr_contains(&format!( |
| 1269 | + "[..] Opening [..]/target/{}/doc/bar/index.html", |
| 1270 | + target |
| 1271 | + )) |
| 1272 | + .run(); |
| 1273 | +} |
| 1274 | + |
| 1275 | +#[cargo_test] |
| 1276 | +fn doc_and_open_virtual_manifest_two_projects() { |
| 1277 | + if cross_compile::disabled() { |
| 1278 | + return; |
| 1279 | + } |
| 1280 | + let target = cross_compile::alternate(); |
| 1281 | + let p = project() |
| 1282 | + .file( |
| 1283 | + "Cargo.toml", |
| 1284 | + r#" |
| 1285 | + [workspace] |
| 1286 | + members = ["foo", "bar"] |
| 1287 | + "#, |
| 1288 | + ) |
| 1289 | + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) |
| 1290 | + .file("foo/src/lib.rs", "") |
| 1291 | + .file( |
| 1292 | + "bar/Cargo.toml", |
| 1293 | + &format!( |
| 1294 | + r#" |
| 1295 | + cargo-features = ["per-package-target"] |
| 1296 | + [package] |
| 1297 | + name = "bar" |
| 1298 | + version = "0.1.0" |
| 1299 | + forced-target = "{}" |
| 1300 | + "#, |
| 1301 | + target |
| 1302 | + ), |
| 1303 | + ) |
| 1304 | + .file("bar/src/lib.rs", "") |
| 1305 | + .build(); |
| 1306 | + |
| 1307 | + p.cargo("doc -p foo -p bar --open") |
| 1308 | + .masquerade_as_nightly_cargo(&["per-package-target"]) |
| 1309 | + .env("BROWSER", tools::echo()) |
| 1310 | + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") |
| 1311 | + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") |
| 1312 | + .with_stderr_contains("[..] Opening [..]/foo/index.html") |
| 1313 | + .run(); |
| 1314 | +} |
| 1315 | + |
1209 | 1316 | #[cargo_test]
|
1210 | 1317 | fn doc_virtual_manifest_glob() {
|
1211 | 1318 | let p = project()
|
@@ -1306,6 +1413,210 @@ fn doc_workspace_open_help_message() {
|
1306 | 1413 | .run();
|
1307 | 1414 | }
|
1308 | 1415 |
|
| 1416 | +#[cargo_test] |
| 1417 | +fn doc_workspace_open_first_one_built_for_host() { |
| 1418 | + if cross_compile::disabled() { |
| 1419 | + return; |
| 1420 | + } |
| 1421 | + let target = cross_compile::alternate(); |
| 1422 | + let p = project() |
| 1423 | + .file( |
| 1424 | + "Cargo.toml", |
| 1425 | + r#" |
| 1426 | + [workspace] |
| 1427 | + members = ["foo", "bar"] |
| 1428 | + "#, |
| 1429 | + ) |
| 1430 | + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) |
| 1431 | + .file("foo/src/lib.rs", "") |
| 1432 | + .file( |
| 1433 | + "bar/Cargo.toml", |
| 1434 | + &format!( |
| 1435 | + r#" |
| 1436 | + cargo-features = ["per-package-target"] |
| 1437 | + [package] |
| 1438 | + name = "bar" |
| 1439 | + version = "0.1.0" |
| 1440 | + forced-target = "{}" |
| 1441 | + "#, |
| 1442 | + target |
| 1443 | + ), |
| 1444 | + ) |
| 1445 | + .file("bar/src/lib.rs", "") |
| 1446 | + .build(); |
| 1447 | + |
| 1448 | + p.cargo("doc --workspace --open") |
| 1449 | + .masquerade_as_nightly_cargo(&["per-package-target"]) |
| 1450 | + .env("BROWSER", tools::echo()) |
| 1451 | + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") |
| 1452 | + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") |
| 1453 | + .with_stderr_contains("[..] Opening [..]/foo/index.html") |
| 1454 | + .run(); |
| 1455 | +} |
| 1456 | + |
| 1457 | +#[cargo_test] |
| 1458 | +fn doc_workspace_open_first_one_when_no_one_built_for_host() { |
| 1459 | + if cross_compile::disabled() { |
| 1460 | + return; |
| 1461 | + } |
| 1462 | + let target = cross_compile::alternate(); |
| 1463 | + |
| 1464 | + let p = project() |
| 1465 | + .file( |
| 1466 | + "Cargo.toml", |
| 1467 | + r#" |
| 1468 | + [workspace] |
| 1469 | + members = ["foo", "bar"] |
| 1470 | + "#, |
| 1471 | + ) |
| 1472 | + .file( |
| 1473 | + "foo/Cargo.toml", |
| 1474 | + &format!( |
| 1475 | + r#" |
| 1476 | + cargo-features = ["per-package-target"] |
| 1477 | + [package] |
| 1478 | + name = "foo" |
| 1479 | + version = "0.1.0" |
| 1480 | + forced-target = "{}" |
| 1481 | + "#, |
| 1482 | + target |
| 1483 | + ), |
| 1484 | + ) |
| 1485 | + .file("foo/src/lib.rs", "") |
| 1486 | + .file( |
| 1487 | + "bar/Cargo.toml", |
| 1488 | + &format!( |
| 1489 | + r#" |
| 1490 | + cargo-features = ["per-package-target"] |
| 1491 | + [package] |
| 1492 | + name = "bar" |
| 1493 | + version = "0.1.0" |
| 1494 | + forced-target = "{}" |
| 1495 | + "#, |
| 1496 | + target |
| 1497 | + ), |
| 1498 | + ) |
| 1499 | + .file("bar/src/lib.rs", "") |
| 1500 | + .build(); |
| 1501 | + |
| 1502 | + p.cargo("doc --workspace --open") |
| 1503 | + .masquerade_as_nightly_cargo(&["per-package-target"]) |
| 1504 | + .env("BROWSER", tools::echo()) |
| 1505 | + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") |
| 1506 | + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") |
| 1507 | + .with_stderr_contains(&format!( |
| 1508 | + "[..] Opening [..]/target/{}/doc/bar/index.html", |
| 1509 | + target |
| 1510 | + )) |
| 1511 | + .run(); |
| 1512 | +} |
| 1513 | + |
| 1514 | +#[cargo_test] |
| 1515 | +fn doc_workspace_open_first_one_built_for_target() { |
| 1516 | + if cross_compile::disabled() { |
| 1517 | + return; |
| 1518 | + } |
| 1519 | + let target = cross_compile::alternate(); |
| 1520 | + |
| 1521 | + let p = project() |
| 1522 | + .file( |
| 1523 | + "Cargo.toml", |
| 1524 | + r#" |
| 1525 | + [workspace] |
| 1526 | + members = ["foo", "bar"] |
| 1527 | + "#, |
| 1528 | + ) |
| 1529 | + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) |
| 1530 | + .file("foo/src/lib.rs", "") |
| 1531 | + .file( |
| 1532 | + "bar/Cargo.toml", |
| 1533 | + &format!( |
| 1534 | + r#" |
| 1535 | + cargo-features = ["per-package-target"] |
| 1536 | + [package] |
| 1537 | + name = "bar" |
| 1538 | + version = "0.1.0" |
| 1539 | + forced-target = "{}" |
| 1540 | + "#, |
| 1541 | + target |
| 1542 | + ), |
| 1543 | + ) |
| 1544 | + .file("bar/src/lib.rs", "") |
| 1545 | + .build(); |
| 1546 | + |
| 1547 | + p.cargo("doc --workspace --open --target") |
| 1548 | + .arg(target) |
| 1549 | + .masquerade_as_nightly_cargo(&["per-package-target"]) |
| 1550 | + .env("BROWSER", tools::echo()) |
| 1551 | + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") |
| 1552 | + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") |
| 1553 | + .with_stderr_contains(&format!( |
| 1554 | + "[..] Opening [..]/target/{}/doc/bar/index.html", |
| 1555 | + target |
| 1556 | + )) |
| 1557 | + .run(); |
| 1558 | +} |
| 1559 | + |
| 1560 | +#[cargo_test] |
| 1561 | +fn doc_workspace_open_first_one_when_no_one_built_for_target() { |
| 1562 | + if cross_compile::disabled() { |
| 1563 | + return; |
| 1564 | + } |
| 1565 | + let target = cross_compile::alternate(); |
| 1566 | + |
| 1567 | + let p = project() |
| 1568 | + .file( |
| 1569 | + "Cargo.toml", |
| 1570 | + r#" |
| 1571 | + [workspace] |
| 1572 | + members = ["foo", "bar"] |
| 1573 | + "#, |
| 1574 | + ) |
| 1575 | + .file( |
| 1576 | + "foo/Cargo.toml", |
| 1577 | + &format!( |
| 1578 | + r#" |
| 1579 | + cargo-features = ["per-package-target"] |
| 1580 | + [package] |
| 1581 | + name = "foo" |
| 1582 | + version = "0.1.0" |
| 1583 | + forced-target = "{}" |
| 1584 | + "#, |
| 1585 | + target |
| 1586 | + ), |
| 1587 | + ) |
| 1588 | + .file("foo/src/lib.rs", "") |
| 1589 | + .file( |
| 1590 | + "bar/Cargo.toml", |
| 1591 | + &format!( |
| 1592 | + r#" |
| 1593 | + cargo-features = ["per-package-target"] |
| 1594 | + [package] |
| 1595 | + name = "bar" |
| 1596 | + version = "0.1.0" |
| 1597 | + forced-target = "{}" |
| 1598 | + "#, |
| 1599 | + target |
| 1600 | + ), |
| 1601 | + ) |
| 1602 | + .file("bar/src/lib.rs", "") |
| 1603 | + .build(); |
| 1604 | + |
| 1605 | + // We don't build for host, so we should open the first one built for TARGET. |
| 1606 | + let host_target = rustc_host(); |
| 1607 | + p.cargo("doc --workspace --open --target") |
| 1608 | + .arg(host_target) |
| 1609 | + .masquerade_as_nightly_cargo(&["per-package-target"]) |
| 1610 | + .env("BROWSER", tools::echo()) |
| 1611 | + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") |
| 1612 | + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") |
| 1613 | + .with_stderr_contains(&format!( |
| 1614 | + "[..] Opening [..]/target/{}/doc/bar/index.html", |
| 1615 | + target |
| 1616 | + )) |
| 1617 | + .run(); |
| 1618 | +} |
| 1619 | + |
1309 | 1620 | #[cargo_test(nightly, reason = "-Zextern-html-root-url is unstable")]
|
1310 | 1621 | fn doc_extern_map_local() {
|
1311 | 1622 | let p = project()
|
|
0 commit comments