report fatal errors during doctest parsing
This commit is contained in:
parent
a850a42649
commit
a912664113
4 changed files with 55 additions and 6 deletions
|
@ -166,9 +166,18 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
|
||||||
compile_fail: bool, mut error_codes: Vec<String>, opts: &TestOptions,
|
compile_fail: bool, mut error_codes: Vec<String>, opts: &TestOptions,
|
||||||
maybe_sysroot: Option<PathBuf>, linker: Option<PathBuf>, edition: Edition,
|
maybe_sysroot: Option<PathBuf>, linker: Option<PathBuf>, edition: Edition,
|
||||||
persist_doctests: Option<PathBuf>) {
|
persist_doctests: Option<PathBuf>) {
|
||||||
// The test harness wants its own `main` and top-level functions, so
|
let (test, line_offset) = match panic::catch_unwind(|| {
|
||||||
// never wrap the test in `fn main() { ... }`.
|
make_test(test, Some(cratename), as_test_harness, opts)
|
||||||
let (test, line_offset) = make_test(test, Some(cratename), as_test_harness, opts);
|
}) {
|
||||||
|
Ok((test, line_offset)) => (test, line_offset),
|
||||||
|
Err(cause) if cause.is::<errors::FatalErrorMarker>() => {
|
||||||
|
// If the parser used by `make_test` panicked due to a fatal error, pass the test code
|
||||||
|
// through unchanged. The error will be reported during compilation.
|
||||||
|
(test.to_owned(), 0)
|
||||||
|
},
|
||||||
|
Err(cause) => panic::resume_unwind(cause),
|
||||||
|
};
|
||||||
|
|
||||||
// FIXME(#44940): if doctests ever support path remapping, then this filename
|
// FIXME(#44940): if doctests ever support path remapping, then this filename
|
||||||
// needs to be the result of `SourceMap::span_to_unmapped_path`.
|
// needs to be the result of `SourceMap::span_to_unmapped_path`.
|
||||||
let path = match filename {
|
let path = match filename {
|
||||||
|
@ -337,7 +346,13 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Makes the test file. Also returns the number of lines before the code begins
|
/// Transforms a test into code that can be compiled into a Rust binary, and returns the number of
|
||||||
|
/// lines before the test code begins.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// This function uses the compiler's parser internally. The parser will panic if it encounters a
|
||||||
|
/// fatal error while parsing the test.
|
||||||
pub fn make_test(s: &str,
|
pub fn make_test(s: &str,
|
||||||
cratename: Option<&str>,
|
cratename: Option<&str>,
|
||||||
dont_insert_main: bool,
|
dont_insert_main: bool,
|
||||||
|
|
|
@ -15,7 +15,7 @@ error[E0425]: cannot find value `no` in this scope
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0425`.
|
For more information about this error, try `rustc --explain E0425`.
|
||||||
thread '$DIR/failed-doctest-output.rs - OtherStruct (line 17)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:310:13
|
thread '$DIR/failed-doctest-output.rs - OtherStruct (line 17)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:319:13
|
||||||
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
|
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
|
||||||
|
|
||||||
---- $DIR/failed-doctest-output.rs - SomeStruct (line 11) stdout ----
|
---- $DIR/failed-doctest-output.rs - SomeStruct (line 11) stdout ----
|
||||||
|
@ -24,7 +24,7 @@ thread '$DIR/failed-doctest-output.rs - SomeStruct (line 11)' panicked at 'test
|
||||||
thread 'main' panicked at 'oh no', $DIR/failed-doctest-output.rs:3:1
|
thread 'main' panicked at 'oh no', $DIR/failed-doctest-output.rs:3:1
|
||||||
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
|
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
|
||||||
|
|
||||||
', src/librustdoc/test.rs:332:17
|
', src/librustdoc/test.rs:341:17
|
||||||
|
|
||||||
|
|
||||||
failures:
|
failures:
|
||||||
|
|
10
src/test/rustdoc-ui/unparseable-doc-test.rs
Normal file
10
src/test/rustdoc-ui/unparseable-doc-test.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
// compile-flags: --test
|
||||||
|
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
|
||||||
|
// failure-status: 101
|
||||||
|
// rustc-env: RUST_BACKTRACE=0
|
||||||
|
|
||||||
|
/// ```rust
|
||||||
|
/// let x = 7;
|
||||||
|
/// "unterminated
|
||||||
|
/// ```
|
||||||
|
pub fn foo() {}
|
24
src/test/rustdoc-ui/unparseable-doc-test.stdout
Normal file
24
src/test/rustdoc-ui/unparseable-doc-test.stdout
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
|
||||||
|
running 1 test
|
||||||
|
test $DIR/unparseable-doc-test.rs - foo (line 6) ... FAILED
|
||||||
|
|
||||||
|
failures:
|
||||||
|
|
||||||
|
---- $DIR/unparseable-doc-test.rs - foo (line 6) stdout ----
|
||||||
|
error: unterminated double quote string
|
||||||
|
--> $DIR/unparseable-doc-test.rs:8:1
|
||||||
|
|
|
||||||
|
2 | "unterminated
|
||||||
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
thread '$DIR/unparseable-doc-test.rs - foo (line 6)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:319:13
|
||||||
|
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
|
||||||
|
|
||||||
|
|
||||||
|
failures:
|
||||||
|
$DIR/unparseable-doc-test.rs - foo (line 6)
|
||||||
|
|
||||||
|
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue