Skip to content

Commit b439062

Browse files
committed
test: public dependencies don't show up in cargo-metadata
1 parent b687045 commit b439062

File tree

1 file changed

+198
-0
lines changed

1 file changed

+198
-0
lines changed

tests/testsuite/metadata.rs

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,204 @@ fn cargo_metadata_with_deps_and_version() {
627627
.run();
628628
}
629629

630+
/// The `public` field should not show up in `cargo metadata` output if `-Zpublic-dependency`
631+
/// is not enabled
632+
#[cargo_test]
633+
fn cargo_metadata_public_private_dependencies_disabled() {
634+
let p = project()
635+
.file("src/foo.rs", "")
636+
.file(
637+
"Cargo.toml",
638+
r#"
639+
[package]
640+
name = "foo"
641+
version = "0.5.0"
642+
authors = []
643+
license = "MIT"
644+
description = "foo"
645+
646+
[[bin]]
647+
name = "foo"
648+
649+
[dependencies]
650+
bar = { version = "*", public = false }
651+
foobar = { version = "*", public = true }
652+
baz = "*"
653+
"#,
654+
)
655+
.build();
656+
Package::new("bar", "0.0.1").publish();
657+
Package::new("foobar", "0.0.2").publish();
658+
Package::new("baz", "0.0.3").publish();
659+
660+
p.cargo("metadata -q --format-version 1")
661+
.masquerade_as_nightly_cargo(&[])
662+
.with_stdout_data(
663+
str![[r#"
664+
{
665+
"metadata": null,
666+
"packages": [
667+
{
668+
"name": "bar",
669+
"...": "{...}"
670+
},
671+
{
672+
"name": "baz",
673+
"...": "{...}"
674+
},
675+
{
676+
"name": "foo",
677+
"dependencies": [
678+
{
679+
"features": [],
680+
"kind": null,
681+
"name": "bar",
682+
"optional": false,
683+
"registry": null,
684+
"rename": null,
685+
"req": "*",
686+
"source": "registry+https://github.com/rust-lang/crates.io-index",
687+
"target": null,
688+
"uses_default_features": true
689+
},
690+
{
691+
"features": [],
692+
"kind": null,
693+
"name": "baz",
694+
"optional": false,
695+
"registry": null,
696+
"rename": null,
697+
"req": "*",
698+
"source": "registry+https://github.com/rust-lang/crates.io-index",
699+
"target": null,
700+
"uses_default_features": true
701+
},
702+
{
703+
"features": [],
704+
"kind": null,
705+
"name": "foobar",
706+
"optional": false,
707+
"registry": null,
708+
"rename": null,
709+
"req": "*",
710+
"source": "registry+https://github.com/rust-lang/crates.io-index",
711+
"target": null,
712+
"uses_default_features": true
713+
}
714+
],
715+
"...": "{...}"
716+
},
717+
{
718+
"name": "foobar",
719+
"...": "{...}"
720+
}
721+
],
722+
"...": "{...}"
723+
}
724+
"#]]
725+
.is_json(),
726+
)
727+
.run();
728+
}
729+
730+
#[cargo_test]
731+
fn cargo_metadata_public_private_dependencies_enabled() {
732+
let p = project()
733+
.file("src/foo.rs", "")
734+
.file(
735+
"Cargo.toml",
736+
r#"
737+
[package]
738+
name = "foo"
739+
version = "0.5.0"
740+
authors = []
741+
license = "MIT"
742+
description = "foo"
743+
744+
[[bin]]
745+
name = "foo"
746+
747+
[dependencies]
748+
bar = { version = "*", public = false }
749+
foobar = { version = "*", public = true }
750+
baz = "*"
751+
"#,
752+
)
753+
.build();
754+
Package::new("bar", "0.0.1").publish();
755+
Package::new("foobar", "0.0.2").publish();
756+
Package::new("baz", "0.0.3").publish();
757+
758+
p.cargo("metadata -q --format-version 1 -Zpublic-dependency")
759+
.masquerade_as_nightly_cargo(&["public-dependency"])
760+
.with_stdout_data(
761+
str![[r#"
762+
{
763+
"metadata": null,
764+
"packages": [
765+
{
766+
"name": "bar",
767+
"...": "{...}"
768+
},
769+
{
770+
"name": "baz",
771+
"...": "{...}"
772+
},
773+
{
774+
"name": "foo",
775+
"dependencies": [
776+
{
777+
"features": [],
778+
"kind": null,
779+
"name": "bar",
780+
"optional": false,
781+
"registry": null,
782+
"rename": null,
783+
"req": "*",
784+
"source": "registry+https://github.com/rust-lang/crates.io-index",
785+
"target": null,
786+
"uses_default_features": true
787+
},
788+
{
789+
"features": [],
790+
"kind": null,
791+
"name": "baz",
792+
"optional": false,
793+
"registry": null,
794+
"rename": null,
795+
"req": "*",
796+
"source": "registry+https://github.com/rust-lang/crates.io-index",
797+
"target": null,
798+
"uses_default_features": true
799+
},
800+
{
801+
"features": [],
802+
"kind": null,
803+
"name": "foobar",
804+
"optional": false,
805+
"registry": null,
806+
"rename": null,
807+
"req": "*",
808+
"source": "registry+https://github.com/rust-lang/crates.io-index",
809+
"target": null,
810+
"uses_default_features": true
811+
}
812+
],
813+
"...": "{...}"
814+
},
815+
{
816+
"name": "foobar",
817+
"...": "{...}"
818+
}
819+
],
820+
"...": "{...}"
821+
}
822+
"#]]
823+
.is_json(),
824+
)
825+
.run();
826+
}
827+
630828
#[cargo_test]
631829
fn example() {
632830
let p = project()

0 commit comments

Comments
 (0)