Commit Graph

76 Commits

Author SHA1 Message Date
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
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
Michael Howell
ac7de1a0d9 Ignore Windows due to its differing path syntax 2024-10-30 12:39:05 -07:00
许杰友 Jieyou Xu (Joe)
a864e30269
Rollup merge of #131096 - GuillaumeGomez:rm-no_unused, r=notriddle
rustdoc: Remove usage of `allow(unused)` attribute on `no_run` merged doctests

Fixes [#130681](https://github.com/rust-lang/rust/issues/130681).

It fixes the behaviour difference with the current doctests.

r? ``@notriddle``
2024-10-30 22:22:04 +08:00
Michael Howell
1819b4fa23 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-26 17:56:38 -07:00
Guillaume Gomez
aab2b6747d Add regression test for #131893 2024-10-24 21:35:15 +02:00
Urgau
77b3065ed2 Remove deprecation note in the non_local_definitions warning 2024-10-11 21:21:32 +02:00
Guillaume Gomez
b073ddcce5 Add regression tests for #130681 2024-10-01 17:08:01 +02:00
Guillaume Gomez
6f5f21adfc Rename doctest attribute standalone-crate into standalone_crate for coherency 2024-09-29 13:01:41 +02:00
Guillaume Gomez
632fed891d Improve mistyped docblock attribute warning messages 2024-09-28 18:38:11 +02:00
Guillaume Gomez
84d41e2fc1 Add regression tests for mistyped standalone-crate attribute 2024-09-28 18:38:11 +02:00
Urgau
2423e9e244 Update rustdoc doctest non_local_defs impl test 2024-09-23 10:01:59 +02:00
Urgau
cb58668748 Revert "Switch back non_local_definitions lint to allow-by-default"
This reverts commit 0c0dfb88ee.
2024-09-23 09:23:04 +02:00
Michael Howell
65e432db60 rustdoc: use the correct span for doctests 2024-09-19 13:57:44 -07:00
Guillaume Gomez
a708d0bc77 Fix commands syntax in rustdoc-ui tests 2024-08-13 20:14:57 +02:00
Guillaume Gomez
cbf6fe05e7 Add more merged doctests tests 2024-08-13 20:14:57 +02:00
Guillaume Gomez
4b1db071d1 Don't special-case if there is only one merged doctest 2024-08-13 20:14:56 +02:00
Guillaume Gomez
d512438435 Run mergeable doctest as part of standalone doctests if there is only one 2024-08-13 20:14:56 +02:00