File tree Expand file tree Collapse file tree 3 files changed +58
-3
lines changed
tests/run-make/rustdoc-should-panic Expand file tree Collapse file tree 3 files changed +58
-3
lines changed Original file line number Diff line number Diff line change @@ -135,8 +135,13 @@ mod __doctest_mod {{
135
135
.args(std::env::args().skip(1).collect::<Vec<_>>())
136
136
.output()
137
137
.expect(\" failed to run command\" );
138
- if should_panic && out.status.code() != Some(101) {{
139
- eprintln!(\" Test didn't panic, but it's marked `should_panic`.\" );
138
+ if should_panic {{
139
+ if out.status.code() != Some(101) {{
140
+ eprintln!(\" Test didn't panic, but it's marked `should_panic`.\" );
141
+ ExitCode::FAILURE
142
+ }} else {{
143
+ ExitCode::SUCCESS
144
+ }}
140
145
}} else if !out.status.success() {{
141
146
if let Some(code) = out.status.code() {{
142
147
eprintln!(\" Test executable failed (exit status: {{code}}).\" );
@@ -281,7 +286,7 @@ if let Some(bin_path) = crate::__doctest_mod::doctest_path() {{
281
286
test::assert_test_result(doctest_bundle::{test_id}::__main_fn())
282
287
}}
283
288
" ,
284
- should_panic = !scraped_test . langstr . no_run && scraped_test. langstr. should_panic,
289
+ should_panic = scraped_test. langstr. should_panic,
285
290
)
286
291
} ,
287
292
)
Original file line number Diff line number Diff line change
1
+ // Ensure that `should_panic` doctests only succeed if the test actually panicked.
2
+ // Regression test for <https://github.com/rust-lang/rust/issues/143009>.
3
+
4
+ //@ needs-target-std
5
+
6
+ use run_make_support:: rustdoc;
7
+
8
+ fn check_output ( output : String , edition : & str ) {
9
+ let should_contain = & [
10
+ "test test.rs - bad_exit_code (line 1) ... FAILED" ,
11
+ "test test.rs - did_not_panic (line 6) ... FAILED" ,
12
+ "test test.rs - did_panic (line 11) ... ok" ,
13
+ "---- test.rs - bad_exit_code (line 1) stdout ----
14
+ Test executable failed (exit status: 1)." ,
15
+ "---- test.rs - did_not_panic (line 6) stdout ----
16
+ Test didn't panic, but it's marked `should_panic`." ,
17
+ "test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out;" ,
18
+ ] ;
19
+ for text in should_contain {
20
+ assert ! (
21
+ output. contains( text) ,
22
+ "output doesn't contains (edition: {edition}) {:?}\n full output: {output}" ,
23
+ text
24
+ ) ;
25
+ }
26
+ }
27
+
28
+ fn main ( ) {
29
+ check_output ( rustdoc ( ) . input ( "test.rs" ) . arg ( "--test" ) . run_fail ( ) . stdout_utf8 ( ) , "2015" ) ;
30
+
31
+ // Same check with the merged doctest feature (enabled with the 2024 edition).
32
+ check_output (
33
+ rustdoc ( ) . input ( "test.rs" ) . arg ( "--test" ) . edition ( "2024" ) . run_fail ( ) . stdout_utf8 ( ) ,
34
+ "2024" ,
35
+ ) ;
36
+ }
Original file line number Diff line number Diff line change
1
+ /// ```
2
+ /// std::process::exit(1);
3
+ /// ```
4
+ fn bad_exit_code ( ) { }
5
+
6
+ /// ```should_panic
7
+ /// std::process::exit(1);
8
+ /// ```
9
+ fn did_not_panic ( ) { }
10
+
11
+ /// ```should_panic
12
+ /// panic!("yeay");
13
+ /// ```
14
+ fn did_panic ( ) { }
You can’t perform that action at this time.
0 commit comments