about summary refs log tree commit diff
path: root/tests/ui/process/multi-panic.rs
blob: 1fddffeb770a301666cc0551541da3010aec8dce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//@ run-pass
//@ needs-subprocess
//@ needs-unwind

fn check_for_no_backtrace(test: std::process::Output) {
    assert!(!test.status.success());
    let err = String::from_utf8_lossy(&test.stderr);
    let mut it = err.lines().filter(|l| !l.is_empty());

    assert_eq!(
        it.next().map(|l| l.starts_with("thread '<unnamed>' (") && l.contains("panicked")),
        Some(true),
        "out: ```{err}```",
    );
    assert_eq!(it.next().is_some(), true, "out: ```{err}```");
    assert_eq!(
        it.next(),
        Some(
            "note: run with `RUST_BACKTRACE=1` \
                                environment variable to display a backtrace"
        ),
        "out: ```{err}```",
    );
    assert_eq!(
        it.next().map(|l| l.starts_with("thread 'main' (") && l.contains("panicked at")),
        Some(true),
        "out: ```{err}```",
    );
    assert_eq!(it.next().is_some(), true, "out: ```{err}```");
    assert_eq!(it.next(), None, "out: ```{err}```");
}

fn main() {
    let args: Vec<String> = std::env::args().collect();
    if args.len() > 1 && args[1] == "run_test" {
        let _ = std::thread::spawn(|| {
            panic!();
        })
        .join();

        panic!();
    } else {
        let test = std::process::Command::new(&args[0])
            .arg("run_test")
            .env_remove("RUST_BACKTRACE")
            .output()
            .unwrap();
        check_for_no_backtrace(test);
        let test = std::process::Command::new(&args[0])
            .arg("run_test")
            .env("RUST_BACKTRACE", "0")
            .output()
            .unwrap();
        check_for_no_backtrace(test);
    }
}