|
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,49 @@ 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 | + |
1209 | 1275 | #[cargo_test]
|
1210 | 1276 | fn doc_virtual_manifest_glob() {
|
1211 | 1277 | let p = project()
|
@@ -1306,6 +1372,210 @@ fn doc_workspace_open_help_message() {
|
1306 | 1372 | .run();
|
1307 | 1373 | }
|
1308 | 1374 |
|
| 1375 | +#[cargo_test] |
| 1376 | +fn doc_workspace_open_first_one_built_for_host() { |
| 1377 | + if cross_compile::disabled() { |
| 1378 | + return; |
| 1379 | + } |
| 1380 | + let target = cross_compile::alternate(); |
| 1381 | + let p = project() |
| 1382 | + .file( |
| 1383 | + "Cargo.toml", |
| 1384 | + r#" |
| 1385 | + [workspace] |
| 1386 | + members = ["foo", "bar"] |
| 1387 | + "#, |
| 1388 | + ) |
| 1389 | + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) |
| 1390 | + .file("foo/src/lib.rs", "") |
| 1391 | + .file( |
| 1392 | + "bar/Cargo.toml", |
| 1393 | + &format!( |
| 1394 | + r#" |
| 1395 | + cargo-features = ["per-package-target"] |
| 1396 | + [package] |
| 1397 | + name = "bar" |
| 1398 | + version = "0.1.0" |
| 1399 | + forced-target = "{}" |
| 1400 | + "#, |
| 1401 | + target |
| 1402 | + ), |
| 1403 | + ) |
| 1404 | + .file("bar/src/lib.rs", "") |
| 1405 | + .build(); |
| 1406 | + |
| 1407 | + p.cargo("doc --workspace --open") |
| 1408 | + .masquerade_as_nightly_cargo(&["per-package-target"]) |
| 1409 | + .env("BROWSER", tools::echo()) |
| 1410 | + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") |
| 1411 | + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") |
| 1412 | + .with_stderr_contains("[..] Opening [..]/foo/index.html") |
| 1413 | + .run(); |
| 1414 | +} |
| 1415 | + |
| 1416 | +#[cargo_test] |
| 1417 | +fn doc_workspace_open_first_one_when_no_one_built_for_host() { |
| 1418 | + if cross_compile::disabled() { |
| 1419 | + return; |
| 1420 | + } |
| 1421 | + let target = cross_compile::alternate(); |
| 1422 | + |
| 1423 | + let p = project() |
| 1424 | + .file( |
| 1425 | + "Cargo.toml", |
| 1426 | + r#" |
| 1427 | + [workspace] |
| 1428 | + members = ["foo", "bar"] |
| 1429 | + "#, |
| 1430 | + ) |
| 1431 | + .file( |
| 1432 | + "foo/Cargo.toml", |
| 1433 | + &format!( |
| 1434 | + r#" |
| 1435 | + cargo-features = ["per-package-target"] |
| 1436 | + [package] |
| 1437 | + name = "foo" |
| 1438 | + version = "0.1.0" |
| 1439 | + forced-target = "{}" |
| 1440 | + "#, |
| 1441 | + target |
| 1442 | + ), |
| 1443 | + ) |
| 1444 | + .file("foo/src/lib.rs", "") |
| 1445 | + .file( |
| 1446 | + "bar/Cargo.toml", |
| 1447 | + &format!( |
| 1448 | + r#" |
| 1449 | + cargo-features = ["per-package-target"] |
| 1450 | + [package] |
| 1451 | + name = "bar" |
| 1452 | + version = "0.1.0" |
| 1453 | + forced-target = "{}" |
| 1454 | + "#, |
| 1455 | + target |
| 1456 | + ), |
| 1457 | + ) |
| 1458 | + .file("bar/src/lib.rs", "") |
| 1459 | + .build(); |
| 1460 | + |
| 1461 | + p.cargo("doc --workspace --open") |
| 1462 | + .masquerade_as_nightly_cargo(&["per-package-target"]) |
| 1463 | + .env("BROWSER", tools::echo()) |
| 1464 | + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") |
| 1465 | + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") |
| 1466 | + .with_stderr_contains(&format!( |
| 1467 | + "[..] Opening [..]/target/{}/doc/bar/index.html", |
| 1468 | + target |
| 1469 | + )) |
| 1470 | + .run(); |
| 1471 | +} |
| 1472 | + |
| 1473 | +#[cargo_test] |
| 1474 | +fn doc_workspace_open_first_one_built_for_target() { |
| 1475 | + if cross_compile::disabled() { |
| 1476 | + return; |
| 1477 | + } |
| 1478 | + let target = cross_compile::alternate(); |
| 1479 | + |
| 1480 | + let p = project() |
| 1481 | + .file( |
| 1482 | + "Cargo.toml", |
| 1483 | + r#" |
| 1484 | + [workspace] |
| 1485 | + members = ["foo", "bar"] |
| 1486 | + "#, |
| 1487 | + ) |
| 1488 | + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) |
| 1489 | + .file("foo/src/lib.rs", "") |
| 1490 | + .file( |
| 1491 | + "bar/Cargo.toml", |
| 1492 | + &format!( |
| 1493 | + r#" |
| 1494 | + cargo-features = ["per-package-target"] |
| 1495 | + [package] |
| 1496 | + name = "bar" |
| 1497 | + version = "0.1.0" |
| 1498 | + forced-target = "{}" |
| 1499 | + "#, |
| 1500 | + target |
| 1501 | + ), |
| 1502 | + ) |
| 1503 | + .file("bar/src/lib.rs", "") |
| 1504 | + .build(); |
| 1505 | + |
| 1506 | + p.cargo("doc --workspace --open --target") |
| 1507 | + .arg(target) |
| 1508 | + .masquerade_as_nightly_cargo(&["per-package-target"]) |
| 1509 | + .env("BROWSER", tools::echo()) |
| 1510 | + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") |
| 1511 | + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") |
| 1512 | + .with_stderr_contains(&format!( |
| 1513 | + "[..] Opening [..]/target/{}/doc/bar/index.html", |
| 1514 | + target |
| 1515 | + )) |
| 1516 | + .run(); |
| 1517 | +} |
| 1518 | + |
| 1519 | +#[cargo_test] |
| 1520 | +fn doc_workspace_open_first_one_when_no_one_built_for_target() { |
| 1521 | + if cross_compile::disabled() { |
| 1522 | + return; |
| 1523 | + } |
| 1524 | + let target = cross_compile::alternate(); |
| 1525 | + |
| 1526 | + let p = project() |
| 1527 | + .file( |
| 1528 | + "Cargo.toml", |
| 1529 | + r#" |
| 1530 | + [workspace] |
| 1531 | + members = ["foo", "bar"] |
| 1532 | + "#, |
| 1533 | + ) |
| 1534 | + .file( |
| 1535 | + "foo/Cargo.toml", |
| 1536 | + &format!( |
| 1537 | + r#" |
| 1538 | + cargo-features = ["per-package-target"] |
| 1539 | + [package] |
| 1540 | + name = "foo" |
| 1541 | + version = "0.1.0" |
| 1542 | + forced-target = "{}" |
| 1543 | + "#, |
| 1544 | + target |
| 1545 | + ), |
| 1546 | + ) |
| 1547 | + .file("foo/src/lib.rs", "") |
| 1548 | + .file( |
| 1549 | + "bar/Cargo.toml", |
| 1550 | + &format!( |
| 1551 | + r#" |
| 1552 | + cargo-features = ["per-package-target"] |
| 1553 | + [package] |
| 1554 | + name = "bar" |
| 1555 | + version = "0.1.0" |
| 1556 | + forced-target = "{}" |
| 1557 | + "#, |
| 1558 | + target |
| 1559 | + ), |
| 1560 | + ) |
| 1561 | + .file("bar/src/lib.rs", "") |
| 1562 | + .build(); |
| 1563 | + |
| 1564 | + // We don't build for host, so we should open the first one built for TARGET. |
| 1565 | + let host_target = rustc_host(); |
| 1566 | + p.cargo("doc --workspace --open --target") |
| 1567 | + .arg(host_target) |
| 1568 | + .masquerade_as_nightly_cargo(&["per-package-target"]) |
| 1569 | + .env("BROWSER", tools::echo()) |
| 1570 | + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") |
| 1571 | + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") |
| 1572 | + .with_stderr_contains(&format!( |
| 1573 | + "[..] Opening [..]/target/{}/doc/bar/index.html", |
| 1574 | + target |
| 1575 | + )) |
| 1576 | + .run(); |
| 1577 | +} |
| 1578 | + |
1309 | 1579 | #[cargo_test(nightly, reason = "-Zextern-html-root-url is unstable")]
|
1310 | 1580 | fn doc_extern_map_local() {
|
1311 | 1581 | let p = project()
|
|
0 commit comments