Skip to content

Commit

Permalink
Add default_run field to Package.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Oct 22, 2021
1 parent 740e184 commit f6e4cbd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>>,
/// 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>,
}

impl Package {
Expand Down
1 change: 1 addition & 0 deletions tests/all/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions tests/test_samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f6e4cbd

Please sign in to comment.