Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit the test field in cargo metadata #8478

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ struct SerializedTarget<'a> {
#[serde(rename = "required-features", skip_serializing_if = "Option::is_none")]
required_features: Option<Vec<&'a str>>,
doctest: bool,
/// Whether tests should be run for the target (`test` field in `Cargo.toml`)
test: bool,
}

impl ser::Serialize for Target {
Expand All @@ -283,6 +285,7 @@ impl ser::Serialize for Target {
.required_features()
.map(|rf| rf.iter().map(|s| &**s).collect()),
doctest: self.doctested() && self.doctestable(),
test: self.tested(),
}
.serialize(s)
}
Expand Down
5 changes: 4 additions & 1 deletion src/doc/man/cargo-metadata.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ The output has the following format:
/* Whether or not this target has doc tests enabled, and
the target is compatible with doc testing.
*/
"doctest": false
"doctest": false,
/* Whether or not this target should be built and run with `--test`
*/
"test": true
}
],
/* Set of features defined for the package.
Expand Down
7 changes: 5 additions & 2 deletions src/doc/man/generated/cargo-metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ <h2 id="cargo_metadata_output_format">OUTPUT FORMAT</h2>
/* Whether or not this target has doc tests enabled, and
the target is compatible with doc testing.
*/
"doctest": false
"doctest": false,
/* Whether or not this target should be built and run with `--test`
*/
"test": true
}
],
/* Set of features defined for the package.
Expand Down Expand Up @@ -514,4 +517,4 @@ <h2 id="cargo_metadata_see_also">SEE ALSO</h2>
<p><a href="index.html">cargo(1)</a></p>
</div>
</div>
</div>
</div>
3 changes: 2 additions & 1 deletion src/doc/src/reference/external-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ following structure:
"name": "my-package",
"src_path": "/path/to/my-package/src/lib.rs",
"edition": "2018",
"doctest": true
"doctest": true,
"test": true
},
/* The profile indicates which compiler settings were used. */
"profile": {
Expand Down
1 change: 1 addition & 0 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ The following is a description of the JSON structure:
"name": "my-package",
"src_path": "/path/to/my-package/src/lib.rs",
"edition": "2018",
"test": true,
"doctest": true
},
/* The profile settings for this unit.
Expand Down
6 changes: 5 additions & 1 deletion src/etc/man/cargo-metadata.1
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ The output has the following format:
/* Whether or not this target has doc tests enabled, and
the target is compatible with doc testing.
*/
"doctest": false
"doctest": false,
/* Whether or not this target has the `test` field set in the manifest,
causing it to be compiled with `--test`.
*/
"test": true
}
],
/* Set of features defined for the package.
Expand Down
5 changes: 3 additions & 2 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ fn bench_autodiscover_2015() {
version = "0.0.1"
authors = []
edition = "2015"

[features]
magic = []

Expand Down Expand Up @@ -1628,7 +1628,8 @@ fn json_artifact_includes_executable_for_benchmark() {
"doctest": false,
"edition": "2015",
"name": "benchmark",
"src_path": "[..]/foo/benches/benchmark.rs"
"src_path": "[..]/foo/benches/benchmark.rs",
"test": false
}
}

Expand Down
21 changes: 14 additions & 7 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3142,7 +3142,8 @@ fn compiler_json_error_format() {
"doctest": false,
"edition": "2015",
"name":"build-script-build",
"src_path":"[..]build.rs"
"src_path":"[..]build.rs",
"test": false
},
"profile": {
"debug_assertions": true,
Expand All @@ -3166,7 +3167,8 @@ fn compiler_json_error_format() {
"doctest": true,
"edition": "2015",
"name":"bar",
"src_path":"[..]lib.rs"
"src_path":"[..]lib.rs",
"test": true
},
"message":"{...}"
}
Expand All @@ -3189,7 +3191,8 @@ fn compiler_json_error_format() {
"doctest": true,
"edition": "2015",
"name":"bar",
"src_path":"[..]lib.rs"
"src_path":"[..]lib.rs",
"test": true
},
"filenames":[
"[..].rlib",
Expand Down Expand Up @@ -3217,7 +3220,8 @@ fn compiler_json_error_format() {
"doctest": false,
"edition": "2015",
"name":"foo",
"src_path":"[..]main.rs"
"src_path":"[..]main.rs",
"test": true
},
"message":"{...}"
}
Expand All @@ -3231,7 +3235,8 @@ fn compiler_json_error_format() {
"doctest": false,
"edition": "2015",
"name":"foo",
"src_path":"[..]main.rs"
"src_path":"[..]main.rs",
"test": true
},
"profile": {
"debug_assertions": true,
Expand Down Expand Up @@ -3299,7 +3304,8 @@ fn message_format_json_forward_stderr() {
"doctest": false,
"edition": "2015",
"name":"foo",
"src_path":"[..]"
"src_path":"[..]",
"test": true
},
"message":"{...}"
}
Expand All @@ -3313,7 +3319,8 @@ fn message_format_json_forward_stderr() {
"doctest": false,
"edition": "2015",
"name":"foo",
"src_path":"[..]"
"src_path":"[..]",
"test": true
},
"profile":{
"debug_assertions":false,
Expand Down
6 changes: 4 additions & 2 deletions tests/testsuite/metabuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ fn metabuild_json_artifact() {
"custom-build"
],
"name": "metabuild-foo",
"src_path": "[..]/foo/target/.metabuild/metabuild-foo-[..].rs"
"src_path": "[..]/foo/target/.metabuild/metabuild-foo-[..].rs",
"test": false
}
}

Expand Down Expand Up @@ -750,7 +751,8 @@ fn metabuild_failed_build_json() {
"custom-build"
],
"name": "metabuild-foo",
"src_path": null
"src_path": null,
"test": false
}
}
"#,
Expand Down
Loading