anos/tests/should_panic.rs

26 lines
513 B
Rust
Raw Normal View History

2021-12-09 11:51:38 +00:00
#![no_std]
#![no_main]
2022-01-13 04:11:03 +00:00
use anos::{exit_qemu, serial_print, serial_println, QemuExitCode};
2021-12-09 11:51:38 +00:00
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
serial_println!("\t[ok]");
exit_qemu(QemuExitCode::Success);
loop {}
}
fn should_fail() {
serial_print!("should_panic::should_fail...");
assert_eq!(0, 1);
}
#[no_mangle]
pub extern "C" fn _start() -> ! {
should_fail();
serial_println!("[test did not panic]");
exit_qemu(QemuExitCode::Failed);
loop {}
}