mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
test: support publish package with a public
field.
This commit is contained in:
parent
dfdd5ff81a
commit
35d5fae5b6
@ -558,6 +558,7 @@ pub struct Dependency {
|
|||||||
package: Option<String>,
|
package: Option<String>,
|
||||||
optional: bool,
|
optional: bool,
|
||||||
default_features: bool,
|
default_features: bool,
|
||||||
|
public: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Entry with data that corresponds to [`tar::EntryType`].
|
/// Entry with data that corresponds to [`tar::EntryType`].
|
||||||
@ -1428,6 +1429,7 @@ impl Package {
|
|||||||
"kind": dep.kind,
|
"kind": dep.kind,
|
||||||
"registry": registry_url,
|
"registry": registry_url,
|
||||||
"package": dep.package,
|
"package": dep.package,
|
||||||
|
"public": dep.public,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
@ -1678,6 +1680,7 @@ impl Dependency {
|
|||||||
optional: false,
|
optional: false,
|
||||||
registry: None,
|
registry: None,
|
||||||
default_features: true,
|
default_features: true,
|
||||||
|
public: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1731,6 +1734,12 @@ impl Dependency {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Changes this to an public dependency.
|
||||||
|
pub fn public(&mut self, public: bool) -> &mut Self {
|
||||||
|
self.public = public;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Adds `default-features = false` if the argument is `false`.
|
/// Adds `default-features = false` if the argument is `false`.
|
||||||
pub fn default_features(&mut self, default_features: bool) -> &mut Self {
|
pub fn default_features(&mut self, default_features: bool) -> &mut Self {
|
||||||
self.default_features = default_features;
|
self.default_features = default_features;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Tests for public/private dependencies.
|
//! Tests for public/private dependencies.
|
||||||
|
|
||||||
use cargo_test_support::project;
|
use cargo_test_support::project;
|
||||||
use cargo_test_support::registry::Package;
|
use cargo_test_support::registry::{Dependency, Package};
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
|
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
|
||||||
fn exported_priv_warning() {
|
fn exported_priv_warning() {
|
||||||
@ -479,3 +479,58 @@ fn allow_priv_in_custom_build() {
|
|||||||
)
|
)
|
||||||
.run()
|
.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
|
||||||
|
fn publish_package_with_public_dependency() {
|
||||||
|
Package::new("pub_bar", "0.1.0")
|
||||||
|
.file("src/lib.rs", "pub struct FromPub;")
|
||||||
|
.publish();
|
||||||
|
Package::new("bar", "0.1.0")
|
||||||
|
.cargo_feature("public-dependency")
|
||||||
|
.add_dep(Dependency::new("pub_bar", "0.1.0").public(true))
|
||||||
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
"
|
||||||
|
extern crate pub_bar;
|
||||||
|
pub use pub_bar::FromPub as BarFromPub;
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.publish();
|
||||||
|
|
||||||
|
let p = project()
|
||||||
|
.file(
|
||||||
|
"Cargo.toml",
|
||||||
|
r#"
|
||||||
|
cargo-features = ["public-dependency"]
|
||||||
|
[package]
|
||||||
|
name = "foo"
|
||||||
|
version = "0.0.1"
|
||||||
|
[dependencies]
|
||||||
|
bar = {version = "0.1.0", public = true}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
"
|
||||||
|
extern crate bar;
|
||||||
|
pub fn use_pub(_: bar::BarFromPub) {}
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
p.cargo("check --message-format=short")
|
||||||
|
.masquerade_as_nightly_cargo(&["public-dependency"])
|
||||||
|
.with_stderr(
|
||||||
|
"\
|
||||||
|
[UPDATING] `[..]` index
|
||||||
|
[DOWNLOADING] crates ...
|
||||||
|
[DOWNLOADED] pub_bar v0.1.0 ([..])
|
||||||
|
[DOWNLOADED] bar v0.1.0 ([..])
|
||||||
|
[CHECKING] pub_bar v0.1.0
|
||||||
|
[CHECKING] bar v0.1.0
|
||||||
|
[CHECKING] foo v0.0.1 ([..])
|
||||||
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.run()
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user