92 Commits

Author SHA1 Message Date
León Orell Valerian Liehr
11b82e134c rustdoc: Rename unstable option --nocapture to --no-capture 2025-10-25 19:45:49 +02:00
Matthias Krüger
dbc5e72ea2 Rollup merge of #147292 - Urgau:rustdoc-test-unstable_opts, r=fmease
Respect `-Z` unstable options in `rustdoc --test`

This PR makes rustdoc respect `-Z` unstable options when collecting doctests (`rustdoc --test`).

In the process I also realized that `--error-format` wasn't respected as well, making UI annotations impossible to write so I fixed that as well.

Best reviewed commit by commit.

Fixes https://github.com/rust-lang/rust/issues/147276
Fixes https://github.com/rust-lang/rust/issues/143930
r? fmease
2025-10-03 21:10:33 +02:00
Urgau
c1443e2591 Add regression test for -Zcrate-attr in rustdoc --test 2025-10-03 17:04:17 +02:00
Urgau
e914a1a6e0 Respect --error-format in rustdoc --test 2025-10-03 17:04:17 +02:00
Urgau
3d5f54ad55 Respect -Z unstable options in rustdoc --test 2025-10-03 12:05:31 +02:00
Guillaume Gomez
b7e444de16 Add regression test for merged doctests compilation time display 2025-09-26 22:04:00 +02:00
Trevor Gross
289fe36d37 Print thread ID in panic message if thread name is unknown
`panic!` does not print any identifying information for threads that are
unnamed. However, in many cases, the thread ID can be determined.

This changes the panic message from something like this:

    thread '<unnamed>' panicked at src/main.rs:3:5:
    explicit panic

To something like this:

    thread '<unnamed>' (0xff9bf) panicked at src/main.rs:3:5:
    explicit panic

Stack overflow messages are updated as well.

This change applies to both named and unnamed threads. The ID printed is
the OS integer thread ID rather than the Rust thread ID, which should
also be what debuggers print.
2025-08-06 23:59:47 +00:00
Samuel Tardieu
61760fbda4 Rollup merge of #144308 - GuillaumeGomez:merged-doctest-times, r=lolbinarycat
[rustdoc] Display total time and compilation time of merged doctests

Fixes rust-lang/rust#144270.

Does it look good to you `@kpreid?`

<img width="908" height="263" alt="image" src="https://github.com/user-attachments/assets/cd5d082d-c4e0-42ed-91dd-bd263b413dcd" />
2025-07-30 19:49:02 +02:00
Scott Schafer
aa9767290e feat: Right align line numbers 2025-07-28 16:32:11 -06:00
Guillaume Gomez
64e3078bbd Update rustdoc ui tests 2025-07-24 11:06:28 +02:00
Urgau
d96d3bed6f Collect and use #[doc(test(attr(..)))] at every level 2025-05-22 20:12:50 +02:00
Urgau
041d95d4dc Allow #![doc(test(attr(..)))] doctests to be again merged together 2025-05-22 20:12:50 +02:00
Urgau
9d9705f4c3 Collect and use #![doc(test(attr(..)))] at module level too 2025-05-22 20:10:32 +02:00
bors
1d679446b0 Auto merge of #140527 - GuillaumeGomez:doctest-main-fn, r=notriddle
Emit a warning if the doctest `main` function will not be run

Fixes #140310.

I think we could try to go much further like adding a "link" (ie UI annotations) on the `main` function in the doctest. However that will require some more computation, not sure if it's worth it or not. Can still be done in a follow-up if we want it.

For now, this PR does two things:
1. Pass the `DiagCtxt` to the doctest parser to emit the warning.
2. Correctly generate the `Span` to where the doctest is starting (I hope the way I did it isn't too bad either...).

cc `@fmease`
r? `@notriddle`
2025-05-22 08:40:58 +00:00
Matthias Krüger
7a5bbe0527 Rollup merge of #139863 - fmease:simp-doctest-build-arg-passing, r=GuillaumeGomez
rustdoc: Replace unstable flag `--doctest-compilation-args` with a simpler one: `--doctest-build-arg`

Tracking issue: https://github.com/rust-lang/rust/issues/134172.
Context: https://github.com/rust-lang/rust/pull/137096#issuecomment-2776318800

Yeets the ad hoc shell-like lexer for 'nested' program arguments.
No FCP necessary since the flag is unstable.

I've chosen to replace `compilation` with `build` because it's shorter (you now need to pass it multiple times in order to pass many arguments to the doctest compiler, so it matters a bit) and since I prefer it esthetically.

**Issue**: Even though we don't process the argument passed to `--doctest-build-arg`, we end up passing it via an argument file (`rustc `@argfile`)` which delimits arguments by line break (LF or CRLF, [via](https://doc.rust-lang.org/rustc/command-line-arguments.html#path-load-command-line-flags-from-a-path)) meaning ultimately the arguments still get split which is unfortunate. Still, I think this change is an improvement over the status quo.

I'll update the tracking issue if/once this PR merges. I'll also add the (CR)LF issue to 'unresolved question'.

r? GuillaumeGomez
r? notriddle
2025-05-09 21:50:06 +02:00
Guillaume Gomez
5b86fa8282 Add regression test for #140310 2025-05-02 13:57:53 +02:00
Guillaume Gomez
b791eaa448 Emit a warning if the doctest main function will not be run 2025-05-02 13:57:53 +02:00
León Orell Valerian Liehr
714ea10ea4 rustdoc: Fix doctest heuristic for main fn wrapping 2025-05-01 11:56:11 +02:00
Guillaume Gomez
a782b54e01 Rollup merge of #140220 - GuillaumeGomez:doctest-main-wrapping, r=fmease
Fix detection of main function if there are expressions around it

Fixes #140162.
Fixes #139651.

Once this is merged, we can backport and I'll send a follow-up to emit a warning in case a `main` function is about to be "wrapped" (and therefore not run).

r? `@fmease`

try-job: x86_64-mingw-1
2025-04-28 13:30:44 +02:00
Guillaume Gomez
aa69e3a0cb Fix bad handling of macros if there is already a main function 2025-04-27 00:12:32 +02:00
Guillaume Gomez
3ef98a55ef If there is a ; alone, we consider that the doctest needs to be put inside a function 2025-04-25 22:04:50 +02:00
Guillaume Gomez
c44068b916 Add rustdoc-ui regression test for #140289 2025-04-25 15:55:54 +02:00
Guillaume Gomez
70c389e069 Correctly display stdout and stderr in case a doctest is failing 2025-04-25 14:13:24 +02:00
Guillaume Gomez
81438c0b05 Add regression ui test for #140162 and for #139651 2025-04-23 22:09:35 +02:00
León Orell Valerian Liehr
307a67a02a Replace flag --doctest-compilation-args with a simpler one: --doctest-build-arg
More notably, the value of the new flag does *not* get lexed shell-like and ad hoc.
2025-04-15 15:44:45 +02:00
xizheyin
c73598f0fb Report span of test when should_panic test failed
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-14 10:36:11 +08:00
Pietro Albini
cd371b90e2 replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
Matthias Krüger
cfc2297cfc Rollup merge of #139328 - GuillaumeGomez:fix-panic-output-137970, r=fmease
Fix 2024 edition doctest panic output

Fixes #137970.

The problem was that the output was actually displayed by rustc itself because we're exiting with `Result<(), String>`, and the display is really not great. So instead, we get the output, we print it and then we return an `ExitCode`.

r? ````@aDotInTheVoid````
2025-04-04 21:54:57 +02:00
Guillaume Gomez
f9927ee042 Use eprint! instead of eprintln! 2025-04-03 19:37:18 +02:00
Vadim Petrochenkov
4d64990690 compiletest: Require //~ annotations even if error-pattern is specified 2025-04-03 11:08:55 +03:00
Matthias Krüger
ad87732cae Rollup merge of #138104 - GuillaumeGomez:simplify-doctest-parsing, r=fmease
Greatly simplify doctest parsing and information extraction

The original process was pretty terrible, as it tried to extract information such as attributes by performing matches over tokens like `#!`, which doesn't work very well considering you can have `#   ! [`, which is valid.

Also, it now does it in one pass: if the parser is happy, then we try to extract information, otherwise we return early.

r? `@fmease`
2025-03-28 12:59:55 +01:00
Guillaume Gomez
123ea25542 Correctly handle line comments in attributes and generate extern crates
outside of wrapping function
2025-03-27 11:18:43 +01:00
Takayuki Maeda
90c541d637 ignore doctests only in specified targets
add necessary lines

fix ui test error
2025-03-25 15:39:41 +09:00
Esteban Küber
f0b8e13b59 Do not suggest using -Zmacro-backtrace for builtin macros
For macros that are implemented on the compiler, we do *not* mention the `-Zmacro-backtrace` flag. This includes `derive`s and standard macros.
2025-03-14 19:50:03 +00:00
Michael Howell
9cf531d26f doctests: build test bundle and harness separately
This prevents the included test case from getting at nightly-only
features when run on stable. The harness builds with
RUSTC_BOOTSTRAP, but the bundle doesn't.
2025-03-10 01:47:36 +01:00
Chris Denton
95a5ecc995 Enable relative-path-include-bytes on Windows 2025-02-16 10:40:04 +00:00
Ben Kimock
7dfc786df1 Enable more tests on Windows 2025-02-03 10:39:32 -05:00
许杰友 Jieyou Xu (Joe)
64768c5630 Rollup merge of #135736 - fmease:rustdoc-fix-flaky-test, r=GuillaumeGomez
rustdoc: Fix flaky doctest test

Fixes #135660.
2025-01-20 12:37:55 +08:00
León Orell Valerian Liehr
64d667ae78 rustdoc: Fix flaky doctest test 2025-01-19 18:41:11 +01:00
John Kåre Alsaker
4bf85c25ec Try to write the panic message with a single write_all call 2025-01-01 15:58:29 +01:00
peicuiping
09541c263e chore: fix some typos
Signed-off-by: peicuiping <ezc5@sina.cn>
2024-12-31 15:11:18 +08:00
Zalathar
835fbcbcab Remove the -test suffix from normalize directives 2024-12-27 19:58:16 +11:00
Guillaume Gomez
2d914bed2d Add test to ensure passing --doctest_compilation_args multiple times work 2024-12-20 22:35:00 +01:00
Guillaume Gomez
2bd869082b Add regression test for --doctest-compilation-args 2024-12-20 15:17:47 +01:00
Guillaume Gomez
c367cc3ef5 Remove unneeded handling of backlines in doctest attributes 2024-12-16 17:59:07 +01:00
Guillaume Gomez
2383985342 Also handle cases where attributes are unclosed 2024-12-16 13:59:41 +01:00
Guillaume Gomez
9c4a61ff52 Add ui regression test for #134221 2024-12-16 11:47:56 +01:00
Eric Huss
6005d1c9f7 Update more 2024 tests to remove -Zunstable-options 2024-11-28 14:32:45 -08:00
Eric Huss
31c9222639 Stabilize the 2024 edition 2024-11-22 11:12:15 -08:00
Jubilee
62ba25de39 Rollup merge of #132210 - notriddle:notriddle/doctest-span-hack, r=GuillaumeGomez
rustdoc: make doctest span tweak a 2024 edition change

Fixes #132203

This is a compatibility hack, because I think the new behavior is better. When an A `include_str!` B, and B `include_str!` C, the path to C should be resolved relative to B, not A. That's how `include!` itself works, so that's how `include_str!` with should work.
2024-10-30 14:01:37 -07:00