-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 --quiet option for cargo test
#6358
Conversation
tests/testsuite/test.rs
Outdated
).build(); | ||
|
||
p.cargo("test -q hello") | ||
.with_stdout_contains("running 1 test") |
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.
Shouldn't it not contain this? In fact, should the two assertions be the following?
.with_stdout("")
.with_stderr("")
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.
The output only contains no of tests
being run plus the test result
. It only doesn't show the actual tests being run. This is the same as doing
$ rustc --test unit-test.rs
$ ./unit-test --quiet
cc @dwijnand
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.
Right, that's what I thought. libtest's help says:
-q, --quiet Display one character per test instead of one line.
Alias to --format=terse
So I think if we incorporate that information into cargo test --help
and expand this test to test the full output of out and err, for me, we can make this change.
Updated. Thank you! |
Hmm that's the global -q for all commands. We'd have to find a way to do it just for the test command... |
🤦♂️ Oops! my bad. Hadn't noticed this. Going to fix this in a few. |
03db201
to
9e76402
Compare
Fixed. test command |
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.
Thanks for this! FWIW this is not quite as trivial as it may seem I think because the libtest-based test harness isn't the only one out there in use by Cargo. Through harness = false
we'd be passing a --quiet
option to test harnesses which may not expect this, so this runs the risk of breaking existing workflows.
In general though this is definitely a papercut and one we've wanted to fix for quite some time. We've never really sat down though and thought through the consequences. I'd personally prefer if we established a defined set of arguments that we may passed to test harnesses to define the Cargo conventions they should follow. I'm somewhat wary to land piecemeal adjustments before that though due to the breakage it could cause.
src/bin/cargo/cli.rs
Outdated
) | ||
} | ||
|
||
// add --quiet option to command |
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.
I'm a little confused about why this function is necessary, should the quiet
argument be added to the below subcommands if it's not already present?
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.
Added this because quiet
was already present (set to global) for all cargo
subcommands
Line 223 in c4b5a63
.global(true), |
--quiet
for all other subcommands OR for only cargo test
if this is not required for others.
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.
Hm ok, if we end up landing this I think we'll want to take the route of declaratively adding --quiet
to each subcommand, either through a shared implementation or manually, I don't think we'll want to sneak in --quiet
as an argument right at the end
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.
Thanks, makes sense. Also I noticed --quiet
does nothing for some subcommands i.e cargo search
, generate-lockfile
, etc. Is it ok to not add the --quiet
for these? The option was present for all before so my worry is removing it may cause breakage.
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.
Nah I think it's fine to add this for those commands to, they'll likely just pick up the existing behavior for --quiet
naturally!
Updated the PR to explicitly add |
In terms of definition, I think in theory |
Maybe a crazy idea, but related to custom test frameworks, the In the short term, maybe it can just skip the flag when harness=false? |
That seems plausible to me! In any case not passing it through automatically with |
☔ The latest upstream changes (presumably #6631) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping @collin5 do you think you'd be able to change it so that it doesn't forward flags if |
@ehuss Sorry for the delay on this, been a bit busy lately. Will be working on it this weekend. Thanks for the reminder. |
Changed to forwarding the |
src/cargo/ops/cargo_test.rs
Outdated
@@ -83,7 +84,12 @@ fn run_unit_tests( | |||
for &(ref pkg, ref kind, ref test, ref exe) in &compilation.tests { | |||
let exe_display = exe.strip_prefix(cwd).unwrap_or(exe).display(); | |||
let mut cmd = compilation.target_process(exe, pkg)?; | |||
let targets = pkg.manifest().targets(); | |||
let harness = targets.iter().any(|t| t.kind() == &TargetKind::Test && t.harness()); |
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.
I don't think this is the correct way to check for a harness. For example, this won't work if the target is a lib or bin. It also won't work properly if some targets of a harness and some don't. I think maybe the entire Target struct will need to be included in Compilation::tests
?
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.
Makes sense. Will do. Thank you!
Updated! Thank you. @ehuss |
src/cargo/ops/cargo_test.rs
Outdated
let exe_display = exe.strip_prefix(cwd).unwrap_or(exe).display(); | ||
let mut cmd = compilation.target_process(exe, pkg)?; | ||
cmd.args(test_args); | ||
if target.harness() && options.quiet_run { |
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.
Sorry, just one more minor question. Is there a reason quiet_run
was added to TestOptions
instead of just checking the verbosity level? Something like: config.shell().verbosity() == Verbosity::Quiet
. The reason I ask is because "cargo -q test" behaves differently from "cargo test -q".
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.
Oops! Had missed this. I've updated changes. Thanks again. @ehuss
📌 Commit d93b2d7 has been approved by |
Add --quiet option for `cargo test` Fixes #4325
☀️ Test successful - checks-travis, status-appveyor |
Update cargo 5 commits in 95b45eca19ac785263fed98ecefe540bb47337ac..dd761226d944712a363ea515cb294f4e2b6bdbe5 2019-03-06 19:24:30 +0000 to 2019-03-11 18:51:14 +0000 - Fingerprint build script deps only for path packages. (rust-lang/cargo#6734) - Add --quiet option for `cargo test` (rust-lang/cargo#6358) - .gitignore should end with a newline. (rust-lang/cargo#6732) - Emit warning on misspelled environment variables (rust-lang/cargo#6694) - Update glob requirement from 0.2.11 to 0.3.0 (rust-lang/cargo#6724)
Update cargo 6 commits in 95b45eca19ac785263fed98ecefe540bb47337ac..0e35bd8af0ec72d3225c4819b330b94628f0e9d0 2019-03-06 19:24:30 +0000 to 2019-03-13 06:52:51 +0000 - Make `hg` optional for tests. (rust-lang/cargo#6739) - Fingerprint build script deps only for path packages. (rust-lang/cargo#6734) - Add --quiet option for `cargo test` (rust-lang/cargo#6358) - .gitignore should end with a newline. (rust-lang/cargo#6732) - Emit warning on misspelled environment variables (rust-lang/cargo#6694) - Update glob requirement from 0.2.11 to 0.3.0 (rust-lang/cargo#6724)
This fixes an issue where `--quiet` doesn't work with commands that have subcommands. This is because `config_configure` only looks at the global and top-level subcommand, and not deeper subcommands. The issue was that `--quiet` was not defined as a global flag. This was changed in rust-lang#6358 in order to give a better help message for `cargo test --quiet`. I don't remember if clap just didn't support overriding at the time, or if we just didn't know how it worked. Anyways, it seems to work to override it now, so I think it should be fine to mark it as global. This should bring in `--quiet` more in-line with how `--verbose` works. This means that `--quiet` is now accepted with `cargo report`, `cargo help`, and `cargo config`. This also fixes `--quiet` with `cargo clean gc`. This should also help with supporting `--quiet` with the new `cargo owner` subcommands being added in rust-lang#11879. Fixes rust-lang#12957
This fixes an issue where `--quiet` doesn't work with commands that have subcommands. This is because `config_configure` only looks at the global and top-level subcommand, and not deeper subcommands. The issue was that `--quiet` was not defined as a global flag. This was changed in rust-lang#6358 in order to give a better help message for `cargo test --quiet`. I don't remember if clap just didn't support overriding at the time, or if we just didn't know how it worked. Anyways, it seems to work to override it now, so I think it should be fine to mark it as global. This should bring in `--quiet` more in-line with how `--verbose` works. This means that `--quiet` is now accepted with `cargo report`, `cargo help`, and `cargo config`. This also fixes `--quiet` with `cargo clean gc`. This should also help with supporting `--quiet` with the new `cargo owner` subcommands being added in rust-lang#11879. Fixes rust-lang#12957
Fix --quiet being used with nested subcommands. This fixes an issue where `--quiet` doesn't work with commands that have subcommands. This is because `config_configure` only looks at the global and top-level subcommand, and not deeper subcommands. The issue was that `--quiet` was not defined as a global flag. This was changed in #6358 in order to give a better help message for `cargo test --quiet`. I don't remember if clap just didn't support overriding at the time, or if we just didn't know how it worked. Anyways, it seems to work to override it now, so I think it should be fine to mark it as global. This should bring in `--quiet` more in-line with how `--verbose` works. This means that `--quiet` is now accepted with `cargo report`, `cargo help`, and `cargo config`. This also fixes `--quiet` with `cargo clean gc`. This should also help with supporting `--quiet` with the new `cargo owner` subcommands being added in #11879. As for this diff, the help text changes because the `--quiet` flag is changing position (except for the 3 commands mentioned above where it is now added). Fixes #12957
Fixes #4325