Skip to content

Commit 10ff613

Browse files
committed
test(priv_dep): add test for verify public is respected recursively
1 parent 1a2666d commit 10ff613

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

tests/testsuite/pub_priv.rs

+132
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,135 @@ fn allow_priv_in_custom_build() {
479479
)
480480
.run()
481481
}
482+
483+
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
484+
fn recursive_package_pub_no_warning() {
485+
Package::new("grandparent_bar", "0.1.0")
486+
.file("src/lib.rs", "pub struct FromPub;")
487+
.publish();
488+
Package::new("parent_bar", "0.1.0")
489+
.dep("grandparent_bar", "0.1.0")
490+
.file(
491+
"src/lib.rs",
492+
"
493+
extern crate grandparent_bar;
494+
pub use grandparent_bar::*;
495+
",
496+
)
497+
.publish();
498+
Package::new("pub_dep", "0.1.0")
499+
.dep("parent_bar", "0.1.0")
500+
.file(
501+
"src/lib.rs",
502+
"
503+
extern crate parent_bar;
504+
pub use parent_bar::*;
505+
",
506+
)
507+
.publish();
508+
let p = project()
509+
.file(
510+
"Cargo.toml",
511+
r#"
512+
cargo-features = ["public-dependency"]
513+
514+
[package]
515+
name = "foo"
516+
version = "0.0.1"
517+
518+
[dependencies]
519+
pub_dep = {version = "0.1.0", public = true}
520+
"#,
521+
)
522+
.file(
523+
"src/lib.rs",
524+
"
525+
extern crate pub_dep;
526+
pub fn use_pub(_: pub_dep::FromPub) {}
527+
",
528+
)
529+
.build();
530+
531+
p.cargo("check --message-format=short")
532+
.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 [..]",
545+
)
546+
.run()
547+
}
548+
549+
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
550+
fn recursive_package_priv_warning() {
551+
Package::new("grandparent_bar", "0.1.0")
552+
.file("src/lib.rs", "pub struct FromPriv;")
553+
.publish();
554+
Package::new("parent_bar", "0.1.0")
555+
.dep("grandparent_bar", "0.1.0")
556+
.file(
557+
"src/lib.rs",
558+
"
559+
extern crate grandparent_bar;
560+
pub use grandparent_bar::*;
561+
",
562+
)
563+
.publish();
564+
Package::new("priv_dep", "0.1.0")
565+
.dep("parent_bar", "0.1.0")
566+
.file(
567+
"src/lib.rs",
568+
"
569+
extern crate parent_bar;
570+
pub use parent_bar::*;
571+
",
572+
)
573+
.publish();
574+
let p = project()
575+
.file(
576+
"Cargo.toml",
577+
r#"
578+
cargo-features = ["public-dependency"]
579+
580+
[package]
581+
name = "foo"
582+
version = "0.0.1"
583+
584+
[dependencies]
585+
priv_dep = "0.1.0"
586+
"#,
587+
)
588+
.file(
589+
"src/lib.rs",
590+
"
591+
extern crate priv_dep;
592+
pub fn use_pub(_: priv_dep::FromPriv) {}
593+
",
594+
)
595+
.build();
596+
597+
p.cargo("check --message-format=short")
598+
.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 [..]",
611+
)
612+
.run()
613+
}

0 commit comments

Comments
 (0)