added tests that mimic the #[should_panic] cargo test feature
This commit is contained in:
parent
caa6e8e951
commit
b4eb0a37cf
2 changed files with 29 additions and 0 deletions
|
@ -8,6 +8,10 @@ name = "totos"
|
||||||
test = true
|
test = true
|
||||||
bench = false
|
bench = false
|
||||||
|
|
||||||
|
[[test]]
|
||||||
|
name = "should_panic"
|
||||||
|
harness = false
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
panic = "abort" # disable stack unwinding on panic
|
panic = "abort" # disable stack unwinding on panic
|
||||||
|
|
||||||
|
|
25
tests/should_panic.rs
Normal file
25
tests/should_panic.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
use totos::{exit_qemu, serial_print, serial_println, QemuExitCode};
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn _start() -> ! {
|
||||||
|
should_fail();
|
||||||
|
serial_println!("[test did not panic]");
|
||||||
|
exit_qemu(QemuExitCode::Failed);
|
||||||
|
loop{}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn should_fail() {
|
||||||
|
serial_print!("should_panic::should_fail...\t");
|
||||||
|
assert_eq!(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(_info: &PanicInfo) -> ! {
|
||||||
|
serial_println!("[ok]");
|
||||||
|
exit_qemu(QemuExitCode::Success);
|
||||||
|
loop {}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue