|
1 | 1 | //! Tests for public/private dependencies.
|
2 | 2 |
|
3 | 3 | use cargo_test_support::project;
|
4 |
| -use cargo_test_support::registry::Package; |
| 4 | +use cargo_test_support::registry::{Dependency, Package}; |
5 | 5 |
|
6 | 6 | #[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
|
7 | 7 | fn exported_priv_warning() {
|
@@ -479,3 +479,220 @@ fn allow_priv_in_custom_build() {
|
479 | 479 | )
|
480 | 480 | .run()
|
481 | 481 | }
|
| 482 | + |
| 483 | +// A indirectly add D as private dependency. |
| 484 | +// A -> B -> C -> D |
| 485 | +#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")] |
| 486 | +fn recursive_package_pub_no_warning() { |
| 487 | + Package::new("grandparent_bar", "0.1.0") |
| 488 | + .file("src/lib.rs", "pub struct FromPub;") |
| 489 | + .publish(); |
| 490 | + Package::new("parent_bar", "0.1.0") |
| 491 | + .cargo_feature("public-dependency") |
| 492 | + .add_dep(Dependency::new("grandparent_bar", "0.1.0").public(true)) |
| 493 | + .file( |
| 494 | + "src/lib.rs", |
| 495 | + " |
| 496 | + extern crate grandparent_bar; |
| 497 | + pub use grandparent_bar::*; |
| 498 | + ", |
| 499 | + ) |
| 500 | + .publish(); |
| 501 | + Package::new("pub_dep", "0.1.0") |
| 502 | + .cargo_feature("public-dependency") |
| 503 | + .add_dep(Dependency::new("parent_bar", "0.1.0").public(true)) |
| 504 | + .file( |
| 505 | + "src/lib.rs", |
| 506 | + " |
| 507 | + extern crate parent_bar; |
| 508 | + pub use parent_bar::*; |
| 509 | + ", |
| 510 | + ) |
| 511 | + .publish(); |
| 512 | + let p = project() |
| 513 | + .file( |
| 514 | + "Cargo.toml", |
| 515 | + r#" |
| 516 | + cargo-features = ["public-dependency"] |
| 517 | +
|
| 518 | + [package] |
| 519 | + name = "foo" |
| 520 | + version = "0.0.1" |
| 521 | +
|
| 522 | + [dependencies] |
| 523 | + pub_dep = {version = "0.1.0", public = true} |
| 524 | + "#, |
| 525 | + ) |
| 526 | + .file( |
| 527 | + "src/lib.rs", |
| 528 | + " |
| 529 | + extern crate pub_dep; |
| 530 | + pub fn use_pub(_: pub_dep::FromPub) {} |
| 531 | + ", |
| 532 | + ) |
| 533 | + .build(); |
| 534 | + |
| 535 | + p.cargo("check --message-format=short") |
| 536 | + .masquerade_as_nightly_cargo(&["public-dependency"]) |
| 537 | + .with_stderr( |
| 538 | + "\ |
| 539 | +[UPDATING] `[..]` index |
| 540 | +[DOWNLOADING] crates ... |
| 541 | +[DOWNLOADED] pub_dep v0.1.0 ([..]) |
| 542 | +[DOWNLOADED] parent_bar v0.1.0 ([..]) |
| 543 | +[DOWNLOADED] grandparent_bar v0.1.0 ([..]) |
| 544 | +[CHECKING] grandparent_bar v0.1.0 |
| 545 | +[CHECKING] parent_bar v0.1.0 |
| 546 | +[CHECKING] pub_dep v0.1.0 |
| 547 | +[CHECKING] foo v0.0.1 ([..]) |
| 548 | +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] |
| 549 | +", |
| 550 | + ) |
| 551 | + .run() |
| 552 | +} |
| 553 | + |
| 554 | +// A indirectly add D as private dependency. |
| 555 | +// A -> B -> C -> D |
| 556 | +#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")] |
| 557 | +fn recursive_package_priv_warning() { |
| 558 | + Package::new("grandparent_bar", "0.1.0") |
| 559 | + .file("src/lib.rs", "pub struct FromPriv;") |
| 560 | + .publish(); |
| 561 | + Package::new("parent_bar", "0.1.0") |
| 562 | + .cargo_feature("public-dependency") |
| 563 | + .add_dep(Dependency::new("grandparent_bar", "0.1.0").public(true)) |
| 564 | + .file( |
| 565 | + "src/lib.rs", |
| 566 | + " |
| 567 | + extern crate grandparent_bar; |
| 568 | + pub use grandparent_bar::*; |
| 569 | + ", |
| 570 | + ) |
| 571 | + .publish(); |
| 572 | + Package::new("priv_dep", "0.1.0") |
| 573 | + .cargo_feature("public-dependency") |
| 574 | + .add_dep(Dependency::new("parent_bar", "0.1.0").public(true)) |
| 575 | + .file( |
| 576 | + "src/lib.rs", |
| 577 | + " |
| 578 | + extern crate parent_bar; |
| 579 | + pub use parent_bar::*; |
| 580 | + ", |
| 581 | + ) |
| 582 | + .publish(); |
| 583 | + let p = project() |
| 584 | + .file( |
| 585 | + "Cargo.toml", |
| 586 | + r#" |
| 587 | + cargo-features = ["public-dependency"] |
| 588 | +
|
| 589 | + [package] |
| 590 | + name = "foo" |
| 591 | + version = "0.0.1" |
| 592 | +
|
| 593 | + [dependencies] |
| 594 | + priv_dep = "0.1.0" |
| 595 | + "#, |
| 596 | + ) |
| 597 | + .file( |
| 598 | + "src/lib.rs", |
| 599 | + " |
| 600 | + extern crate priv_dep; |
| 601 | + pub fn use_pub(_: priv_dep::FromPriv) {} |
| 602 | + ", |
| 603 | + ) |
| 604 | + .build(); |
| 605 | + |
| 606 | + p.cargo("check --message-format=short") |
| 607 | + .masquerade_as_nightly_cargo(&["public-dependency"]) |
| 608 | + .with_stderr( |
| 609 | + "\ |
| 610 | +[UPDATING] `[..]` index |
| 611 | +[DOWNLOADING] crates ... |
| 612 | +[DOWNLOADED] priv_dep v0.1.0 ([..]) |
| 613 | +[DOWNLOADED] parent_bar v0.1.0 ([..]) |
| 614 | +[DOWNLOADED] grandparent_bar v0.1.0 ([..]) |
| 615 | +[CHECKING] grandparent_bar v0.1.0 |
| 616 | +[CHECKING] parent_bar v0.1.0 |
| 617 | +[CHECKING] priv_dep v0.1.0 |
| 618 | +[CHECKING] foo v0.0.1 ([..]) |
| 619 | +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] |
| 620 | +", |
| 621 | + ) |
| 622 | + .run() |
| 623 | +} |
| 624 | + |
| 625 | +// A indirectly add D as public dependency, then directly add D as private dependency. |
| 626 | +// A -> B -> C -> D |
| 627 | +// \ _ _ _ _ _ /|\ |
| 628 | +#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")] |
| 629 | +fn recursive_package_pub_priv_together() { |
| 630 | + Package::new("grandparent_bar", "0.1.0") |
| 631 | + .file("src/lib.rs", "pub struct FromPriv;") |
| 632 | + .publish(); |
| 633 | + Package::new("parent_bar", "0.1.0") |
| 634 | + .cargo_feature("public-dependency") |
| 635 | + .add_dep(Dependency::new("grandparent_bar", "0.1.0").public(true)) |
| 636 | + .file( |
| 637 | + "src/lib.rs", |
| 638 | + " |
| 639 | + extern crate grandparent_bar; |
| 640 | + pub use grandparent_bar::*; |
| 641 | + ", |
| 642 | + ) |
| 643 | + .publish(); |
| 644 | + Package::new("pub_dep", "0.1.0") |
| 645 | + .cargo_feature("public-dependency") |
| 646 | + .add_dep(Dependency::new("parent_bar", "0.1.0").public(true)) |
| 647 | + .file( |
| 648 | + "src/lib.rs", |
| 649 | + " |
| 650 | + extern crate parent_bar; |
| 651 | + pub use parent_bar::*; |
| 652 | + ", |
| 653 | + ) |
| 654 | + .publish(); |
| 655 | + let p = project() |
| 656 | + .file( |
| 657 | + "Cargo.toml", |
| 658 | + r#" |
| 659 | + cargo-features = ["public-dependency"] |
| 660 | +
|
| 661 | + [package] |
| 662 | + name = "foo" |
| 663 | + version = "0.0.1" |
| 664 | +
|
| 665 | + [dependencies] |
| 666 | + pub_dep = {version = "0.1.0", public = true} |
| 667 | + grandparent_bar = "0.1.0" |
| 668 | + "#, |
| 669 | + ) |
| 670 | + .file( |
| 671 | + "src/lib.rs", |
| 672 | + " |
| 673 | + extern crate pub_dep; |
| 674 | + extern crate grandparent_bar; |
| 675 | +
|
| 676 | + pub fn use_pub(_: grandparent_bar::FromPriv) {} |
| 677 | + ", |
| 678 | + ) |
| 679 | + .build(); |
| 680 | + |
| 681 | + p.cargo("check --message-format=short") |
| 682 | + .masquerade_as_nightly_cargo(&["public-dependency"]) |
| 683 | + .with_stderr( |
| 684 | + "\ |
| 685 | +[UPDATING] `[..]` index |
| 686 | +[DOWNLOADING] crates ... |
| 687 | +[DOWNLOADED] pub_dep v0.1.0 ([..]) |
| 688 | +[DOWNLOADED] parent_bar v0.1.0 ([..]) |
| 689 | +[DOWNLOADED] grandparent_bar v0.1.0 ([..]) |
| 690 | +[CHECKING] grandparent_bar v0.1.0 |
| 691 | +[CHECKING] parent_bar v0.1.0 |
| 692 | +[CHECKING] pub_dep v0.1.0 |
| 693 | +[CHECKING] foo v0.0.1 ([..]) |
| 694 | +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] |
| 695 | +", |
| 696 | + ) |
| 697 | + .run() |
| 698 | +} |
0 commit comments