report doctest compile failures correctly

This commit is contained in:
QuietMisdreavus 2018-07-09 19:11:06 -05:00
parent 33654195a1
commit 41e7ac16c4
3 changed files with 41 additions and 25 deletions

View File

@ -260,7 +260,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
let old = io::set_panic(Some(box Sink(data.clone())));
let _bomb = Bomb(data.clone(), old.unwrap_or(box io::stdout()));
let (libdir, outdir) = driver::spawn_thread_pool(sessopts, |sessopts| {
let (libdir, outdir, compile_result) = driver::spawn_thread_pool(sessopts, |sessopts| {
let codemap = Lrc::new(CodeMap::new_doctest(
sessopts.file_path_mapping(), filename.clone(), line as isize - line_offset as isize
));
@ -314,29 +314,29 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
Err(_) | Ok(Err(CompileIncomplete::Errored(_))) => Err(())
};
match (compile_result, compile_fail) {
(Ok(()), true) => {
panic!("test compiled while it wasn't supposed to")
}
(Ok(()), false) => {}
(Err(()), true) => {
if error_codes.len() > 0 {
let out = String::from_utf8(data.lock().unwrap().to_vec()).unwrap();
error_codes.retain(|err| !out.contains(err));
}
}
(Err(()), false) => {
panic!("couldn't compile the test")
}
}
if error_codes.len() > 0 {
panic!("Some expected error codes were not found: {:?}", error_codes);
}
(libdir, outdir)
(libdir, outdir, compile_result)
});
match (compile_result, compile_fail) {
(Ok(()), true) => {
panic!("test compiled while it wasn't supposed to")
}
(Ok(()), false) => {}
(Err(()), true) => {
if error_codes.len() > 0 {
let out = String::from_utf8(data.lock().unwrap().to_vec()).unwrap();
error_codes.retain(|err| !out.contains(err));
}
}
(Err(()), false) => {
panic!("couldn't compile the test")
}
}
if error_codes.len() > 0 {
panic!("Some expected error codes were not found: {:?}", error_codes);
}
if no_run { return }
// Run the code!

View File

@ -17,3 +17,8 @@
/// panic!("oh no");
/// ```
pub struct SomeStruct;
/// ```
/// no
/// ```
pub struct OtherStruct;

View File

@ -1,9 +1,20 @@
running 1 test
running 2 tests
test src/test/rustdoc-ui/failed-doctest-output.rs - OtherStruct (line 21) ... FAILED
test src/test/rustdoc-ui/failed-doctest-output.rs - SomeStruct (line 16) ... FAILED
failures:
---- src/test/rustdoc-ui/failed-doctest-output.rs - OtherStruct (line 21) stdout ----
error[E0425]: cannot find value `no` in this scope
--> src/test/rustdoc-ui/failed-doctest-output.rs:22:1
|
3 | no
| ^^ not found in this scope
thread 'src/test/rustdoc-ui/failed-doctest-output.rs - OtherStruct (line 21)' panicked at 'couldn't compile the test', librustdoc/test.rs:332:13
note: Run with `RUST_BACKTRACE=1` for a backtrace.
---- src/test/rustdoc-ui/failed-doctest-output.rs - SomeStruct (line 16) stdout ----
thread 'src/test/rustdoc-ui/failed-doctest-output.rs - SomeStruct (line 16)' panicked at 'test executable failed:
@ -11,11 +22,11 @@ thread 'main' panicked at 'oh no', src/test/rustdoc-ui/failed-doctest-output.rs:
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/test/rustdoc-ui/failed-doctest-output.rs - OtherStruct (line 21)
src/test/rustdoc-ui/failed-doctest-output.rs - SomeStruct (line 16)
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out