summaryrefslogtreecommitdiffstats
path: root/vendor/cargo_metadata
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/cargo_metadata')
-rw-r--r--vendor/cargo_metadata/.cargo-checksum.json2
-rw-r--r--vendor/cargo_metadata/CHANGELOG.md6
-rw-r--r--vendor/cargo_metadata/Cargo.toml3
-rw-r--r--vendor/cargo_metadata/src/lib.rs90
-rw-r--r--vendor/cargo_metadata/src/libtest.rs165
-rw-r--r--vendor/cargo_metadata/tests/selftest.rs17
-rw-r--r--vendor/cargo_metadata/tests/test_samples.rs61
7 files changed, 315 insertions, 29 deletions
diff --git a/vendor/cargo_metadata/.cargo-checksum.json b/vendor/cargo_metadata/.cargo-checksum.json
index a2fc9f56f..b686d1b95 100644
--- a/vendor/cargo_metadata/.cargo-checksum.json
+++ b/vendor/cargo_metadata/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"CHANGELOG.md":"2e68a86864c8d2c00e40f0f9d53a8507cc69bc124f1779e795b5334451ce75bb","Cargo.toml":"cc68bf23ad777a381d94a2d0a40758412d7ba5323750965427cb6b4537616fbd","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"6be7aaba23d8646b470a966eef2f00c9fa04cf4d1de25cfb71680cef562e1574","clippy.toml":"0eb773e1a242ba7e06f0ca5c23be71b5989f4952fe18cae35e5322066e706495","src/dependency.rs":"c593ddc73d863c5712e2aba58b5f4d9bd915a5ac0bc17df71642aa79aa93bfdc","src/diagnostic.rs":"fee47d27390f1026ff99ffade5dfd2ab3e9b9839c3f33ce91a7dcde875551374","src/errors.rs":"797afd61efdd843ae570d9e972dd2425d33823d4a78c0c488028493dffb45c7a","src/lib.rs":"f436be9c0ded5ce27198ba145dce70673e37d0d53728e11b12276ef0c55741ec","src/messages.rs":"b16fd1d8a1a7099d371edb5d2e1495871afb61856025b0128a9e2262517e2099","tests/selftest.rs":"73afd494c1bf7dd4e1a99971e9ff66a0e21fc7bf3e327663df15d2350dcdfc70","tests/test_samples.rs":"f5015e6635935b505ad9a09caf8b05b980ff248adaaaf7bde166f8bce2152823"},"package":"e7daec1a2a2129eeba1644b220b4647ec537b0b5d4bfd6876fcc5a540056b592"} \ No newline at end of file
+{"files":{"CHANGELOG.md":"5c0030a1b27f047409d0fdf83f6458017c10e14b047347d2ce272250d818b86a","Cargo.toml":"0e1d4e7281f6404de243ec62cb3022fb13f0be663c6980f933204e30d33b9857","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"6be7aaba23d8646b470a966eef2f00c9fa04cf4d1de25cfb71680cef562e1574","clippy.toml":"0eb773e1a242ba7e06f0ca5c23be71b5989f4952fe18cae35e5322066e706495","src/dependency.rs":"c593ddc73d863c5712e2aba58b5f4d9bd915a5ac0bc17df71642aa79aa93bfdc","src/diagnostic.rs":"fee47d27390f1026ff99ffade5dfd2ab3e9b9839c3f33ce91a7dcde875551374","src/errors.rs":"797afd61efdd843ae570d9e972dd2425d33823d4a78c0c488028493dffb45c7a","src/lib.rs":"6e1fb60137253ea074d17c2cd83208de3d46d7f20927efd307a52b02baa0d87d","src/libtest.rs":"705519c92f6f1ad1594908b9024d6311777a3c20e23e74a3424e4577850f374c","src/messages.rs":"b16fd1d8a1a7099d371edb5d2e1495871afb61856025b0128a9e2262517e2099","tests/selftest.rs":"926ab92fd8823f9e43bacf753343cfa8a24e38d8d384604f274f1e9df500a511","tests/test_samples.rs":"f7dce6f723da930f822cf5eceda20af6473e8ac0302957cccff06479aabb8678"},"package":"2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037"} \ No newline at end of file
diff --git a/vendor/cargo_metadata/CHANGELOG.md b/vendor/cargo_metadata/CHANGELOG.md
index 0759858a2..c045c7d04 100644
--- a/vendor/cargo_metadata/CHANGELOG.md
+++ b/vendor/cargo_metadata/CHANGELOG.md
@@ -38,3 +38,9 @@
- Updated `derive_builder` to the latest version.
- Made use of `matches!` macros where possible.
- Fixed some tests
+
+## [0.15.1] - 2022-10-13
+
+### Added
+
+- Added `TestMessage`, `TestEvent`, `SuiteEvent` for parsing the `cargo test -- --format json` output.
diff --git a/vendor/cargo_metadata/Cargo.toml b/vendor/cargo_metadata/Cargo.toml
index 6ae78b7b0..4465fd7f0 100644
--- a/vendor/cargo_metadata/Cargo.toml
+++ b/vendor/cargo_metadata/Cargo.toml
@@ -13,7 +13,7 @@
edition = "2018"
rust-version = "1.56.0"
name = "cargo_metadata"
-version = "0.17.0"
+version = "0.18.1"
authors = ["Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>"]
description = "structured access to the output of `cargo metadata`"
readme = "README.md"
@@ -53,3 +53,4 @@ version = "1.0.31"
[features]
builder = ["derive_builder"]
default = []
+unstable = []
diff --git a/vendor/cargo_metadata/src/lib.rs b/vendor/cargo_metadata/src/lib.rs
index c222c130e..061fd8bc6 100644
--- a/vendor/cargo_metadata/src/lib.rs
+++ b/vendor/cargo_metadata/src/lib.rs
@@ -99,6 +99,8 @@ pub use dependency::DependencyBuilder;
pub use dependency::{Dependency, DependencyKind};
use diagnostic::Diagnostic;
pub use errors::{Error, Result};
+#[cfg(feature = "unstable")]
+pub use libtest::TestMessage;
#[allow(deprecated)]
pub use messages::parse_messages;
pub use messages::{
@@ -115,6 +117,8 @@ use serde::{Deserialize, Deserializer, Serialize};
mod dependency;
pub mod diagnostic;
mod errors;
+#[cfg(feature = "unstable")]
+pub mod libtest;
mod messages;
/// An "opaque" identifier for a package.
@@ -151,6 +155,11 @@ pub struct Metadata {
pub packages: Vec<Package>,
/// A list of all workspace members
pub workspace_members: Vec<PackageId>,
+ /// The list of default workspace members
+ ///
+ /// This not available if running with a version of Cargo older than 1.71.
+ #[serde(skip_serializing_if = "workspace_default_members_is_missing")]
+ pub workspace_default_members: WorkspaceDefaultMembers,
/// Dependencies graph
pub resolve: Option<Resolve>,
/// Workspace root
@@ -190,6 +199,18 @@ impl Metadata {
.filter(|&p| self.workspace_members.contains(&p.id))
.collect()
}
+
+ /// Get the workspace default packages.
+ ///
+ /// # Panics
+ ///
+ /// This will panic if running with a version of Cargo older than 1.71.
+ pub fn workspace_default_packages(&self) -> Vec<&Package> {
+ self.packages
+ .iter()
+ .filter(|&p| self.workspace_default_members.contains(&p.id))
+ .collect()
+ }
}
impl<'a> std::ops::Index<&'a PackageId> for Metadata {
@@ -203,6 +224,41 @@ impl<'a> std::ops::Index<&'a PackageId> for Metadata {
}
}
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(transparent)]
+/// A list of default workspace members.
+///
+/// See [`Metadata::workspace_default_members`].
+///
+/// It is only available if running a version of Cargo of 1.71 or newer.
+///
+/// # Panics
+///
+/// Dereferencing when running an older version of Cargo will panic.
+pub struct WorkspaceDefaultMembers(Option<Vec<PackageId>>);
+
+impl core::ops::Deref for WorkspaceDefaultMembers {
+ type Target = [PackageId];
+
+ fn deref(&self) -> &Self::Target {
+ self.0
+ .as_ref()
+ .expect("WorkspaceDefaultMembers should only be dereferenced on Cargo versions >= 1.71")
+ }
+}
+
+/// Return true if a valid value for [`WorkspaceDefaultMembers`] is missing, and
+/// dereferencing it would panic.
+///
+/// Internal helper for `skip_serializing_if` and test code. Might be removed in
+/// the future.
+#[doc(hidden)]
+pub fn workspace_default_members_is_missing(
+ workspace_default_members: &WorkspaceDefaultMembers,
+) -> bool {
+ workspace_default_members.0.is_none()
+}
+
#[derive(Clone, Serialize, Deserialize, Debug)]
#[cfg_attr(feature = "builder", derive(Builder))]
#[non_exhaustive]
@@ -289,11 +345,12 @@ pub struct DepKindInfo {
/// Each [`target`][Package::targets] of a `Package` will be built as a crate.
/// For more information, see <https://doc.rust-lang.org/book/ch07-01-packages-and-crates.html>.
pub struct Package {
- /// Name as given in the `Cargo.toml`
+ /// The [`name` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-name-field) as given in the `Cargo.toml`
+ // (We say "given in" instead of "specified in" since the `name` key cannot be inherited from the workspace.)
pub name: String,
- /// Version given in the `Cargo.toml`
+ /// The [`version` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-version-field) as specified in the `Cargo.toml`
pub version: Version,
- /// Authors given in the `Cargo.toml`
+ /// The [`authors` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-authors-field) as specified in the `Cargo.toml`
#[serde(default)]
pub authors: Vec<String>,
/// An opaque identifier for a package
@@ -301,12 +358,13 @@ pub struct Package {
/// The source of the package, e.g.
/// crates.io or `None` for local projects.
pub source: Option<Source>,
- /// Description as given in the `Cargo.toml`
+ /// The [`description` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-description-field) as specified in the `Cargo.toml`
pub description: Option<String>,
/// List of dependencies of this particular package
pub dependencies: Vec<Dependency>,
- /// License as given in the `Cargo.toml`
+ /// The [`license` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-license-and-license-file-fields) as specified in the `Cargo.toml`
pub license: Option<String>,
+ /// The [`license-file` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-license-and-license-file-fields) as specified in the `Cargo.toml`.
/// If the package is using a nonstandard license, this key may be specified instead of
/// `license`, and must point to a file relative to the manifest.
pub license_file: Option<Utf8PathBuf>,
@@ -316,32 +374,33 @@ pub struct Package {
pub features: BTreeMap<String, Vec<String>>,
/// Path containing the `Cargo.toml`
pub manifest_path: Utf8PathBuf,
- /// Categories as given in the `Cargo.toml`
+ /// The [`categories` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-categories-field) as specified in the `Cargo.toml`
#[serde(default)]
pub categories: Vec<String>,
- /// Keywords as given in the `Cargo.toml`
+ /// The [`keywords` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-keywords-field) as specified in the `Cargo.toml`
#[serde(default)]
pub keywords: Vec<String>,
- /// Readme as given in the `Cargo.toml`
+ /// The [`readme` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-readme-field) as specified in the `Cargo.toml`
pub readme: Option<Utf8PathBuf>,
- /// Repository as given in the `Cargo.toml`
+ /// The [`repository` URL](https://doc.rust-lang.org/cargo/reference/manifest.html#the-repository-field) as specified in the `Cargo.toml`
// can't use `url::Url` because that requires a more recent stable compiler
pub repository: Option<String>,
- /// Homepage as given in the `Cargo.toml`
+ /// The [`homepage` URL](https://doc.rust-lang.org/cargo/reference/manifest.html#the-homepage-field) as specified in the `Cargo.toml`.
///
/// On versions of cargo before 1.49, this will always be [`None`].
pub homepage: Option<String>,
- /// Documentation URL as given in the `Cargo.toml`
+ /// The [`documentation` URL](https://doc.rust-lang.org/cargo/reference/manifest.html#the-documentation-field) as specified in the `Cargo.toml`.
///
/// On versions of cargo before 1.49, this will always be [`None`].
pub documentation: Option<String>,
- /// Default Rust edition for the package
+ /// The default Rust edition for the package (either what's specified in the [`edition` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-edition-field)
+ /// or defaulting to [`Edition::E2015`]).
///
/// Beware that individual targets may specify their own edition in
/// [`Target::edition`].
#[serde(default)]
pub edition: Edition,
- /// Contents of the free form package.metadata section
+ /// Contents of the free form [`package.metadata` section](https://doc.rust-lang.org/cargo/reference/manifest.html#the-metadata-table).
///
/// This contents can be serialized to a struct using serde:
///
@@ -368,16 +427,19 @@ pub struct Package {
pub metadata: serde_json::Value,
/// The name of a native library the package is linking to.
pub links: Option<String>,
- /// List of registries to which this package may be published.
+ /// List of registries to which this package may be published (derived from the [`publish` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field)).
///
/// 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<Vec<String>>,
+ /// The [`default-run` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-default-run-field) as given in the `Cargo.toml`
+ // (We say "given in" instead of "specified in" since the `default-run` key cannot be inherited from the workspace.)
/// The default binary to run by `cargo run`.
///
/// This is always `None` if running with a version of Cargo older than 1.55.
pub default_run: Option<String>,
+ /// The [`rust-version` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field) as specified in the `Cargo.toml`.
/// The minimum supported Rust version of this package.
///
/// This is always `None` if running with a version of Cargo older than 1.58.
diff --git a/vendor/cargo_metadata/src/libtest.rs b/vendor/cargo_metadata/src/libtest.rs
new file mode 100644
index 000000000..4de86e7d2
--- /dev/null
+++ b/vendor/cargo_metadata/src/libtest.rs
@@ -0,0 +1,165 @@
+//! Parses output of [libtest](https://github.com/rust-lang/rust/blob/master/library/test/src/formatters/json.rs).
+//!
+//! Since this module parses output in an unstable format, all structs in this module may change at any time, and are exempt from semver guarantees.
+use serde::{Deserialize, Serialize};
+
+/// Suite related event
+#[derive(Debug, PartialEq, Deserialize, Serialize)]
+#[serde(tag = "event")]
+#[serde(rename_all = "lowercase")]
+/// Suite event
+pub enum SuiteEvent {
+ /// emitted on the start of a test run, and the start of the doctests
+ Started {
+ /// number of tests in this suite
+ test_count: usize,
+ },
+ /// the suite has finished
+ Ok {
+ /// the number of tests that passed
+ passed: usize,
+ /// the number of tests that failed
+ failed: usize,
+ /// number of tests that were ignored
+ ignored: usize,
+ /// number of benchmarks run
+ measured: usize,
+ /// i think this is based on what you specify in the cargo test argument
+ filtered_out: usize,
+ /// how long the suite took to run
+ exec_time: f32,
+ },
+ /// the suite has at least one failing test
+ Failed {
+ /// the number of tests that passed
+ passed: usize,
+ /// the number of tests that failed
+ failed: usize,
+ /// number of tests that were ignored
+ ignored: usize,
+ /// i think its something to do with benchmarks?
+ measured: usize,
+ /// i think this is based on what you specify in the cargo test argument
+ filtered_out: usize,
+ /// how long the suite took to run
+ exec_time: f32,
+ },
+}
+
+#[derive(Debug, PartialEq, Deserialize, Serialize)]
+#[serde(tag = "event")]
+#[serde(rename_all = "lowercase")]
+/// Test event
+pub enum TestEvent {
+ /// a new test starts
+ Started {
+ /// the name of this test
+ name: String,
+ },
+ /// the test has finished
+ Ok {
+ /// which one
+ name: String,
+ /// in how long
+ exec_time: f32,
+ /// what did it say?
+ stdout: Option<String>,
+ },
+ /// the test has failed
+ Failed {
+ /// which one
+ name: String,
+ /// in how long
+ exec_time: f32,
+ /// why?
+ stdout: Option<String>,
+ /// it timed out?
+ reason: Option<String>,
+ /// what message
+ message: Option<String>,
+ },
+ /// the test has been ignored
+ Ignored {
+ /// which one
+ name: String,
+ },
+ /// the test has timed out
+ Timeout {
+ /// which one
+ name: String,
+ },
+}
+
+impl TestEvent {
+ /// Get the name of this test
+ pub fn name(&self) -> &str {
+ let (Self::Started { name }
+ | Self::Ok { name, .. }
+ | Self::Ignored { name }
+ | Self::Failed { name, .. }
+ | Self::Timeout { name }) = self;
+ name
+ }
+
+ /// Get the stdout of this test, if available.
+ pub fn stdout(&self) -> Option<&str> {
+ match self {
+ Self::Ok { stdout, .. } | Self::Failed { stdout, .. } => stdout.as_deref(),
+ _ => None,
+ }
+ }
+}
+
+#[derive(Debug, PartialEq, Deserialize, Serialize)]
+/// Represents the output of `cargo test -- -Zunstable-options --report-time --show-output --format json`.
+///
+/// requires --report-time
+///
+/// # Stability
+///
+/// As this struct is for interfacing with the unstable libtest json output, this struct may change at any time, without semver guarantees.
+#[serde(tag = "type")]
+#[serde(rename_all = "lowercase")]
+pub enum TestMessage {
+ /// suite related message
+ Suite(SuiteEvent),
+ /// test related message
+ Test(TestEvent),
+ /// bench related message
+ Bench {
+ /// name of benchmark
+ name: String,
+ /// distribution
+ median: f32,
+ /// deviation
+ deviation: f32,
+ /// thruput in MiB per second
+ mib_per_second: Option<f32>,
+ },
+}
+
+#[test]
+fn deser() {
+ macro_rules! run {
+ ($($input:literal parses to $output:expr),+) => {
+ $(assert_eq!(dbg!(serde_json::from_str::<TestMessage>($input)).unwrap(), $output);)+
+ };
+ }
+ run![
+ r#"{ "type": "suite", "event": "started", "test_count": 2 }"# parses to TestMessage::Suite(SuiteEvent::Started { test_count: 2 }),
+ r#"{ "type": "test", "event": "started", "name": "fail" }"# parses to TestMessage::Test(TestEvent::Started { name: "fail".into() }),
+ r#"{ "type": "test", "name": "fail", "event": "ok", "exec_time": 0.000003428, "stdout": "hello world" }"# parses to TestMessage::Test(TestEvent::Ok { name: "fail".into(), exec_time: 0.000003428, stdout: Some("hello world".into()) }),
+ r#"{ "type": "test", "event": "started", "name": "nope" }"# parses to TestMessage::Test(TestEvent::Started { name: "nope".into() }),
+ r#"{ "type": "test", "name": "nope", "event": "ignored" }"# parses to TestMessage::Test(TestEvent::Ignored { name: "nope".into() }),
+ r#"{ "type": "suite", "event": "ok", "passed": 1, "failed": 0, "ignored": 1, "measured": 0, "filtered_out": 0, "exec_time": 0.000684028 }"# parses to TestMessage::Suite(SuiteEvent::Ok { passed: 1, failed: 0, ignored: 1, measured: 0, filtered_out: 0, exec_time: 0.000684028 })
+ ];
+
+ run![
+ r#"{ "type": "suite", "event": "started", "test_count": 2 }"# parses to TestMessage::Suite(SuiteEvent::Started { test_count: 2 }),
+ r#"{ "type": "test", "event": "started", "name": "fail" }"# parses to TestMessage::Test(TestEvent::Started { name: "fail".into() }),
+ r#"{ "type": "test", "event": "started", "name": "benc" }"# parses to TestMessage::Test(TestEvent::Started { name: "benc".into() }),
+ r#"{ "type": "bench", "name": "benc", "median": 0, "deviation": 0 }"# parses to TestMessage::Bench { name: "benc".into(), median: 0., deviation: 0., mib_per_second: None },
+ r#"{ "type": "test", "name": "fail", "event": "failed", "exec_time": 0.000081092, "stdout": "thread 'fail' panicked" }"# parses to TestMessage::Test(TestEvent::Failed { name: "fail".into(), exec_time: 0.000081092, stdout: Some("thread 'fail' panicked".into()), reason: None, message: None} ),
+ r#"{ "type": "suite", "event": "failed", "passed": 0, "failed": 1, "ignored": 0, "measured": 1, "filtered_out": 0, "exec_time": 0.000731068 }"# parses to TestMessage::Suite(SuiteEvent::Failed { passed: 0, failed: 1, ignored: 0, measured: 1, filtered_out: 0, exec_time: 0.000731068 })
+ ];
+}
diff --git a/vendor/cargo_metadata/tests/selftest.rs b/vendor/cargo_metadata/tests/selftest.rs
index d6ab61832..dbcc67ec2 100644
--- a/vendor/cargo_metadata/tests/selftest.rs
+++ b/vendor/cargo_metadata/tests/selftest.rs
@@ -161,3 +161,20 @@ fn metadata_deps() {
assert!(serde.req.matches(&Version::parse("1.99.99").unwrap()));
assert!(!serde.req.matches(&Version::parse("2.0.0").unwrap()));
}
+
+#[test]
+fn workspace_default_packages() {
+ use cargo_metadata::workspace_default_members_is_missing;
+
+ let metadata = MetadataCommand::new()
+ .manifest_path("Cargo.toml")
+ .exec()
+ .unwrap();
+ let workspace_packages = metadata.workspace_packages();
+ // this will only trigger on cargo versions that expose
+ // workspace_default_members (that is, cargo >= 1.71)
+ if !workspace_default_members_is_missing(&metadata.workspace_default_members) {
+ let default_packages = metadata.workspace_default_packages();
+ assert_eq!(default_packages, workspace_packages);
+ }
+}
diff --git a/vendor/cargo_metadata/tests/test_samples.rs b/vendor/cargo_metadata/tests/test_samples.rs
index 15128b075..c834778af 100644
--- a/vendor/cargo_metadata/tests/test_samples.rs
+++ b/vendor/cargo_metadata/tests/test_samples.rs
@@ -5,19 +5,19 @@ extern crate serde_json;
use camino::Utf8PathBuf;
use cargo_metadata::{
- ArtifactDebuginfo, CargoOpt, DependencyKind, Edition, Message, Metadata, MetadataCommand,
+ workspace_default_members_is_missing, ArtifactDebuginfo, CargoOpt, DependencyKind, Edition,
+ Message, Metadata, MetadataCommand,
};
-#[test]
-fn old_minimal() {
- // Output from oldest supported version (1.24).
- // This intentionally has as many null fields as possible.
- // 1.8 is when metadata was introduced.
- // Older versions not supported because the following are required:
- // - `workspace_members` added in 1.13
- // - `target_directory` added in 1.19
- // - `workspace_root` added in 1.24
- let json = r#"
+/// Output from oldest version ever supported (1.24).
+///
+/// This intentionally has as many null fields as possible.
+/// 1.8 is when metadata was introduced.
+/// Older versions not supported because the following are required:
+/// - `workspace_members` added in 1.13
+/// - `target_directory` added in 1.19
+/// - `workspace_root` added in 1.24
+const JSON_OLD_MINIMAL: &str = r#"
{
"packages": [
{
@@ -65,7 +65,10 @@ fn old_minimal() {
"workspace_root": "/foo"
}
"#;
- let meta: Metadata = serde_json::from_str(json).unwrap();
+
+#[test]
+fn old_minimal() {
+ let meta: Metadata = serde_json::from_str(JSON_OLD_MINIMAL).unwrap();
assert_eq!(meta.packages.len(), 1);
let pkg = &meta.packages[0];
assert_eq!(pkg.name, "foo");
@@ -121,6 +124,15 @@ fn old_minimal() {
assert_eq!(meta.workspace_root, "/foo");
assert_eq!(meta.workspace_metadata, serde_json::Value::Null);
assert_eq!(meta.target_directory, "/foo/target");
+
+ assert!(workspace_default_members_is_missing(
+ &meta.workspace_default_members
+ ));
+ let serialized = serde_json::to_value(meta).unwrap();
+ assert!(!serialized
+ .as_object()
+ .unwrap()
+ .contains_key("workspace_default_members"));
}
macro_rules! sorted {
@@ -178,6 +190,7 @@ fn all_the_fields() {
// path added in 1.51
// default_run added in 1.55
// rust_version added in 1.58
+ // workspace_default_members added in 1.71
eprintln!("Skipping all_the_fields test, cargo {} is too old.", ver);
return;
}
@@ -187,7 +200,7 @@ fn all_the_fields() {
.unwrap();
assert_eq!(meta.workspace_root.file_name().unwrap(), "all");
assert_eq!(
- serde_json::from_value::<WorkspaceMetadata>(meta.workspace_metadata).unwrap(),
+ serde_json::from_value::<WorkspaceMetadata>(meta.workspace_metadata.clone()).unwrap(),
WorkspaceMetadata {
testobject: TestObject {
myvalue: "abc".to_string()
@@ -196,6 +209,9 @@ fn all_the_fields() {
);
assert_eq!(meta.workspace_members.len(), 1);
assert!(meta.workspace_members[0].to_string().starts_with("all"));
+ if ver >= semver::Version::parse("1.71.0").unwrap() {
+ assert_eq!(&*meta.workspace_default_members, &meta.workspace_members);
+ }
assert_eq!(meta.packages.len(), 9);
let all = meta.packages.iter().find(|p| p.name == "all").unwrap();
@@ -450,6 +466,18 @@ fn all_the_fields() {
kind.target.as_ref().map(|x| x.to_string()),
Some("cfg(windows)".to_string())
);
+
+ let serialized = serde_json::to_value(meta).unwrap();
+ if ver >= semver::Version::parse("1.71.0").unwrap() {
+ assert!(serialized.as_object().unwrap()["workspace_default_members"]
+ .as_array()
+ .is_some());
+ } else {
+ assert!(!serialized
+ .as_object()
+ .unwrap()
+ .contains_key("workspace_default_members"));
+ }
}
#[test]
@@ -690,3 +718,10 @@ fn debuginfo_variants() {
}
}
}
+
+#[test]
+#[should_panic = "WorkspaceDefaultMembers should only be dereferenced on Cargo versions >= 1.71"]
+fn missing_workspace_default_members() {
+ let meta: Metadata = serde_json::from_str(JSON_OLD_MINIMAL).unwrap();
+ let _ = &*meta.workspace_default_members;
+}