Skip to content

Commit 8dd77a7

Browse files
committed
test(priv_dep): cargo-test-support support public dependency.
1 parent 10ff613 commit 8dd77a7

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

crates/cargo-test-support/src/registry.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ pub struct Dependency {
558558
package: Option<String>,
559559
optional: bool,
560560
default_features: bool,
561+
public: bool,
561562
}
562563

563564
/// Entry with data that corresponds to [`tar::EntryType`].
@@ -1678,6 +1679,7 @@ impl Dependency {
16781679
optional: false,
16791680
registry: None,
16801681
default_features: true,
1682+
public: false,
16811683
}
16821684
}
16831685

@@ -1731,6 +1733,12 @@ impl Dependency {
17311733
self
17321734
}
17331735

1736+
/// Changes this to an public dependency.
1737+
pub fn public(&mut self, public: bool) -> &mut Self {
1738+
self.public = public;
1739+
self
1740+
}
1741+
17341742
/// Adds `default-features = false` if the argument is `false`.
17351743
pub fn default_features(&mut self, default_features: bool) -> &mut Self {
17361744
self.default_features = default_features;

tests/testsuite/pub_priv.rs

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Tests for public/private dependencies.
22
33
use cargo_test_support::project;
4-
use cargo_test_support::registry::Package;
4+
use cargo_test_support::registry::{Dependency, Package};
55

66
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
77
fn exported_priv_warning() {
@@ -486,7 +486,8 @@ fn recursive_package_pub_no_warning() {
486486
.file("src/lib.rs", "pub struct FromPub;")
487487
.publish();
488488
Package::new("parent_bar", "0.1.0")
489-
.dep("grandparent_bar", "0.1.0")
489+
.cargo_feature("public-dependency")
490+
.add_dep(Dependency::new("grandparent_bar", "0.1.0").public(true))
490491
.file(
491492
"src/lib.rs",
492493
"
@@ -496,7 +497,8 @@ fn recursive_package_pub_no_warning() {
496497
)
497498
.publish();
498499
Package::new("pub_dep", "0.1.0")
499-
.dep("parent_bar", "0.1.0")
500+
.cargo_feature("public-dependency")
501+
.add_dep(Dependency::new("parent_bar", "0.1.0").public(true))
500502
.file(
501503
"src/lib.rs",
502504
"
@@ -530,18 +532,8 @@ fn recursive_package_pub_no_warning() {
530532

531533
p.cargo("check --message-format=short")
532534
.masquerade_as_nightly_cargo(&["public-dependency"])
533-
.with_stderr(
534-
"\
535-
[UPDATING] `[..]` index
536-
[DOWNLOADING] crates ...
537-
[DOWNLOADED] pub_dep v0.1.0 ([..])
538-
[DOWNLOADED] parent_bar v0.1.0 ([..])
539-
[DOWNLOADED] grandparent_bar v0.1.0 ([..])
540-
[CHECKING] grandparent_bar v0.1.0
541-
[CHECKING] parent_bar v0.1.0
542-
[CHECKING] pub_dep v0.1.0
543-
[CHECKING] foo v0.0.1 ([CWD])
544-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
535+
.with_stderr_contains(
536+
"src/lib.rs:3:13: warning: type `FromPub` from private dependency 'grandparent_bar' in public interface"
545537
)
546538
.run()
547539
}
@@ -552,7 +544,8 @@ fn recursive_package_priv_warning() {
552544
.file("src/lib.rs", "pub struct FromPriv;")
553545
.publish();
554546
Package::new("parent_bar", "0.1.0")
555-
.dep("grandparent_bar", "0.1.0")
547+
.cargo_feature("public-dependency")
548+
.add_dep(Dependency::new("grandparent_bar", "0.1.0").public(true))
556549
.file(
557550
"src/lib.rs",
558551
"
@@ -562,7 +555,8 @@ fn recursive_package_priv_warning() {
562555
)
563556
.publish();
564557
Package::new("priv_dep", "0.1.0")
565-
.dep("parent_bar", "0.1.0")
558+
.cargo_feature("public-dependency")
559+
.add_dep(Dependency::new("parent_bar", "0.1.0").public(true))
566560
.file(
567561
"src/lib.rs",
568562
"
@@ -596,18 +590,8 @@ fn recursive_package_priv_warning() {
596590

597591
p.cargo("check --message-format=short")
598592
.masquerade_as_nightly_cargo(&["public-dependency"])
599-
.with_stderr(
600-
"\
601-
[UPDATING] `[..]` index
602-
[DOWNLOADING] crates ...
603-
[DOWNLOADED] priv_dep v0.1.0 ([..])
604-
[DOWNLOADED] parent_bar v0.1.0 ([..])
605-
[DOWNLOADED] grandparent_bar v0.1.0 ([..])
606-
[CHECKING] grandparent_bar v0.1.0
607-
[CHECKING] parent_bar v0.1.0
608-
[CHECKING] priv_dep v0.1.0
609-
[CHECKING] foo v0.0.1 ([CWD])
610-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
593+
.with_stderr_contains(
594+
"src/lib.rs:3:13: warning: type `FromPriv` from private dependency 'grandparent_bar' in public interface"
611595
)
612596
.run()
613597
}

0 commit comments

Comments
 (0)