-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add unit test checking to cargo check
#4592
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
235712f
Add unit test checking to `cargo check`
ehuss 390e957
Fix broken tests due to different profile selection.
ehuss 0acc67c
Fix wrong profile selection for `cargo build` and `cargo rustc`.
ehuss 3dd21d8
Rework handling of --tests and --benches with implied targets.
ehuss e171e00
Fix broken bench test for new --benches behavior.
ehuss efc0dd1
Don't change order of tests and benches for cleaner diff.
ehuss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ use std::env; | |
|
||
use cargo::core::Workspace; | ||
use cargo::ops::{self, CompileOptions, MessageFormat, Packages}; | ||
use cargo::util::{CliResult, Config}; | ||
use cargo::util::{CliResult, CliError, Config}; | ||
use cargo::util::important_paths::find_root_manifest_for_wd; | ||
|
||
pub const USAGE: &'static str = " | ||
|
@@ -28,6 +28,7 @@ Options: | |
--benches Check all benches | ||
--all-targets Check all targets (lib and bin targets by default) | ||
--release Check artifacts in release mode, with optimizations | ||
--profile PROFILE Profile to build the selected target for | ||
--features FEATURES Space-separated list of features to also check | ||
--all-features Check all available features | ||
--no-default-features Do not check the `default` feature | ||
|
@@ -53,6 +54,9 @@ Note that `--exclude` has to be specified in conjunction with the `--all` flag. | |
Compilation can be configured via the use of profiles which are configured in | ||
the manifest. The default profile for this command is `dev`, but passing | ||
the --release flag will use the `release` profile instead. | ||
|
||
The `--profile test` flag can be used to check unit tests with the | ||
`#[cfg(test)]` attribute. | ||
"; | ||
|
||
#[derive(Deserialize)] | ||
|
@@ -83,6 +87,7 @@ pub struct Options { | |
flag_frozen: bool, | ||
flag_all: bool, | ||
flag_exclude: Vec<String>, | ||
flag_profile: Option<String>, | ||
#[serde(rename = "flag_Z")] | ||
flag_z: Vec<String>, | ||
} | ||
|
@@ -106,6 +111,17 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { | |
&options.flag_exclude, | ||
&options.flag_package)?; | ||
|
||
let test = options.flag_tests || | ||
match options.flag_profile.as_ref().map(|t| &t[..]) { | ||
Some("test") => true, | ||
None => false, | ||
Some(profile) => { | ||
let err = format!("unknown profile: `{}`, only `test` is currently supported", | ||
profile).into(); | ||
return Err(CliError::new(err, 101)) | ||
} | ||
}; | ||
|
||
let opts = CompileOptions { | ||
config: config, | ||
jobs: options.flag_jobs, | ||
|
@@ -114,10 +130,10 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { | |
all_features: options.flag_all_features, | ||
no_default_features: options.flag_no_default_features, | ||
spec: spec, | ||
mode: ops::CompileMode::Check, | ||
mode: ops::CompileMode::Check{test:test}, | ||
release: options.flag_release, | ||
filter: ops::CompileFilter::new(options.flag_lib, | ||
&options.flag_bin, options.flag_bins, | ||
filter: ops::CompileFilter::new(options.flag_lib || options.flag_tests, | ||
&options.flag_bin, options.flag_bins || options.flag_tests, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a comment to why these two |
||
&options.flag_test, options.flag_tests, | ||
&options.flag_example, options.flag_examples, | ||
&options.flag_bench, options.flag_benches, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -862,7 +862,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { | |
ret.extend(self.maybe_lib(unit)); | ||
|
||
// Integration tests/benchmarks require binaries to be built | ||
if unit.profile.test && | ||
if unit.profile.test && !unit.profile.check && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you expand the above comment to explain this negation? |
||
(unit.target.is_test() || unit.target.is_bench()) { | ||
ret.extend(unit.pkg.targets().iter().filter(|t| { | ||
let no_required_features = Vec::new(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic may cause subtle oddities, although that's maybe ok for now? but for example:
I think that'll check the binary
foo
in "test mode" rather than "do you compile mode", right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. The more I think about it, it is probably wrong.
check --tests
should not check bins with the test profile. I'll fix it.