Skip to content

Commit

Permalink
test: public dependencies don't show up in cargo-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
eopb committed Sep 7, 2024
1 parent 2ddc46a commit 6829bf7
Showing 1 changed file with 197 additions and 0 deletions.
197 changes: 197 additions & 0 deletions tests/testsuite/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,203 @@ fn cargo_metadata_with_deps_and_version() {
.run();
}

/// The `public` field should not show up in `cargo metadata` output if `-Zpublic-dependency`
/// is not enabled
#[cargo_test]
fn cargo_metadata_public_private_dependencies_disabled() {
let p = project()
.file("src/foo.rs", "")
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.5.0"
authors = []
license = "MIT"
description = "foo"
[[bin]]
name = "foo"
[dependencies]
bar = { version = "*", public = false }
foobar = { version = "*", public = true }
baz = "*"
"#,
)
.build();
Package::new("bar", "0.0.1").publish();
Package::new("foobar", "0.0.2").publish();
Package::new("baz", "0.0.3").publish();

p.cargo("metadata -q --format-version 1")
.with_stdout_data(
str![[r#"
{
"metadata": null,
"packages": [
{
"name": "bar",
"...": "{...}"
},
{
"name": "baz",
"...": "{...}"
},
{
"name": "foo",
"dependencies": [
{
"features": [],
"kind": null,
"name": "bar",
"optional": false,
"registry": null,
"rename": null,
"req": "*",
"source": "registry+https://github.com/rust-lang/crates.io-index",
"target": null,
"uses_default_features": true
},
{
"features": [],
"kind": null,
"name": "baz",
"optional": false,
"registry": null,
"rename": null,
"req": "*",
"source": "registry+https://github.com/rust-lang/crates.io-index",
"target": null,
"uses_default_features": true
},
{
"features": [],
"kind": null,
"name": "foobar",
"optional": false,
"registry": null,
"rename": null,
"req": "*",
"source": "registry+https://github.com/rust-lang/crates.io-index",
"target": null,
"uses_default_features": true
}
],
"...": "{...}"
},
{
"name": "foobar",
"...": "{...}"
}
],
"...": "{...}"
}
"#]]
.is_json(),
)
.run();
}

#[cargo_test]
fn cargo_metadata_public_private_dependencies_enabled() {
let p = project()
.file("src/foo.rs", "")
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.5.0"
authors = []
license = "MIT"
description = "foo"
[[bin]]
name = "foo"
[dependencies]
bar = { version = "*", public = false }
foobar = { version = "*", public = true }
baz = "*"
"#,
)
.build();
Package::new("bar", "0.0.1").publish();
Package::new("foobar", "0.0.2").publish();
Package::new("baz", "0.0.3").publish();

p.cargo("metadata -q --format-version 1 -Zpublic-dependency")
.masquerade_as_nightly_cargo(&["public-dependency"])
.with_stdout_data(
str![[r#"
{
"metadata": null,
"packages": [
{
"name": "bar",
"...": "{...}"
},
{
"name": "baz",
"...": "{...}"
},
{
"name": "foo",
"dependencies": [
{
"features": [],
"kind": null,
"name": "bar",
"optional": false,
"registry": null,
"rename": null,
"req": "*",
"source": "registry+https://github.com/rust-lang/crates.io-index",
"target": null,
"uses_default_features": true
},
{
"features": [],
"kind": null,
"name": "baz",
"optional": false,
"registry": null,
"rename": null,
"req": "*",
"source": "registry+https://github.com/rust-lang/crates.io-index",
"target": null,
"uses_default_features": true
},
{
"features": [],
"kind": null,
"name": "foobar",
"optional": false,
"registry": null,
"rename": null,
"req": "*",
"source": "registry+https://github.com/rust-lang/crates.io-index",
"target": null,
"uses_default_features": true
}
],
"...": "{...}"
},
{
"name": "foobar",
"...": "{...}"
}
],
"...": "{...}"
}
"#]]
.is_json(),
)
.run();
}

#[cargo_test]
fn example() {
let p = project()
Expand Down

0 comments on commit 6829bf7

Please sign in to comment.