-
Notifications
You must be signed in to change notification settings - Fork 14k
[rustdoc] Gracefully handle error in case we cannot run the compiler in doctests #147912
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
[rustdoc] Gracefully handle error in case we cannot run the compiler in doctests #147912
Conversation
I think a message like |
4e0541a to
0c495ae
Compare
|
Agreed, improved error messages. |
|
ping @lolbinarycat |
|
I would prefer using Alternatively, we could just throw the whole command into the error message through it's Debug impl, but that might be a bit noisy. |
0c495ae to
ce42e06
Compare
|
Thanks, much better this way. |
src/librustdoc/doctest.rs
Outdated
| @@ -500,7 +501,7 @@ fn add_exe_suffix(input: String, target: &TargetTuple) -> String { | |||
| input + &exe_suffix | |||
| } | |||
|
|
|||
| fn wrapped_rustc_command(rustc_wrappers: &[PathBuf], rustc_binary: &Path) -> Command { | |||
| fn wrapped_rustc_command<'a>(rustc_wrappers: &'a [PathBuf], rustc_binary: &'a Path) -> Command { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the explicit lifetime? leftover from when it returned a tuple?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oups indeed, removing that.
src/librustdoc/doctest.rs
Outdated
| @@ -670,7 +671,14 @@ fn run_test( | |||
|
|
|||
| debug!("compiler invocation for doctest: {compiler:?}"); | |||
|
|
|||
| let mut child = compiler.spawn().expect("Failed to spawn rustc process"); | |||
| let binary_path = compiler.get_program().to_os_string(); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to clone this, it's not like spawn consumes the command or holds a mutable borrow to it, so we just need to make sure we're calling get_program after spawn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was sure spawn was taking self and not &mut self. Well, good to know. :)
src/librustdoc/doctest.rs
Outdated
| let binary_path = runner_compiler.get_program().to_os_string(); | ||
| let mut child_runner = match runner_compiler.spawn() { | ||
| Ok(child) => child, | ||
| Err(error) => { | ||
| eprintln!("Failed to spawn {binary_path:?}: {error:?}"); | ||
| return (Duration::default(), Err(TestFailure::CompileError)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let binary_path = runner_compiler.get_program().to_os_string(); | |
| let mut child_runner = match runner_compiler.spawn() { | |
| Ok(child) => child, | |
| Err(error) => { | |
| eprintln!("Failed to spawn {binary_path:?}: {error:?}"); | |
| return (Duration::default(), Err(TestFailure::CompileError)); | |
| } | |
| let mut child_runner = match runner_compiler.spawn() { | |
| Ok(child) => child, | |
| Err(error) => { | |
| let binary_path = runner_compiler.get_program(); | |
| eprintln!("Failed to spawn {binary_path:?}: {error:?}"); | |
| return (Duration::default(), Err(TestFailure::CompileError)); | |
| } |
as explained above
| .arg("--test-builder") | ||
| .arg(&absolute_path) | ||
| .run_fail(); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets also assert that the exit code is 1 (ICE gives 101, like other panics), seems more robust than string comparisons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
panic! isn't always 101 as exit code (depends on the target). So we can't really check for that. ^^'
Discovered that while reading https://github.com/rust-lang/rust/blob/master/library/test/src/test_result.rs#L107.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, you can just stick it behind a cfg(unix) or something, it would still me more reliable than only looking at the strings.
Is normal error exit always 1? Because that's what I was reccomending we actually put in the assertion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case should be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, when we fail doctests, we exit with 101. ^^'
ce42e06 to
29fe476
Compare
This comment has been minimized.
This comment has been minimized.
|
Updated! |
29fe476 to
db69dbc
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
So I added the assert for |
|
If I think what I would actually like is for there to be a function in |
|
I really like this idea! Gonna need to involve someone else from |
db69dbc to
bc50a23
Compare
|
The run-make-support library was changed cc @jieyouxu |
|
@jieyouxu: I added a new |
| /// Checks that `stderr` contains the Internal Compiler Error message. | ||
| #[track_caller] | ||
| pub fn assert_ice(&self) -> &Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// Checks that `stderr` contains the Internal Compiler Error message. | |
| #[track_caller] | |
| pub fn assert_ice(&self) -> &Self { | |
| /// Checks that `stderr` does not contain the Internal Compiler Error message. | |
| #[track_caller] | |
| pub fn assert_not_ice(&self) -> &Self { |
Previously it looked like a function that asserted that the compiler did encounter an ICE error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Euh yeah, completely reversed everything...
bc50a23 to
ea38070
Compare
|
Fixed doc and method's name. |
Seems good 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized we don't actually have any test coverage for the non-error case of --test-builder.
Unsure if we want to add that here or in a followup, I'm not familiar enough with the option to know how much effort that would be.
| .arg(&absolute_path) | ||
| .run_fail(); | ||
|
|
||
| // We also double-check that we don't have the panic text in the output. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording of this comment doesn't really fit anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arf indeed, missed it.
|
@rustbot author |
ea38070 to
2c3c82c
Compare
That's... well pretty bad. Gonna open an issue for that. Anyway, updated. |
|
Since this is nightly-only and the actual changes to rustdoc are so simple, I think it's fine to push this through without waiting for for @bors r+ |
…ror-handling, r=lolbinarycat [rustdoc] Gracefully handle error in case we cannot run the compiler in doctests Fixes bug reported in [this comment](rust-lang#102981 (comment)). r? `@lolbinarycat`
Rollup of 7 pull requests Successful merges: - #145656 (Stabilize s390x `vector` target feature and `is_s390x_feature_detected!` macro) - #147043 (Add default sanitizers to TargetOptions) - #147803 (Add -Zannotate-moves for profiler visibility of move/copy operations (codegen)) - #147912 ([rustdoc] Gracefully handle error in case we cannot run the compiler in doctests) - #148540 (Minor fixes to StdNonZeroNumberProvider for gdb) - #148541 (Add num_children method to some gdb pretty-printers) - #148549 (Fix broken qemu-cskyv2 link) Failed merges: - #147586 (std-detect: improve detect macro docs) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 7 pull requests Successful merges: - #143037 (Make named asm_labels lint not trigger on hexagon register spans) - #147043 (Add default sanitizers to TargetOptions) - #147586 (std-detect: improve detect macro docs) - #147912 ([rustdoc] Gracefully handle error in case we cannot run the compiler in doctests) - #148540 (Minor fixes to StdNonZeroNumberProvider for gdb) - #148541 (Add num_children method to some gdb pretty-printers) - #148549 (Fix broken qemu-cskyv2 link) Failed merges: - #147935 (Add LLVM realtime sanitizer) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #147912 - GuillaumeGomez:graceful-doctest-error-handling, r=lolbinarycat [rustdoc] Gracefully handle error in case we cannot run the compiler in doctests Fixes bug reported in [this comment](#102981 (comment)). r? ``@lolbinarycat``
Fixes bug reported in this comment.
r? @lolbinarycat