Skip to content

Commit

Permalink
Auto merge of #13536 - linyihai:package-pub-dep, r=epage
Browse files Browse the repository at this point in the history
test: Add test for packaging a public dependency

### What does this PR try to resolve?
Add a test for packaging a public dependency.
if no `-Zpublic-dependency`, the rewrited Cargo.toml does not have public, but if it does, public is in the rewrited Cargo.toml.
According the test, it seems no need to unset public in `prepare_for_publish`

### How should we test and review this PR?

### Additional information
Address #13308
  • Loading branch information
bors committed Mar 5, 2024
2 parents 19141bd + cf45a5c commit 2bb6dc9
Showing 1 changed file with 78 additions and 1 deletion.
79 changes: 78 additions & 1 deletion tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::publish::validate_crate_contents;
use cargo_test_support::registry::{self, Package};
use cargo_test_support::{
basic_manifest, cargo_process, git, path2url, paths, project, symlink_supported, t,
basic_manifest, cargo_process, git, path2url, paths, project, rustc_host, symlink_supported, t,
ProjectBuilder,
};
use flate2::read::GzDecoder;
Expand Down Expand Up @@ -1328,6 +1328,83 @@ fn package_two_kinds_of_deps() {
p.cargo("package --no-verify").run();
}

#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
fn package_public_dep() {
Package::new("bar", "1.0.0").publish();
Package::new("baz", "1.0.0").publish();
let p = project()
.file(
"Cargo.toml",
&format! {
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
[dependencies]
bar = {{ version = "1.0.0", public = true }}
[target.{host}.dependencies]
baz = {{ version = "1.0.0", public = true }}
"#,
host = rustc_host()
},
)
.file("src/main.rs", "fn main() {}")
.build();
let rewritten_toml = format!(
r#"{}
[package]
edition = "2015"
name = "foo"
version = "0.0.1"
[dependencies.bar]
version = "1.0.0"
[target.{host}.dependencies.baz]
version = "1.0.0"
"#,
cargo::core::package::MANIFEST_PREAMBLE,
host = rustc_host()
);
verify(&p, "package", rewritten_toml);

let rewritten_toml = format!(
r#"{}
[package]
edition = "2015"
name = "foo"
version = "0.0.1"
[dependencies.bar]
version = "1.0.0"
public = true
[target.{host}.dependencies.baz]
version = "1.0.0"
public = true
"#,
cargo::core::package::MANIFEST_PREAMBLE,
host = rustc_host()
);
verify(&p, "package -Zpublic-dependency", rewritten_toml);

fn verify(p: &cargo_test_support::Project, cmd: &str, rewritten_toml: String) {
p.cargo(cmd)
.masquerade_as_nightly_cargo(&["public-dependency"])
.run();
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
validate_crate_contents(
f,
"foo-0.0.1.crate",
&["Cargo.toml", "Cargo.toml.orig", "Cargo.lock", "src/main.rs"],
&[("Cargo.toml", &rewritten_toml)],
);
}
}

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

0 comments on commit 2bb6dc9

Please sign in to comment.