Skip to content

Commit cf45a5c

Browse files
committed
test: Add test for packaging a public dependency
1 parent 9e6288e commit cf45a5c

File tree

1 file changed

+78
-1
lines changed

1 file changed

+78
-1
lines changed

Diff for: tests/testsuite/package.rs

+78-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use cargo_test_support::paths::CargoPathExt;
44
use cargo_test_support::publish::validate_crate_contents;
55
use cargo_test_support::registry::{self, Package};
66
use cargo_test_support::{
7-
basic_manifest, cargo_process, git, path2url, paths, project, symlink_supported, t,
7+
basic_manifest, cargo_process, git, path2url, paths, project, rustc_host, symlink_supported, t,
88
ProjectBuilder,
99
};
1010
use flate2::read::GzDecoder;
@@ -1328,6 +1328,83 @@ fn package_two_kinds_of_deps() {
13281328
p.cargo("package --no-verify").run();
13291329
}
13301330

1331+
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
1332+
fn package_public_dep() {
1333+
Package::new("bar", "1.0.0").publish();
1334+
Package::new("baz", "1.0.0").publish();
1335+
let p = project()
1336+
.file(
1337+
"Cargo.toml",
1338+
&format! {
1339+
r#"
1340+
[package]
1341+
name = "foo"
1342+
version = "0.0.1"
1343+
edition = "2015"
1344+
1345+
[dependencies]
1346+
bar = {{ version = "1.0.0", public = true }}
1347+
1348+
[target.{host}.dependencies]
1349+
baz = {{ version = "1.0.0", public = true }}
1350+
"#,
1351+
host = rustc_host()
1352+
},
1353+
)
1354+
.file("src/main.rs", "fn main() {}")
1355+
.build();
1356+
let rewritten_toml = format!(
1357+
r#"{}
1358+
[package]
1359+
edition = "2015"
1360+
name = "foo"
1361+
version = "0.0.1"
1362+
1363+
[dependencies.bar]
1364+
version = "1.0.0"
1365+
1366+
[target.{host}.dependencies.baz]
1367+
version = "1.0.0"
1368+
"#,
1369+
cargo::core::package::MANIFEST_PREAMBLE,
1370+
host = rustc_host()
1371+
);
1372+
verify(&p, "package", rewritten_toml);
1373+
1374+
let rewritten_toml = format!(
1375+
r#"{}
1376+
[package]
1377+
edition = "2015"
1378+
name = "foo"
1379+
version = "0.0.1"
1380+
1381+
[dependencies.bar]
1382+
version = "1.0.0"
1383+
public = true
1384+
1385+
[target.{host}.dependencies.baz]
1386+
version = "1.0.0"
1387+
public = true
1388+
"#,
1389+
cargo::core::package::MANIFEST_PREAMBLE,
1390+
host = rustc_host()
1391+
);
1392+
verify(&p, "package -Zpublic-dependency", rewritten_toml);
1393+
1394+
fn verify(p: &cargo_test_support::Project, cmd: &str, rewritten_toml: String) {
1395+
p.cargo(cmd)
1396+
.masquerade_as_nightly_cargo(&["public-dependency"])
1397+
.run();
1398+
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
1399+
validate_crate_contents(
1400+
f,
1401+
"foo-0.0.1.crate",
1402+
&["Cargo.toml", "Cargo.toml.orig", "Cargo.lock", "src/main.rs"],
1403+
&[("Cargo.toml", &rewritten_toml)],
1404+
);
1405+
}
1406+
}
1407+
13311408
#[cargo_test]
13321409
fn test_edition() {
13331410
let p = project()

0 commit comments

Comments
 (0)