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

Add --quiet option for cargo test #6358

Merged
merged 5 commits into from
Mar 11, 2019
Merged

Add --quiet option for cargo test #6358

merged 5 commits into from
Mar 11, 2019

Conversation

collin5
Copy link
Contributor

@collin5 collin5 commented Nov 28, 2018

Fixes #4325

).build();

p.cargo("test -q hello")
.with_stdout_contains("running 1 test")
Copy link
Member

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("")

Copy link
Contributor Author

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

Copy link
Member

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.

@collin5
Copy link
Contributor Author

collin5 commented Nov 29, 2018

Updated. Thank you!

@dwijnand
Copy link
Member

Hmm that's the global -q for all commands. We'd have to find a way to do it just for the test command...

@collin5
Copy link
Contributor Author

collin5 commented Nov 29, 2018

🤦‍♂️ Oops! my bad. Hadn't noticed this. Going to fix this in a few.

@collin5
Copy link
Contributor Author

collin5 commented Nov 29, 2018

Fixed. test command --quiet description should now override global option. Thanks!

Copy link
Member

@alexcrichton alexcrichton left a 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.

)
}

// add --quiet option to command
Copy link
Member

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?

Copy link
Contributor Author

@collin5 collin5 Dec 8, 2018

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

.global(true),
. I'm adding this to all subcommands except those that already have this option defined to allow these to override this option (as currently couldn't find a way to override the description for a global option for clap.rs). One other option would be to explicitly add --quiet for all other subcommands OR for only cargo test if this is not required for others.

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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!

@collin5
Copy link
Contributor Author

collin5 commented Dec 16, 2018

Updated the PR to explicitly add --quiet to each subcommand. Any ideas on how to go about defining arguments to pass to the test harnesses. Thanks

@alexcrichton
Copy link
Member

In terms of definition, I think in theory --quiet should be defined next to --verbose? In terms of how to make progress on this though with tests harnesses I'm not entirely sure :(

@ehuss
Copy link
Contributor

ehuss commented Dec 17, 2018

Maybe a crazy idea, but related to custom test frameworks, the [testing.framework] section could have some sort of table which describes what capabilities a harness has. I can imagine other things like JSON output, color control, setting --test-threads, could be useful.

In the short term, maybe it can just skip the flag when harness=false?

@alexcrichton
Copy link
Member

That seems plausible to me! In any case not passing it through automatically with harness = false sounds reasonable to me

@bors
Copy link
Collaborator

bors commented Feb 5, 2019

☔ The latest upstream changes (presumably #6631) made this pull request unmergeable. Please resolve the merge conflicts.

@ehuss
Copy link
Contributor

ehuss commented Feb 14, 2019

Ping @collin5 do you think you'd be able to change it so that it doesn't forward flags if harness is false?

@collin5
Copy link
Contributor Author

collin5 commented Feb 14, 2019

@ehuss Sorry for the delay on this, been a bit busy lately. Will be working on it this weekend. Thanks for the reminder.

@collin5
Copy link
Contributor Author

collin5 commented Feb 21, 2019

Changed to forwarding the --quiet, -q flag only if harness is true. Thank you. cc @alexcrichton @ehuss

@@ -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());
Copy link
Contributor

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?

Copy link
Contributor Author

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!

@nrc nrc assigned ehuss Mar 6, 2019
@ehuss ehuss added the S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. label Mar 7, 2019
@collin5
Copy link
Contributor Author

collin5 commented Mar 9, 2019

Updated! Thank you. @ehuss

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 {
Copy link
Contributor

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".

Copy link
Contributor Author

@collin5 collin5 Mar 11, 2019

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

@ehuss
Copy link
Contributor

ehuss commented Mar 11, 2019

Thanks @collin5!

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 11, 2019

📌 Commit d93b2d7 has been approved by ehuss

@bors
Copy link
Collaborator

bors commented Mar 11, 2019

⌛ Testing commit d93b2d7 with merge d74d879...

bors added a commit that referenced this pull request Mar 11, 2019
Add --quiet option for `cargo test`

Fixes #4325
@bors
Copy link
Collaborator

bors commented Mar 11, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: ehuss
Pushing d74d879 to master...

@bors bors merged commit d93b2d7 into rust-lang:master Mar 11, 2019
@collin5 collin5 deleted the b4325 branch March 11, 2019 19:29
bors added a commit to rust-lang/rust that referenced this pull request Mar 13, 2019
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)
bors added a commit to rust-lang/rust that referenced this pull request Mar 13, 2019
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)
@ehuss ehuss added this to the 1.35.0 milestone Feb 6, 2022
ehuss added a commit to ehuss/cargo that referenced this pull request Nov 11, 2023
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
ehuss added a commit to ehuss/cargo that referenced this pull request Nov 12, 2023
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
bors added a commit that referenced this pull request Nov 12, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo test -q not works as expected
5 participants