Skip to main content

pacenotes_installer\selftest/
panic_check.rs

1/// `--selftest-panic [--out FILE]`: panics on purpose, quietly, so a suite can
2/// prove the hook writes a report, a path using the installer correctly never takes.
3#[allow(clippy::panic)] // The point of the flag: proving the crash hook works.
4pub fn panic_if_requested() {
5    let mut arguments = std::env::args().skip(1);
6    let mut requested = false;
7    let mut out = None;
8    while let Some(argument) = arguments.next() {
9        match argument.as_str() {
10            "--selftest-panic" => requested = true,
11            "--out" => out = arguments.next().map(std::path::PathBuf::from),
12            _ => {}
13        }
14    }
15    if !requested {
16        return;
17    }
18    if let Some(path) = out {
19        crate::crash::log_to(path);
20    }
21    crate::crash::be_quiet();
22    panic!("deliberate panic from --selftest-panic");
23}