Skip to content

Commit 7644de5

Browse files
authored
Rollup merge of #95783 - notriddle:notriddle/doctest-signal, r=GuillaumeGomez
rustdoc doctest: include signal number in exit status Related to #95601
2 parents 327caac + 2af843c commit 7644de5

5 files changed

+79
-15
lines changed

src/librustdoc/doctest.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1069,13 +1069,7 @@ impl Tester for Collector {
10691069
}
10701070
}
10711071
TestFailure::ExecutionFailure(out) => {
1072-
let reason = if let Some(code) = out.status.code() {
1073-
format!("exit code {code}")
1074-
} else {
1075-
String::from("terminated by signal")
1076-
};
1077-
1078-
eprintln!("Test executable failed ({reason}).");
1072+
eprintln!("Test executable failed ({reason}).", reason = out.status);
10791073

10801074
// FIXME(#12309): An unfortunate side-effect of capturing the test
10811075
// executable's output is that the relative ordering between the test's
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// only-windows
2+
// There's a parallel generic version of this test for non-windows platforms.
3+
4+
// Issue #51162: A failed doctest was not printing its stdout/stderr
5+
// FIXME: if/when the output of the test harness can be tested on its own, this test should be
6+
// adapted to use that, and that normalize line can go away
7+
8+
// compile-flags:--test --test-args --test-threads=1
9+
// rustc-env:RUST_BACKTRACE=0
10+
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
11+
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
12+
// failure-status: 101
13+
14+
// doctest fails at runtime
15+
/// ```
16+
/// println!("stdout 1");
17+
/// eprintln!("stderr 1");
18+
/// println!("stdout 2");
19+
/// eprintln!("stderr 2");
20+
/// panic!("oh no");
21+
/// ```
22+
pub struct SomeStruct;
23+
24+
// doctest fails at compile time
25+
/// ```
26+
/// no
27+
/// ```
28+
pub struct OtherStruct;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
running 2 tests
3+
test $DIR/failed-doctest-output-windows.rs - OtherStruct (line 25) ... FAILED
4+
test $DIR/failed-doctest-output-windows.rs - SomeStruct (line 15) ... FAILED
5+
6+
failures:
7+
8+
---- $DIR/failed-doctest-output-windows.rs - OtherStruct (line 25) stdout ----
9+
error[E0425]: cannot find value `no` in this scope
10+
--> $DIR/failed-doctest-output-windows.rs:26:1
11+
|
12+
LL | no
13+
| ^^ not found in this scope
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0425`.
18+
Couldn't compile the test.
19+
---- $DIR/failed-doctest-output-windows.rs - SomeStruct (line 15) stdout ----
20+
Test executable failed (exit code: 101).
21+
22+
stdout:
23+
stdout 1
24+
stdout 2
25+
26+
stderr:
27+
stderr 1
28+
stderr 2
29+
thread 'main' panicked at 'oh no', $DIR/failed-doctest-output-windows.rs:7:1
30+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
31+
32+
33+
34+
failures:
35+
$DIR/failed-doctest-output-windows.rs - OtherStruct (line 25)
36+
$DIR/failed-doctest-output-windows.rs - SomeStruct (line 15)
37+
38+
test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
39+

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

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// ignore-windows
2+
// There's a parallel version of this test for Windows.
3+
14
// Issue #51162: A failed doctest was not printing its stdout/stderr
25
// FIXME: if/when the output of the test harness can be tested on its own, this test should be
36
// adapted to use that, and that normalize line can go away
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
running 2 tests
3-
test $DIR/failed-doctest-output.rs - OtherStruct (line 22) ... FAILED
4-
test $DIR/failed-doctest-output.rs - SomeStruct (line 12) ... FAILED
3+
test $DIR/failed-doctest-output.rs - OtherStruct (line 25) ... FAILED
4+
test $DIR/failed-doctest-output.rs - SomeStruct (line 15) ... FAILED
55

66
failures:
77

8-
---- $DIR/failed-doctest-output.rs - OtherStruct (line 22) stdout ----
8+
---- $DIR/failed-doctest-output.rs - OtherStruct (line 25) stdout ----
99
error[E0425]: cannot find value `no` in this scope
10-
--> $DIR/failed-doctest-output.rs:23:1
10+
--> $DIR/failed-doctest-output.rs:26:1
1111
|
1212
LL | no
1313
| ^^ not found in this scope
@@ -16,8 +16,8 @@ error: aborting due to previous error
1616

1717
For more information about this error, try `rustc --explain E0425`.
1818
Couldn't compile the test.
19-
---- $DIR/failed-doctest-output.rs - SomeStruct (line 12) stdout ----
20-
Test executable failed (exit code 101).
19+
---- $DIR/failed-doctest-output.rs - SomeStruct (line 15) stdout ----
20+
Test executable failed (exit status: 101).
2121

2222
stdout:
2323
stdout 1
@@ -32,8 +32,8 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3232

3333

3434
failures:
35-
$DIR/failed-doctest-output.rs - OtherStruct (line 22)
36-
$DIR/failed-doctest-output.rs - SomeStruct (line 12)
35+
$DIR/failed-doctest-output.rs - OtherStruct (line 25)
36+
$DIR/failed-doctest-output.rs - SomeStruct (line 15)
3737

3838
test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
3939

0 commit comments

Comments
 (0)