Skip to content

Commit

Permalink
Add doc field to Target.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Oct 23, 2021
1 parent 312b8a5 commit 90e2073
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ pub struct Target {
#[serde(default = "default_true")]
#[cfg_attr(feature = "builder", builder(default = "true"))]
pub test: bool,
/// Whether or not this target is documented by `cargo doc`.
///
/// This is always `true` if running with a version of Cargo older than 1.50.
#[serde(default = "default_true")]
#[cfg_attr(feature = "builder", builder(default = "true"))]
pub doc: bool,
}

fn default_true() -> bool {
Expand Down
1 change: 1 addition & 0 deletions tests/all/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ crate-type = ["rlib", "cdylib", "dylib", "staticlib"]
[[bin]]
name = "otherbin"
edition = '2015'
doc = false

[[bin]]
name = "reqfeat"
Expand Down
19 changes: 11 additions & 8 deletions tests/test_samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn old_minimal() {
assert_eq!(target.edition, "2015");
assert_eq!(target.doctest, true);
assert_eq!(target.test, true);
assert_eq!(target.doc, true);
assert_eq!(pkg.features.len(), 0);
assert_eq!(pkg.manifest_path, "/foo/Cargo.toml");
assert_eq!(pkg.categories.len(), 0);
Expand Down Expand Up @@ -155,10 +156,10 @@ struct TestObject {

#[test]
fn all_the_fields() {
// All the fields currently generated as of 1.49. This tries to exercise as
// All the fields currently generated as of 1.51. This tries to exercise as
// much as possible.
let ver = cargo_version();
let minimum = semver::Version::parse("1.49.0").unwrap();
let minimum = semver::Version::parse("1.51.0").unwrap();
if ver < minimum {
// edition added in 1.30
// rename added in 1.31
Expand All @@ -169,6 +170,7 @@ fn all_the_fields() {
// test added in 1.47
// homepage added in 1.49
// documentation added in 1.49
// doc added in 1.50
// path added in 1.51
eprintln!("Skipping all_the_fields test, cargo {} is too old.", ver);
return;
Expand Down Expand Up @@ -222,12 +224,10 @@ fn all_the_fields() {
assert_eq!(path_dep.source, None);
assert_eq!(path_dep.kind, DependencyKind::Normal);
assert_eq!(path_dep.req, semver::VersionReq::parse("*").unwrap());
if ver >= semver::Version::parse("1.51.0").unwrap() {
assert_eq!(
path_dep.path.as_ref().map(|p| p.ends_with("path-dep")),
Some(true),
);
}
assert_eq!(
path_dep.path.as_ref().map(|p| p.ends_with("path-dep")),
Some(true),
);

all.dependencies
.iter()
Expand Down Expand Up @@ -292,15 +292,18 @@ fn all_the_fields() {
assert_eq!(lib.edition, "2018");
assert_eq!(lib.doctest, true);
assert_eq!(lib.test, true);
assert_eq!(lib.doc, 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);
assert_eq!(main.test, true);
assert_eq!(main.doc, true);

let otherbin = get_file_name!("otherbin.rs");
assert_eq!(otherbin.edition, "2015");
assert_eq!(otherbin.doc, false);

let reqfeat = get_file_name!("reqfeat.rs");
assert_eq!(reqfeat.required_features, vec!["feat2"]);
Expand Down

0 comments on commit 90e2073

Please sign in to comment.