Skip to content

Commit c396c12

Browse files
committed
Add test for libtest panic=abort mode
1 parent c792c25 commit c396c12

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/test/ui/test-panic-abort.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// no-prefer-dynamic
2+
// compile-flags: --test -Cpanic=abort
3+
// run-flags: --test-threads=1
4+
// run-fail
5+
// check-run-results
6+
7+
#![cfg(test)]
8+
9+
use std::io::Write;
10+
11+
#[test]
12+
fn it_works() {
13+
assert_eq!(1 + 1, 2);
14+
}
15+
16+
#[test]
17+
#[should_panic]
18+
fn it_panics() {
19+
assert_eq!(1 + 1, 4);
20+
}
21+
22+
#[test]
23+
fn it_fails() {
24+
println!("hello, world");
25+
writeln!(std::io::stdout(), "testing123").unwrap();
26+
writeln!(std::io::stderr(), "testing321").unwrap();
27+
assert_eq!(1 + 1, 5);
28+
}
29+
30+
#[test]
31+
fn it_exits() {
32+
std::process::exit(123);
33+
}
34+
35+
#[test]
36+
fn it_segfaults() {
37+
let x = unsafe { *(0 as *const u64) };
38+
println!("output: {}", x);
39+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
running 5 tests
3+
test it_exits ... FAILED
4+
test it_fails ... FAILED
5+
test it_panics ... ok
6+
test it_segfaults ... ok
7+
test it_works ... ok
8+
9+
failures:
10+
11+
---- it_exits stdout ----
12+
---- it_exits stderr ----
13+
note: got unexpected return code 123
14+
---- it_fails stdout ----
15+
hello, world
16+
testing123
17+
---- it_fails stderr ----
18+
testing321
19+
thread 'main' panicked at 'assertion failed: `(left == right)`
20+
left: `2`,
21+
right: `5`', $DIR/test-panic-abort.rs:27:5
22+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
23+
24+
25+
failures:
26+
it_exits
27+
it_fails
28+
29+
test result: FAILED. 3 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out
30+

0 commit comments

Comments
 (0)