Skip to content

Commit d5fa7e2

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

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

tests/testsuite/pub_priv.rs

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,138 @@ 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_module_pub_no_warning() {
485+
Package::new("pub_dep", "0.1.0")
486+
.file(
487+
"src/lib.rs",
488+
"
489+
mod pub_bar;
490+
pub use self::pub_bar::*;
491+
",
492+
)
493+
.file(
494+
"src/pub_bar/mod.rs",
495+
"
496+
mod parent_bar;
497+
pub use self::parent_bar::*;
498+
",
499+
)
500+
.file(
501+
"src/pub_bar/parent_bar/mod.rs",
502+
"
503+
mod grandparent_bar;
504+
pub use self::grandparent_bar::*;
505+
",
506+
)
507+
.file(
508+
"src/pub_bar/parent_bar/grandparent_bar/mod.rs",
509+
"
510+
pub struct FromPub;
511+
",
512+
)
513+
.publish();
514+
515+
let p = project()
516+
.file(
517+
"Cargo.toml",
518+
r#"
519+
cargo-features = ["public-dependency"]
520+
521+
[package]
522+
name = "foo"
523+
version = "0.0.1"
524+
525+
[dependencies]
526+
pub_dep = {version = "0.1.0", public = true}
527+
"#,
528+
)
529+
.file(
530+
"src/lib.rs",
531+
"
532+
extern crate pub_dep;
533+
pub fn use_pub(_: pub_dep::FromPub) {}
534+
",
535+
)
536+
.build();
537+
538+
p.cargo("check --message-format=short")
539+
.masquerade_as_nightly_cargo(&["public-dependency"])
540+
.with_stderr(
541+
"\
542+
[UPDATING] `[..]` index
543+
[DOWNLOADING] crates ...
544+
[DOWNLOADED] pub_dep v0.1.0 ([..])
545+
[CHECKING] pub_dep v0.1.0
546+
[CHECKING] foo v0.0.1 ([CWD])
547+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
548+
)
549+
.run()
550+
}
551+
552+
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
553+
fn recursive_package_pub_no_warning() {
554+
Package::new("grandparent_bar", "0.1.0")
555+
.file("src/lib.rs", "pub struct FromPub;")
556+
.publish();
557+
Package::new("parent_bar", "0.1.0")
558+
.dep("grandparent_bar", "0.1.0")
559+
.file(
560+
"src/lib.rs",
561+
"
562+
extern crate grandparent_bar;
563+
pub use grandparent_bar::*;
564+
",
565+
)
566+
.publish();
567+
Package::new("pub_dep", "0.1.0")
568+
.dep("parent_bar", "0.1.0")
569+
.file(
570+
"src/lib.rs",
571+
"
572+
extern crate parent_bar;
573+
pub use parent_bar::*;
574+
",
575+
)
576+
.publish();
577+
let p = project()
578+
.file(
579+
"Cargo.toml",
580+
r#"
581+
cargo-features = ["public-dependency"]
582+
583+
[package]
584+
name = "foo"
585+
version = "0.0.1"
586+
587+
[dependencies]
588+
pub_dep = {version = "0.1.0", public = true}
589+
"#,
590+
)
591+
.file(
592+
"src/lib.rs",
593+
"
594+
extern crate pub_dep;
595+
pub fn use_pub(_: pub_dep::FromPub) {}
596+
",
597+
)
598+
.build();
599+
600+
p.cargo("check")
601+
.masquerade_as_nightly_cargo(&["public-dependency"])
602+
.with_stderr(
603+
"\
604+
[UPDATING] `[..]` index
605+
[DOWNLOADING] crates ...
606+
[DOWNLOADED] pub_dep v0.1.0 ([..])
607+
[DOWNLOADED] parent_bar v0.1.0 ([..])
608+
[DOWNLOADED] grandparent_bar v0.1.0 ([..])
609+
[CHECKING] grandparent_bar v0.1.0
610+
[CHECKING] parent_bar v0.1.0
611+
[CHECKING] pub_dep v0.1.0
612+
[CHECKING] foo v0.0.1 ([CWD])
613+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
614+
)
615+
.run()
616+
}

0 commit comments

Comments
 (0)