|
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()
|
@@ -1306,6 +1329,210 @@ fn doc_workspace_open_help_message() {
|
1306 | 1329 | .run();
|
1307 | 1330 | }
|
1308 | 1331 |
|
| 1332 | +#[cargo_test] |
| 1333 | +fn doc_workspace_open_first_one_built_for_host() { |
| 1334 | + if cross_compile::disabled() { |
| 1335 | + return; |
| 1336 | + } |
| 1337 | + let target = cross_compile::alternate(); |
| 1338 | + let p = project() |
| 1339 | + .file( |
| 1340 | + "Cargo.toml", |
| 1341 | + r#" |
| 1342 | + [workspace] |
| 1343 | + members = ["foo", "bar"] |
| 1344 | + "#, |
| 1345 | + ) |
| 1346 | + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) |
| 1347 | + .file("foo/src/lib.rs", "") |
| 1348 | + .file( |
| 1349 | + "bar/Cargo.toml", |
| 1350 | + &format!( |
| 1351 | + r#" |
| 1352 | + cargo-features = ["per-package-target"] |
| 1353 | + [package] |
| 1354 | + name = "bar" |
| 1355 | + version = "0.1.0" |
| 1356 | + forced-target = "{}" |
| 1357 | + "#, |
| 1358 | + target |
| 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] |
| 1374 | +fn doc_workspace_open_first_one_when_no_one_built_for_host() { |
| 1375 | + if cross_compile::disabled() { |
| 1376 | + return; |
| 1377 | + } |
| 1378 | + let target = cross_compile::alternate(); |
| 1379 | + |
| 1380 | + let p = project() |
| 1381 | + .file( |
| 1382 | + "Cargo.toml", |
| 1383 | + r#" |
| 1384 | + [workspace] |
| 1385 | + members = ["foo", "bar"] |
| 1386 | + "#, |
| 1387 | + ) |
| 1388 | + .file( |
| 1389 | + "foo/Cargo.toml", |
| 1390 | + &format!( |
| 1391 | + r#" |
| 1392 | + cargo-features = ["per-package-target"] |
| 1393 | + [package] |
| 1394 | + name = "foo" |
| 1395 | + version = "0.1.0" |
| 1396 | + forced-target = "{}" |
| 1397 | + "#, |
| 1398 | + target |
| 1399 | + ), |
| 1400 | + ) |
| 1401 | + .file("foo/src/lib.rs", "") |
| 1402 | + .file( |
| 1403 | + "bar/Cargo.toml", |
| 1404 | + &format!( |
| 1405 | + r#" |
| 1406 | + cargo-features = ["per-package-target"] |
| 1407 | + [package] |
| 1408 | + name = "bar" |
| 1409 | + version = "0.1.0" |
| 1410 | + forced-target = "{}" |
| 1411 | + "#, |
| 1412 | + target |
| 1413 | + ), |
| 1414 | + ) |
| 1415 | + .file("bar/src/lib.rs", "") |
| 1416 | + .build(); |
| 1417 | + |
| 1418 | + p.cargo("doc --workspace --open") |
| 1419 | + .masquerade_as_nightly_cargo(&["per-package-target"]) |
| 1420 | + .env("BROWSER", tools::echo()) |
| 1421 | + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") |
| 1422 | + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") |
| 1423 | + .with_stderr_contains(&format!( |
| 1424 | + "[..] Opening [..]/target/{}/doc/bar/index.html", |
| 1425 | + target |
| 1426 | + )) |
| 1427 | + .run(); |
| 1428 | +} |
| 1429 | + |
| 1430 | +#[cargo_test] |
| 1431 | +fn doc_workspace_open_first_one_built_for_target() { |
| 1432 | + if cross_compile::disabled() { |
| 1433 | + return; |
| 1434 | + } |
| 1435 | + let target = cross_compile::alternate(); |
| 1436 | + |
| 1437 | + let p = project() |
| 1438 | + .file( |
| 1439 | + "Cargo.toml", |
| 1440 | + r#" |
| 1441 | + [workspace] |
| 1442 | + members = ["foo", "bar"] |
| 1443 | + "#, |
| 1444 | + ) |
| 1445 | + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) |
| 1446 | + .file("foo/src/lib.rs", "") |
| 1447 | + .file( |
| 1448 | + "bar/Cargo.toml", |
| 1449 | + &format!( |
| 1450 | + r#" |
| 1451 | + cargo-features = ["per-package-target"] |
| 1452 | + [package] |
| 1453 | + name = "bar" |
| 1454 | + version = "0.1.0" |
| 1455 | + forced-target = "{}" |
| 1456 | + "#, |
| 1457 | + target |
| 1458 | + ), |
| 1459 | + ) |
| 1460 | + .file("bar/src/lib.rs", "") |
| 1461 | + .build(); |
| 1462 | + |
| 1463 | + p.cargo("doc --workspace --open --target") |
| 1464 | + .arg(target) |
| 1465 | + .masquerade_as_nightly_cargo(&["per-package-target"]) |
| 1466 | + .env("BROWSER", tools::echo()) |
| 1467 | + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") |
| 1468 | + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") |
| 1469 | + .with_stderr_contains(&format!( |
| 1470 | + "[..] Opening [..]/target/{}/doc/bar/index.html", |
| 1471 | + target |
| 1472 | + )) |
| 1473 | + .run(); |
| 1474 | +} |
| 1475 | + |
| 1476 | +#[cargo_test] |
| 1477 | +fn doc_workspace_open_first_one_when_no_one_built_for_target() { |
| 1478 | + if cross_compile::disabled() { |
| 1479 | + return; |
| 1480 | + } |
| 1481 | + let target = cross_compile::alternate(); |
| 1482 | + |
| 1483 | + let p = project() |
| 1484 | + .file( |
| 1485 | + "Cargo.toml", |
| 1486 | + r#" |
| 1487 | + [workspace] |
| 1488 | + members = ["foo", "bar"] |
| 1489 | + "#, |
| 1490 | + ) |
| 1491 | + .file( |
| 1492 | + "foo/Cargo.toml", |
| 1493 | + &format!( |
| 1494 | + r#" |
| 1495 | + cargo-features = ["per-package-target"] |
| 1496 | + [package] |
| 1497 | + name = "foo" |
| 1498 | + version = "0.1.0" |
| 1499 | + forced-target = "{}" |
| 1500 | + "#, |
| 1501 | + target |
| 1502 | + ), |
| 1503 | + ) |
| 1504 | + .file("foo/src/lib.rs", "") |
| 1505 | + .file( |
| 1506 | + "bar/Cargo.toml", |
| 1507 | + &format!( |
| 1508 | + r#" |
| 1509 | + cargo-features = ["per-package-target"] |
| 1510 | + [package] |
| 1511 | + name = "bar" |
| 1512 | + version = "0.1.0" |
| 1513 | + forced-target = "{}" |
| 1514 | + "#, |
| 1515 | + target |
| 1516 | + ), |
| 1517 | + ) |
| 1518 | + .file("bar/src/lib.rs", "") |
| 1519 | + .build(); |
| 1520 | + |
| 1521 | + // We don't build for host, so we should open the first one built for TARGET. |
| 1522 | + let host_target = rustc_host(); |
| 1523 | + p.cargo("doc --workspace --open --target") |
| 1524 | + .arg(host_target) |
| 1525 | + .masquerade_as_nightly_cargo(&["per-package-target"]) |
| 1526 | + .env("BROWSER", tools::echo()) |
| 1527 | + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") |
| 1528 | + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") |
| 1529 | + .with_stderr_contains(&format!( |
| 1530 | + "[..] Opening [..]/target/{}/doc/bar/index.html", |
| 1531 | + target |
| 1532 | + )) |
| 1533 | + .run(); |
| 1534 | +} |
| 1535 | + |
1309 | 1536 | #[cargo_test(nightly, reason = "-Zextern-html-root-url is unstable")]
|
1310 | 1537 | fn doc_extern_map_local() {
|
1311 | 1538 | let p = project()
|
|
0 commit comments