Skip to content

Commit 75d0a95

Browse files
QuietMisdreavuspietroalbini
authored andcommitted
report doctest compile failures correctly
1 parent 7f0c8e4 commit 75d0a95

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

src/librustdoc/test.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
260260
let old = io::set_panic(Some(box Sink(data.clone())));
261261
let _bomb = Bomb(data.clone(), old.unwrap_or(box io::stdout()));
262262

263-
let (libdir, outdir) = driver::spawn_thread_pool(sessopts, |sessopts| {
263+
let (libdir, outdir, compile_result) = driver::spawn_thread_pool(sessopts, |sessopts| {
264264
let codemap = Lrc::new(CodeMap::new_doctest(
265265
sessopts.file_path_mapping(), filename.clone(), line as isize - line_offset as isize
266266
));
@@ -312,28 +312,28 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
312312
Err(_) | Ok(Err(CompileIncomplete::Errored(_))) => Err(())
313313
};
314314

315-
match (compile_result, compile_fail) {
316-
(Ok(()), true) => {
317-
panic!("test compiled while it wasn't supposed to")
318-
}
319-
(Ok(()), false) => {}
320-
(Err(()), true) => {
321-
if error_codes.len() > 0 {
322-
let out = String::from_utf8(data.lock().unwrap().to_vec()).unwrap();
323-
error_codes.retain(|err| !out.contains(err));
324-
}
325-
}
326-
(Err(()), false) => {
327-
panic!("couldn't compile the test")
315+
(libdir, outdir, compile_result)
316+
});
317+
318+
match (compile_result, compile_fail) {
319+
(Ok(()), true) => {
320+
panic!("test compiled while it wasn't supposed to")
321+
}
322+
(Ok(()), false) => {}
323+
(Err(()), true) => {
324+
if error_codes.len() > 0 {
325+
let out = String::from_utf8(data.lock().unwrap().to_vec()).unwrap();
326+
error_codes.retain(|err| !out.contains(err));
328327
}
329328
}
330-
331-
if error_codes.len() > 0 {
332-
panic!("Some expected error codes were not found: {:?}", error_codes);
329+
(Err(()), false) => {
330+
panic!("couldn't compile the test")
333331
}
332+
}
334333

335-
(libdir, outdir)
336-
});
334+
if error_codes.len() > 0 {
335+
panic!("Some expected error codes were not found: {:?}", error_codes);
336+
}
337337

338338
if no_run { return }
339339

src/test/rustdoc-ui/failed-doctest-output.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@
1717
/// panic!("oh no");
1818
/// ```
1919
pub struct SomeStruct;
20+
21+
/// ```
22+
/// no
23+
/// ```
24+
pub struct OtherStruct;
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11

2-
running 1 test
2+
running 2 tests
3+
test src/test/rustdoc-ui/failed-doctest-output.rs - OtherStruct (line 21) ... FAILED
34
test src/test/rustdoc-ui/failed-doctest-output.rs - SomeStruct (line 16) ... FAILED
45

56
failures:
67

8+
---- src/test/rustdoc-ui/failed-doctest-output.rs - OtherStruct (line 21) stdout ----
9+
error[E0425]: cannot find value `no` in this scope
10+
--> src/test/rustdoc-ui/failed-doctest-output.rs:22:1
11+
|
12+
3 | no
13+
| ^^ not found in this scope
14+
15+
thread 'src/test/rustdoc-ui/failed-doctest-output.rs - OtherStruct (line 21)' panicked at 'couldn't compile the test', librustdoc/test.rs:332:13
16+
note: Run with `RUST_BACKTRACE=1` for a backtrace.
17+
718
---- src/test/rustdoc-ui/failed-doctest-output.rs - SomeStruct (line 16) stdout ----
819
thread 'src/test/rustdoc-ui/failed-doctest-output.rs - SomeStruct (line 16)' panicked at 'test executable failed:
920

1021
thread 'main' panicked at 'oh no', src/test/rustdoc-ui/failed-doctest-output.rs:3:1
1122
note: Run with `RUST_BACKTRACE=1` for a backtrace.
1223

1324
', librustdoc/test.rs:367:17
14-
note: Run with `RUST_BACKTRACE=1` for a backtrace.
1525

1626

1727
failures:
28+
src/test/rustdoc-ui/failed-doctest-output.rs - OtherStruct (line 21)
1829
src/test/rustdoc-ui/failed-doctest-output.rs - SomeStruct (line 16)
1930

20-
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
31+
test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out
2132

0 commit comments

Comments
 (0)