diff --git a/src/lib.rs b/src/lib.rs index f1deb84a..0bc2343b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -355,6 +355,12 @@ pub struct Package { pub metadata: serde_json::Value, /// The name of a native library the package is linking to. pub links: Option, + /// List of registries to which this package may be published. + /// + /// Publishing is unrestricted if `None`, and forbidden if the `Vec` is empty. + /// + /// This is always `None` if running with a version of Cargo older than 1.39. + pub publish: Option>, #[doc(hidden)] #[serde(skip)] __do_not_match_exhaustively: (), @@ -400,11 +406,21 @@ pub struct Target { /// Rust edition for this target #[serde(default = "edition_default")] pub edition: String, + /// Whether or not this target has doc tests enabled, and the target is + /// compatible with doc testing. + /// + /// This is always `true` if running with a version of Cargo older than 1.37. + #[serde(default = "default_true")] + pub doctest: bool, #[doc(hidden)] #[serde(skip)] __do_not_match_exhaustively: (), } +fn default_true() -> bool { + true +} + fn edition_default() -> String { "2015".to_string() } diff --git a/tests/all/Cargo.lock b/tests/all/Cargo.lock index 7d75f5b2..6aa1c9ba 100644 --- a/tests/all/Cargo.lock +++ b/tests/all/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "all" version = "0.1.0" diff --git a/tests/all/Cargo.toml b/tests/all/Cargo.toml index 24301209..e62b030a 100644 --- a/tests/all/Cargo.toml +++ b/tests/all/Cargo.toml @@ -11,6 +11,7 @@ keywords = ["cli"] readme = "README.md" repository = "https://github.com/oli-obk/cargo_metadata/" links = "foo" +publish = false [package.metadata.docs.rs] all-features = true diff --git a/tests/test_samples.rs b/tests/test_samples.rs index fbdaf98e..24d8deb8 100644 --- a/tests/test_samples.rs +++ b/tests/test_samples.rs @@ -93,6 +93,7 @@ fn old_minimal() { assert_eq!(target.required_features.len(), 0); assert_eq!(target.src_path, PathBuf::from("/foo/src/main.rs")); assert_eq!(target.edition, "2015"); + assert_eq!(target.doctest, true); assert_eq!(pkg.features.len(), 0); assert_eq!(pkg.manifest_path, PathBuf::from("/foo/Cargo.toml")); assert_eq!(pkg.categories.len(), 0); @@ -102,6 +103,7 @@ fn old_minimal() { assert_eq!(pkg.edition, "2015"); assert_eq!(pkg.metadata, serde_json::Value::Null); assert_eq!(pkg.links, None); + assert_eq!(pkg.publish, None); assert_eq!(meta.workspace_members.len(), 1); assert_eq!( meta.workspace_members[0].to_string(), @@ -128,15 +130,19 @@ fn cargo_version() -> semver::Version { let out = std::str::from_utf8(&output.stdout).expect("invalid utf8").trim(); let split: Vec<&str> = out.split_whitespace().collect(); assert!(split.len() >= 2, "cargo -V output is unexpected: {}", out); - semver::Version::parse(split[1]).expect("cargo -V semver could not be parsed") + let mut ver = semver::Version::parse(split[1]).expect("cargo -V semver could not be parsed"); + // Don't care about metadata, it is awkward to compare. + ver.pre = Vec::new(); + ver.build = Vec::new(); + ver } #[test] fn all_the_fields() { - // All the fields currently generated as of 1.31. This tries to exercise as + // All the fields currently generated as of 1.39. This tries to exercise as // much as possible. let ver = cargo_version(); - let minimum = semver::Version::parse("1.31.0").unwrap(); + let minimum = semver::Version::parse("1.39.0").unwrap(); if ver < minimum { // edition added in 1.30 // rename added in 1.31 @@ -166,6 +172,7 @@ fn all_the_fields() { assert_eq!(all.description, Some("Package description.".to_string())); assert_eq!(all.license, Some("MIT/Apache-2.0".to_string())); assert_eq!(all.license_file, Some(PathBuf::from("LICENSE"))); + assert_eq!(all.publish, Some(vec![])); assert_eq!(all.dependencies.len(), 8); let bitflags = all @@ -250,10 +257,12 @@ fn all_the_fields() { ); assert_eq!(lib.required_features.len(), 0); assert_eq!(lib.edition, "2018"); + assert_eq!(lib.doctest, true); let main = get_file_name!("main.rs"); assert_eq!(main.crate_types, vec!["bin"]); assert_eq!(main.kind, vec!["bin"]); + assert_eq!(main.doctest, false); let otherbin = get_file_name!("otherbin.rs"); assert_eq!(otherbin.edition, "2015");