From 409729edac4d129332a35f887f61e491622d9f05 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 22 Oct 2021 12:40:45 -0700 Subject: [PATCH] Add `default_run` field to `Package`. Added in https://github.com/rust-lang/cargo/pull/9550 --- src/lib.rs | 4 ++++ tests/all/Cargo.toml | 1 + tests/test_samples.rs | 7 +++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 52205e85..653224c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -345,6 +345,10 @@ pub struct Package { /// /// This is always `None` if running with a version of Cargo older than 1.39. pub publish: Option>, + /// 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, } impl Package { diff --git a/tests/all/Cargo.toml b/tests/all/Cargo.toml index 6a161866..db2d82ff 100644 --- a/tests/all/Cargo.toml +++ b/tests/all/Cargo.toml @@ -14,6 +14,7 @@ homepage = "https://github.com/oli-obk/cargo_metadata/" documentation = "https://docs.rs/cargo_metadata/" links = "foo" publish = false +default-run = "otherbin" [package.metadata.docs.rs] all-features = true diff --git a/tests/test_samples.rs b/tests/test_samples.rs index c57b812f..cbf4d22e 100644 --- a/tests/test_samples.rs +++ b/tests/test_samples.rs @@ -73,6 +73,7 @@ fn old_minimal() { assert_eq!(pkg.description, None); assert_eq!(pkg.license, None); assert_eq!(pkg.license_file, None); + assert_eq!(pkg.default_run, None); assert_eq!(pkg.dependencies.len(), 1); let dep = &pkg.dependencies[0]; assert_eq!(dep.name, "somedep"); @@ -156,10 +157,10 @@ struct TestObject { #[test] fn all_the_fields() { - // All the fields currently generated as of 1.51. This tries to exercise as + // All the fields currently generated as of 1.55. This tries to exercise as // much as possible. let ver = cargo_version(); - let minimum = semver::Version::parse("1.51.0").unwrap(); + let minimum = semver::Version::parse("1.55.0").unwrap(); if ver < minimum { // edition added in 1.30 // rename added in 1.31 @@ -172,6 +173,7 @@ fn all_the_fields() { // documentation added in 1.49 // doc added in 1.50 // path added in 1.51 + // default_run added in 1.55 eprintln!("Skipping all_the_fields test, cargo {} is too old.", ver); return; } @@ -202,6 +204,7 @@ fn all_the_fields() { assert!(all.license_file().unwrap().ends_with("tests/all/LICENSE")); assert_eq!(all.publish, Some(vec![])); assert_eq!(all.links, Some("foo".to_string())); + assert_eq!(all.default_run, Some("otherbin".to_string())); assert_eq!(all.dependencies.len(), 8); let bitflags = all