File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
tests/run-make/rustdoc-should-panic Expand file tree Collapse file tree 2 files changed +50
-0
lines changed 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