@@ -4029,3 +4029,253 @@ fn mergeable_info_dep_collision() {
40294029 // ...and the fingerprint content are different (path to dep.json different)
40304030 assert_ne ! ( first_fingerprint, second_fingerprint) ;
40314031}
4032+
4033+ #[ cargo_test( nightly, reason = "public-dependency feature is unstable" ) ]
4034+ fn doc_with_public_dependency_transitive ( ) {
4035+ // foo is the selected package
4036+ // bar is a direct dep of foo
4037+ // baz is a public dep of bar
4038+ // qux is a public dep of baz
4039+
4040+ Package :: new ( "qux" , "0.0.1" )
4041+ . file ( "src/lib.rs" , "pub fn qux() {}" )
4042+ . publish ( ) ;
4043+
4044+ Package :: new ( "baz" , "0.0.1" )
4045+ . cargo_feature ( "public-dependency" )
4046+ . add_dep ( cargo_test_support:: registry:: Dependency :: new ( "qux" , "0.0.1" ) . public ( true ) )
4047+ . file ( "src/lib.rs" , "pub fn baz() {}" )
4048+ . publish ( ) ;
4049+
4050+ Package :: new ( "bar" , "0.0.1" )
4051+ . cargo_feature ( "public-dependency" )
4052+ . add_dep ( cargo_test_support:: registry:: Dependency :: new ( "baz" , "0.0.1" ) . public ( true ) )
4053+ . file ( "src/lib.rs" , "pub fn bar() {}" )
4054+ . publish ( ) ;
4055+
4056+ let p = project ( )
4057+ . file (
4058+ "Cargo.toml" ,
4059+ r#"
4060+ cargo-features = ["public-dependency"]
4061+
4062+ [package]
4063+ name = "foo"
4064+ version = "0.0.1"
4065+ edition = "2021"
4066+
4067+ [dependencies]
4068+ bar = "0.0.1"
4069+ "# ,
4070+ )
4071+ . file ( "src/lib.rs" , "pub fn foo() {}" )
4072+ . build ( ) ;
4073+
4074+ p. cargo ( "doc -Zpublic-dependency" )
4075+ . masquerade_as_nightly_cargo ( & [ "public-dependency" ] )
4076+ . with_stderr_data (
4077+ str![ [ r#"
4078+ [UPDATING] `dummy-registry` index
4079+ [LOCKING] 3 packages to latest compatible versions
4080+ [DOWNLOADING] crates ...
4081+ [DOWNLOADED] qux v0.0.1 (registry `dummy-registry`)
4082+ [DOWNLOADED] baz v0.0.1 (registry `dummy-registry`)
4083+ [DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
4084+ [DOCUMENTING] qux v0.0.1
4085+ [CHECKING] qux v0.0.1
4086+ [DOCUMENTING] baz v0.0.1
4087+ [CHECKING] baz v0.0.1
4088+ [DOCUMENTING] bar v0.0.1
4089+ [CHECKING] bar v0.0.1
4090+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
4091+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
4092+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
4093+
4094+ "# ] ]
4095+ . unordered ( ) ,
4096+ )
4097+ . run ( ) ;
4098+
4099+ // All four are documented: the whole chain is public.
4100+ assert ! ( p. root( ) . join( "target/doc/foo/index.html" ) . is_file( ) ) ;
4101+ assert ! ( p. root( ) . join( "target/doc/bar/index.html" ) . is_file( ) ) ;
4102+ assert ! ( p. root( ) . join( "target/doc/baz/index.html" ) . is_file( ) ) ;
4103+ assert ! ( p. root( ) . join( "target/doc/qux/index.html" ) . is_file( ) ) ;
4104+ }
4105+
4106+ #[ cargo_test( nightly, reason = "public-dependency feature is unstable" ) ]
4107+ fn doc_direct_deps_always_documented ( ) {
4108+ // Direct dependencies should always be documented regardless of public flag
4109+ // foo -> bar (public=true), baz (public=false)
4110+ // Both bar and baz should be documented since they are direct deps
4111+
4112+ Package :: new ( "bar" , "0.0.1" )
4113+ . file ( "src/lib.rs" , "pub fn bar() {}" )
4114+ . publish ( ) ;
4115+
4116+ Package :: new ( "baz" , "0.0.1" )
4117+ . file ( "src/lib.rs" , "pub fn baz() {}" )
4118+ . publish ( ) ;
4119+
4120+ let p = project ( )
4121+ . file (
4122+ "Cargo.toml" ,
4123+ r#"
4124+ cargo-features = ["public-dependency"]
4125+
4126+ [package]
4127+ name = "foo"
4128+ version = "0.0.1"
4129+ edition = "2021"
4130+
4131+ [dependencies]
4132+ bar = { version = "0.0.1", public = true }
4133+ baz = { version = "0.0.1", public = false }
4134+ "# ,
4135+ )
4136+ . file ( "src/lib.rs" , "pub fn foo() {}" )
4137+ . build ( ) ;
4138+
4139+ p. cargo ( "doc -Zpublic-dependency" )
4140+ . masquerade_as_nightly_cargo ( & [ "public-dependency" ] )
4141+ . with_stderr_data (
4142+ str![ [ r#"
4143+ [UPDATING] `dummy-registry` index
4144+ [LOCKING] 2 packages to latest compatible versions
4145+ [DOWNLOADING] crates ...
4146+ [DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
4147+ [DOWNLOADED] baz v0.0.1 (registry `dummy-registry`)
4148+ [DOCUMENTING] bar v0.0.1
4149+ [CHECKING] bar v0.0.1
4150+ [DOCUMENTING] baz v0.0.1
4151+ [CHECKING] baz v0.0.1
4152+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
4153+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
4154+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
4155+
4156+ "# ] ]
4157+ . unordered ( ) ,
4158+ )
4159+ . run ( ) ;
4160+
4161+ // Both direct deps should be documented
4162+ assert ! ( p. root( ) . join( "target/doc/foo/index.html" ) . is_file( ) ) ;
4163+ assert ! ( p. root( ) . join( "target/doc/bar/index.html" ) . is_file( ) ) ;
4164+ assert ! ( p. root( ) . join( "target/doc/baz/index.html" ) . is_file( ) ) ;
4165+ }
4166+
4167+ #[ cargo_test( nightly, reason = "public-dependency feature is unstable" ) ]
4168+ fn doc_with_private_dependency ( ) {
4169+ // foo -> bar (direct dep) -> baz (transitive private dep of bar)
4170+
4171+ Package :: new ( "baz" , "0.0.1" )
4172+ . file ( "src/lib.rs" , "pub fn baz() {}" )
4173+ . publish ( ) ;
4174+
4175+ Package :: new ( "bar" , "0.0.1" )
4176+ . cargo_feature ( "public-dependency" )
4177+ . add_dep ( cargo_test_support:: registry:: Dependency :: new ( "baz" , "0.0.1" ) . public ( false ) )
4178+ . file ( "src/lib.rs" , "pub fn bar() {}" )
4179+ . publish ( ) ;
4180+
4181+ let p = project ( )
4182+ . file (
4183+ "Cargo.toml" ,
4184+ r#"
4185+ cargo-features = ["public-dependency"]
4186+
4187+ [package]
4188+ name = "foo"
4189+ version = "0.0.1"
4190+ edition = "2021"
4191+
4192+ [dependencies]
4193+ bar = "0.0.1"
4194+ "# ,
4195+ )
4196+ . file ( "src/lib.rs" , "pub fn foo() {}" )
4197+ . build ( ) ;
4198+
4199+ p. cargo ( "doc -Zpublic-dependency" )
4200+ . masquerade_as_nightly_cargo ( & [ "public-dependency" ] )
4201+ . with_stderr_data (
4202+ str![ [ r#"
4203+ [UPDATING] `dummy-registry` index
4204+ [LOCKING] 2 packages to latest compatible versions
4205+ [DOWNLOADING] crates ...
4206+ [DOWNLOADED] baz v0.0.1 (registry `dummy-registry`)
4207+ [DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
4208+ [DOCUMENTING] baz v0.0.1
4209+ [CHECKING] baz v0.0.1
4210+ [DOCUMENTING] bar v0.0.1
4211+ [CHECKING] bar v0.0.1
4212+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
4213+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
4214+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
4215+
4216+ "# ] ]
4217+ . unordered ( ) ,
4218+ )
4219+ . run ( ) ;
4220+
4221+ assert ! ( p. root( ) . join( "target/doc/foo/index.html" ) . is_file( ) ) ;
4222+ assert ! ( p. root( ) . join( "target/doc/bar/index.html" ) . is_file( ) ) ;
4223+ assert ! ( p. root( ) . join( "target/doc/baz/index.html" ) . is_file( ) ) ;
4224+ }
4225+
4226+ #[ cargo_test( nightly, reason = "public-dependency feature is unstable" ) ]
4227+ fn doc_mixed_public_private_deps ( ) {
4228+ // foo -> pub_dep (public), priv_dep (private), priv_dep_with_dep (unannotated)
4229+ // priv_dep_with_dep -> transitive
4230+
4231+ Package :: new ( "pub_dep" , "0.0.1" )
4232+ . file ( "src/lib.rs" , "pub fn pub_dep() {}" )
4233+ . publish ( ) ;
4234+
4235+ Package :: new ( "priv_dep" , "0.0.1" )
4236+ . file ( "src/lib.rs" , "pub fn priv_dep() {}" )
4237+ . publish ( ) ;
4238+
4239+ Package :: new ( "transitive" , "0.0.1" )
4240+ . file ( "src/lib.rs" , "pub fn transitive() {}" )
4241+ . publish ( ) ;
4242+
4243+ Package :: new ( "priv_dep_with_dep" , "0.0.1" )
4244+ . dep ( "transitive" , "0.0.1" )
4245+ . file ( "src/lib.rs" , "pub fn priv_dep_with_dep() {}" )
4246+ . publish ( ) ;
4247+
4248+ let p = project ( )
4249+ . file (
4250+ "Cargo.toml" ,
4251+ r#"
4252+ cargo-features = ["public-dependency"]
4253+
4254+ [package]
4255+ name = "foo"
4256+ version = "0.0.1"
4257+ edition = "2021"
4258+
4259+ [dependencies]
4260+ pub_dep = { version = "0.0.1", public = true }
4261+ priv_dep = { version = "0.0.1", public = false }
4262+ priv_dep_with_dep = "0.0.1"
4263+ "# ,
4264+ )
4265+ . file ( "src/lib.rs" , "pub fn foo() {}" )
4266+ . build ( ) ;
4267+
4268+ p. cargo ( "doc -Zpublic-dependency" )
4269+ . masquerade_as_nightly_cargo ( & [ "public-dependency" ] )
4270+ . run ( ) ;
4271+
4272+ assert ! ( p. root( ) . join( "target/doc/foo/index.html" ) . is_file( ) ) ;
4273+ assert ! ( p. root( ) . join( "target/doc/pub_dep/index.html" ) . is_file( ) ) ;
4274+ assert ! ( p. root( ) . join( "target/doc/priv_dep/index.html" ) . is_file( ) ) ;
4275+ assert ! (
4276+ p. root( )
4277+ . join( "target/doc/priv_dep_with_dep/index.html" )
4278+ . is_file( )
4279+ ) ;
4280+ assert ! ( p. root( ) . join( "target/doc/transitive/index.html" ) . is_file( ) ) ;
4281+ }
0 commit comments