File tree 4 files changed +92
-1
lines changed
4 files changed +92
-1
lines changed Original file line number Diff line number Diff line change @@ -131,7 +131,22 @@ mod __doctest_mod {{
131
131
.output()
132
132
.expect(\" failed to run command\" );
133
133
if !out.status.success() {{
134
- eprint!(\" {{}}\" , String::from_utf8_lossy(&out.stderr));
134
+ if let Some(code) = out.status.code() {{
135
+ eprintln!(\" Test executable failed (exit status: {{code}}).\" );
136
+ }} else {{
137
+ eprintln!(\" Test executable failed (terminated by signal).\" );
138
+ }}
139
+ if !out.stdout.is_empty() || !out.stderr.is_empty() {{
140
+ eprintln!();
141
+ }}
142
+ if !out.stdout.is_empty() {{
143
+ eprintln!(\" stdout:\" );
144
+ eprintln!(\" {{}}\" , String::from_utf8_lossy(&out.stdout));
145
+ }}
146
+ if !out.stderr.is_empty() {{
147
+ eprintln!(\" stderr:\" );
148
+ eprintln!(\" {{}}\" , String::from_utf8_lossy(&out.stderr));
149
+ }}
135
150
ExitCode::FAILURE
136
151
}} else {{
137
152
ExitCode::SUCCESS
Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ test $DIR/edition-2024-error-output.rs - (line 12) ... FAILED
5
5
failures:
6
6
7
7
---- $DIR/edition-2024-error-output.rs - (line 12) stdout ----
8
+ Test executable failed (exit status: 101).
9
+
10
+ stderr:
8
11
9
12
thread 'main' panicked at $TMP:6:1:
10
13
assertion `left == right` failed
@@ -13,6 +16,7 @@ assertion `left == right` failed
13
16
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
14
17
15
18
19
+
16
20
failures:
17
21
$DIR/edition-2024-error-output.rs - (line 12)
18
22
Original file line number Diff line number Diff line change
1
+ // This test ensures that the output is correctly generated when the
2
+ // doctest fails. It checks when there is stderr and stdout, no stdout
3
+ // and no stderr/stdout.
4
+ //
5
+ // This is a regression test for <https://github.com/rust-lang/rust/issues/140289>.
6
+
7
+ //@ edition: 2024
8
+ //@ compile-flags:--test --test-args=--test-threads=1
9
+ //@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
10
+ //@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
11
+ //@ normalize-stdout: "panicked at .+rs:" -> "panicked at $$TMP:"
12
+ //@ failure-status: 101
13
+ //@ rustc-env:RUST_BACKTRACE=0
14
+
15
+ //! ```
16
+ //! println!("######## from a DOC TEST ########");
17
+ //! assert_eq!("doc", "test");
18
+ //! ```
19
+ //!
20
+ //! ```
21
+ //! assert_eq!("doc", "test");
22
+ //! ```
23
+ //!
24
+ //! ```
25
+ //! std::process::exit(1);
26
+ //! ```
Original file line number Diff line number Diff line change
1
+
2
+ running 3 tests
3
+ test $DIR/stdout-and-stderr.rs - (line 15) ... FAILED
4
+ test $DIR/stdout-and-stderr.rs - (line 20) ... FAILED
5
+ test $DIR/stdout-and-stderr.rs - (line 24) ... FAILED
6
+
7
+ failures:
8
+
9
+ ---- $DIR/stdout-and-stderr.rs - (line 15) stdout ----
10
+ Test executable failed (exit status: 101).
11
+
12
+ stdout:
13
+ ######## from a DOC TEST ########
14
+
15
+ stderr:
16
+
17
+ thread 'main' panicked at $TMP:7:1:
18
+ assertion `left == right` failed
19
+ left: "doc"
20
+ right: "test"
21
+ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
22
+
23
+
24
+ ---- $DIR/stdout-and-stderr.rs - (line 20) stdout ----
25
+ Test executable failed (exit status: 101).
26
+
27
+ stderr:
28
+
29
+ thread 'main' panicked at $TMP:15:1:
30
+ assertion `left == right` failed
31
+ left: "doc"
32
+ right: "test"
33
+ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
+
35
+
36
+ ---- $DIR/stdout-and-stderr.rs - (line 24) stdout ----
37
+ Test executable failed (exit status: 1).
38
+
39
+
40
+ failures:
41
+ $DIR/stdout-and-stderr.rs - (line 15)
42
+ $DIR/stdout-and-stderr.rs - (line 20)
43
+ $DIR/stdout-and-stderr.rs - (line 24)
44
+
45
+ test result: FAILED. 0 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
46
+
You can’t perform that action at this time.
0 commit comments