Skip to content

Doctest execution should report discovery and compilation time #144270

Closed

Description

@kpreid

Consider the following output from running doctests:

$ time cargo test -p all-is-cubes-base --doc
    Finished `test` profile [optimized + debuginfo] target(s) in 0.06s
   Doc-tests all_is_cubes_base

running 60 tests
test all-is-cubes-base/src/math.rs - math::notnan (line 60) ... ok
test all-is-cubes-base/src/math/aab.rs - math::aab::Aab::round_up_to_grid (line 331) ... ok
[...]
test all-is-cubes-base/src/resolution.rs - resolution::Resolution::log2 (line 70) ... ok

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


running 4 tests
test all-is-cubes-base/src/math.rs - math::notnan (line 76) - compile fail ... ok
test all-is-cubes-base/src/math.rs - math::notnan (line 91) - compile fail ... ok
test all-is-cubes-base/src/math.rs - math::notnan (line 69) - compile fail ... ok
test all-is-cubes-base/src/math.rs - math::notnan (line 83) - compile fail ... ok

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


real	0m10.268s
user	0m6.745s
sys	0m6.373s

The wall-clock time taken to run this test command is 10 s. The reported time to run these tests is 0.06 s + 0.01 s + 1.55 s, which only adds up to 1.62 s — the time spent discovering and compiling the doctests is not counted and reported. I believe this is a “diagnostic bug” of sorts — information is being omitted which misleads the user about the performance of their project’s test suite (until they carefully watch it progress in real time).

I believe this is caused by merged doctests, in that if I add ```standalone_crate to a doctest, it moves down to the second section and increases the reported time. (But, of course, that also increases the total time needed, so it does not help someone who wishes to improve performance of their test suite.)

It would be ideal if the compilation time was reported separately from the execution time (except for compile-fail tests) so the test author can direct their attention to the right part of the problem. However, it seems that would require either expanding libtest’s OutputFormatter trait or writing output outside of it (to stderr?).

Version

rustdoc 1.88.0 (6b00bc3 2025-06-23)

@rustbot label +A-doctests +A-libtest +T-rustdoc +T-testing-devex

Activity

  1. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Jul 21, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    A-doctestsArea: Documentation tests, run by rustdoc
    A-libtestArea: `#[test]` / the `test` library
    T-testing-devexRelevant to the testing devex team (testing DX), which will review and decide on the PR/issue.
    on Jul 21, 2025
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 21, 2025
  4. GuillaumeGomez commented on Jul 21, 2025

    @GuillaumeGomez
    Member

    The origin of this bug is because rustdoc uses libtest which doesn't compile test, just run them, and therefore doesn't take into account the compilation time. I suppose we can provide this time to the lib.

  5. kpreid commented on Jul 21, 2025

    @kpreid
    ContributorAuthor

    While merely including the compilation time would “fix the regression”, I believe that it would be highly valuable to report the compilation time separately, so that users can distinguish “this doctest takes too long to compile” from “this doctest takes too long to run”, which are very different problems.

  6. GuillaumeGomez commented on Jul 21, 2025

    @GuillaumeGomez
    Member

    That also makes the fix a lot simpler so definitely approve this approach. 😈

  7. added a commit that references this issue on Jul 30, 2025
    61760fb
  8. added a commit that references this issue on Jul 30, 2025
    9064be6
  9. added a commit that references this issue on Dec 21, 2025
    77b922e
  10. added a commit that references this issue on Dec 29, 2025
    396a82e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-doctestsArea: Documentation tests, run by rustdocA-libtestArea: `#[test]` / the `test` libraryC-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.T-testing-devexRelevant to the testing devex team (testing DX), which will review and decide on the PR/issue.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions