@@ -4029,3 +4029,254 @@ 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+ // Tests recursive public dependency documentation with 2 layers
4036+ // foo -> bar (direct) -> baz (public) -> qux (public)
4037+ // foo and bar should be documented (direct deps)
4038+ // baz should be documented (public dep of direct dep bar)
4039+ // qux should be documented (public dep of public dep baz)
4040+
4041+ Package :: new ( "qux" , "0.0.1" )
4042+ . file ( "src/lib.rs" , "pub fn qux() {}" )
4043+ . publish ( ) ;
4044+
4045+ Package :: new ( "baz" , "0.0.1" )
4046+ . cargo_feature ( "public-dependency" )
4047+ . add_dep ( cargo_test_support:: registry:: Dependency :: new ( "qux" , "0.0.1" ) . public ( true ) )
4048+ . file ( "src/lib.rs" , "pub fn baz() {}" )
4049+ . publish ( ) ;
4050+
4051+ Package :: new ( "bar" , "0.0.1" )
4052+ . cargo_feature ( "public-dependency" )
4053+ . add_dep ( cargo_test_support:: registry:: Dependency :: new ( "baz" , "0.0.1" ) . public ( true ) )
4054+ . file ( "src/lib.rs" , "pub fn bar() {}" )
4055+ . publish ( ) ;
4056+
4057+ let p = project ( )
4058+ . file (
4059+ "Cargo.toml" ,
4060+ r#"
4061+ cargo-features = ["public-dependency"]
4062+
4063+ [package]
4064+ name = "foo"
4065+ version = "0.0.1"
4066+ edition = "2021"
4067+
4068+ [dependencies]
4069+ bar = "0.0.1"
4070+ "# ,
4071+ )
4072+ . file ( "src/lib.rs" , "pub fn foo() {}" )
4073+ . build ( ) ;
4074+
4075+ p. cargo ( "doc -Zpublic-dependency" )
4076+ . masquerade_as_nightly_cargo ( & [ "public-dependency" ] )
4077+ . with_stderr_data (
4078+ str![ [ r#"
4079+ [UPDATING] `dummy-registry` index
4080+ [LOCKING] 3 packages to latest compatible versions
4081+ [DOWNLOADING] crates ...
4082+ [DOWNLOADED] qux v0.0.1 (registry `dummy-registry`)
4083+ [DOWNLOADED] baz v0.0.1 (registry `dummy-registry`)
4084+ [DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
4085+ [DOCUMENTING] qux v0.0.1
4086+ [CHECKING] qux v0.0.1
4087+ [DOCUMENTING] baz v0.0.1
4088+ [CHECKING] baz v0.0.1
4089+ [DOCUMENTING] bar v0.0.1
4090+ [CHECKING] bar v0.0.1
4091+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
4092+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
4093+ [GENERATED] [ROOT]/foo/target/doc/foo/index.html
4094+
4095+ "# ] ]
4096+ . unordered ( ) ,
4097+ )
4098+ . run ( ) ;
4099+
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 (any) -> baz (private)
4170+ // Only foo and bar documented, not baz (transitive private dep)
4171+
4172+ Package :: new ( "baz" , "0.0.1" )
4173+ . file ( "src/lib.rs" , "pub fn baz() {}" )
4174+ . publish ( ) ;
4175+
4176+ Package :: new ( "bar" , "0.0.1" )
4177+ . cargo_feature ( "public-dependency" )
4178+ . add_dep ( cargo_test_support:: registry:: Dependency :: new ( "baz" , "0.0.1" ) . public ( false ) )
4179+ . file ( "src/lib.rs" , "pub fn bar() {}" )
4180+ . publish ( ) ;
4181+
4182+ let p = project ( )
4183+ . file (
4184+ "Cargo.toml" ,
4185+ r#"
4186+ cargo-features = ["public-dependency"]
4187+
4188+ [package]
4189+ name = "foo"
4190+ version = "0.0.1"
4191+ edition = "2021"
4192+
4193+ [dependencies]
4194+ bar = "0.0.1"
4195+ "# ,
4196+ )
4197+ . file ( "src/lib.rs" , "pub fn foo() {}" )
4198+ . build ( ) ;
4199+
4200+ p. cargo ( "doc -Zpublic-dependency" )
4201+ . masquerade_as_nightly_cargo ( & [ "public-dependency" ] )
4202+ . with_stderr_data (
4203+ str![ [ r#"
4204+ [UPDATING] `dummy-registry` index
4205+ [LOCKING] 2 packages to latest compatible versions
4206+ [DOWNLOADING] crates ...
4207+ [DOWNLOADED] baz v0.0.1 (registry `dummy-registry`)
4208+ [DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
4209+ [DOCUMENTING] bar v0.0.1
4210+ [CHECKING] baz 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+ // Tests mixed public and private dependencies
4229+ Package :: new ( "pub_dep" , "0.0.1" )
4230+ . file ( "src/lib.rs" , "pub fn pub_dep() {}" )
4231+ . publish ( ) ;
4232+
4233+ Package :: new ( "priv_dep" , "0.0.1" )
4234+ . file ( "src/lib.rs" , "pub fn priv_dep() {}" )
4235+ . publish ( ) ;
4236+
4237+ Package :: new ( "transitive" , "0.0.1" )
4238+ . file ( "src/lib.rs" , "pub fn transitive() {}" )
4239+ . publish ( ) ;
4240+
4241+ Package :: new ( "priv_dep_with_dep" , "0.0.1" )
4242+ . dep ( "transitive" , "0.0.1" )
4243+ . file ( "src/lib.rs" , "pub fn priv_dep_with_dep() {}" )
4244+ . publish ( ) ;
4245+
4246+ let p = project ( )
4247+ . file (
4248+ "Cargo.toml" ,
4249+ r#"
4250+ cargo-features = ["public-dependency"]
4251+
4252+ [package]
4253+ name = "foo"
4254+ version = "0.0.1"
4255+ edition = "2021"
4256+
4257+ [dependencies]
4258+ pub_dep = { version = "0.0.1", public = true }
4259+ priv_dep = { version = "0.0.1", public = false }
4260+ priv_dep_with_dep = "0.0.1"
4261+ "# ,
4262+ )
4263+ . file ( "src/lib.rs" , "pub fn foo() {}" )
4264+ . build ( ) ;
4265+
4266+ p. cargo ( "doc -Zpublic-dependency" )
4267+ . masquerade_as_nightly_cargo ( & [ "public-dependency" ] )
4268+ . run ( ) ;
4269+
4270+ // Direct deps documented, transitive private deps not documented
4271+ assert ! ( p. root( ) . join( "target/doc/foo/index.html" ) . is_file( ) ) ;
4272+ assert ! ( p. root( ) . join( "target/doc/pub_dep/index.html" ) . is_file( ) ) ;
4273+ assert ! ( p. root( ) . join( "target/doc/priv_dep/index.html" ) . is_file( ) ) ;
4274+ assert ! (
4275+ p. root( )
4276+ . join( "target/doc/priv_dep_with_dep/index.html" )
4277+ . is_file( )
4278+ ) ;
4279+
4280+ // transitive should NOT be documented
4281+ assert ! ( !p. root( ) . join( "target/doc/transitive/index.html" ) . is_file( ) ) ;
4282+ }
0 commit comments