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

doctests run via cargo test are not silenced with --quiet #9728

Closed
bruxisma opened this issue Jul 27, 2021 · 2 comments · Fixed by #9730
Closed

doctests run via cargo test are not silenced with --quiet #9728

bruxisma opened this issue Jul 27, 2021 · 2 comments · Fixed by #9730
Assignees
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. A-doctests Area: rustdoc --test C-bug Category: bug E-easy Experience: Easy

Comments

@bruxisma
Copy link

bruxisma commented Jul 27, 2021

Problem
When passing --quiet to cargo test, doctests are still printed in a verbose style, a though --quiet had not been forwarded to them (output cut for brevity)

$ cargo test --quiet

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


running 36 tests
test src/lib.rs - (line 156) ... ignored
test src/lib.rs - (line 173) ... ignored
test src/lib.rs - (line 71) ... ok
test src/lib.rs - (line 27) ... ok
test src/lib.rs - (line 10) ... ok
# ...
test result: ok. 34 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out; finished in 2.48s

This can also be seen by running cargo test -- --quiet, which manually passes --quiet to each doctest.

$ cargo test -- --quiet

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests my-crate


running 36 tests
ii..................................
test result: ok. 34 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out; finished in 2.51s

Steps

  1. Add several doctests to any library crate
  2. Run cargo test --quiet
  3. Run cargo test -- --quiet

Possible Solution(s)
After looking in src/cargo/ops/cargo_test.rs, I noticed that run_unit_tests will add --quiet to each target if harness=true and the verbosity is set to quiet.

However, this same operation does not happen in run_doc_tests. Having had a brief look at the source it seems the same unit.target.harness() and console.shell().verbosity() could be done after the test_args are pushed into the command

This would explain why --quiet does not work, but -- --quiet does.

Notes

Output of cargo version: cargo 1.53.0 (4369396 2021-04-27)
OS: Windows 10

Although I linked above to recent commits, this code has remained untouched since March of 2021.

@bruxisma bruxisma added the C-bug Category: bug label Jul 27, 2021
@ehuss
Copy link
Contributor

ehuss commented Jul 27, 2021

Thanks for the report! Yea, it should be easy to add. No need to check for the harness, since rustdoc does not support custom harnesses. It just needs to be passed as a --test-arg.

@ehuss ehuss added A-console-output Area: Terminal output, colors, progress bar, etc. A-doctests Area: rustdoc --test E-easy Experience: Easy labels Jul 27, 2021
@Rustin170506
Copy link
Member

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. A-doctests Area: rustdoc --test C-bug Category: bug E-easy Experience: Easy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants