Skip to content

Commit 41e7ac1

Browse files
report doctest compile failures correctly
1 parent 3365419 commit 41e7ac1

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
));
@@ -314,28 +314,28 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
314314
Err(_) | Ok(Err(CompileIncomplete::Errored(_))) => Err(())
315315
};
316316

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

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

340340
if no_run { return }
341341

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)