Open QuietMisdreavus opened 5 years ago
👍
I'd like to remove the panic from doc test error handling. Currently, if you have a doc test that fails or panics, you get output with 2 panics in it:
running 1 test
test src/lib.rs - Foo (line 1) ... FAILED
failures:
---- src/lib.rs - Foo (line 1) stdout ----
thread 'src/lib.rs - Foo (line 1)' panicked at 'test executable failed:
thread 'main' panicked at 'explicit panic', src/lib.rs:3:1
note: Run with `RUST_BACKTRACE=1` for a backtrace.
', librustdoc/test.rs:367:17
note: Run with `RUST_BACKTRACE=1` for a backtrace.
failures:
src/lib.rs - Foo (line 1)
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
A couple large items that i can think of:
main
function on their own) and cause a doctest to fail when it actually should create a proper executable. I see two ways to fix this, but they won't be easy:
main
-wrapping before macro expansion (as a proc-macro or equivalent), then to inspect the AST after macro expansion to see whether the expanded code inserted a main
function of its own. This may be a little more cumbersome to reason about, but it's also a lot easier to implement, as it requires no extra work in libsyntax.cc @rtsuk
This will require a sort of two-phase model, where compilation and execution are handled separately.
Yes, I also need this because I want to be able to cross-compile doctests and run them on a different platform from the host compiler.
Yes, I also need this because I want to be able to cross-compile doctests and run them on a different platform from the host compiler.
Right, and this is quite close to being possible once the --persist-doctests
flag is ready, though it will compile each doctest separately. Creating the "single executable" model is another layer on top of that, where we'll have to separate the compilation and execution in the code itself, rather than just skipping execution if we cross-compile the doctest.
Sounds pretty reasonable to me :+1:
I'd be more than happy to tackle some of the remaining text-based stuff you mention since I've already done it once!
There's been a lot of activity in trying to improve doctests recently. Most notably, a couple contributors outside the Rustdoc Team have really stepped up to help out: @euclio and @rep-nop. It would be cool to coordinate improvements to doctests so we can plan out our changes and not step on each other's toes.
(I'll try to fill this thread with some ideas that i remember seeing or wanting, but full discussion may have to wait until the All-Hands on February 4-8 so i have dedicated time to think about it. In the meantime, feel free to pitch ideas here!)