From b4eb0a37cf49f8a9c300352a3c5710d2a9b2c58d Mon Sep 17 00:00:00 2001 From: clizia Date: Mon, 1 Sep 2025 19:48:17 +0200 Subject: [PATCH] added tests that mimic the #[should_panic] cargo test feature --- Cargo.toml | 4 ++++ tests/should_panic.rs | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/should_panic.rs diff --git a/Cargo.toml b/Cargo.toml index 5b7bef3..6e79b8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,10 @@ name = "totos" test = true bench = false +[[test]] +name = "should_panic" +harness = false + [profile.dev] panic = "abort" # disable stack unwinding on panic diff --git a/tests/should_panic.rs b/tests/should_panic.rs new file mode 100644 index 0000000..7818740 --- /dev/null +++ b/tests/should_panic.rs @@ -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 {} +}