From aad98c0611a8eb5780b68f819b1b923b288f841b Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 7 Aug 2019 11:00:01 +0200 Subject: [PATCH] Add a should_panic test --- tests/should_panic.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/should_panic.rs diff --git a/tests/should_panic.rs b/tests/should_panic.rs new file mode 100644 index 00000000..3fe187cd --- /dev/null +++ b/tests/should_panic.rs @@ -0,0 +1,38 @@ +#![no_std] +#![no_main] +#![feature(custom_test_frameworks)] +#![test_runner(test_runner)] +#![reexport_test_harness_main = "test_main"] + +use blog_os::{exit_qemu, serial_print, serial_println, QemuExitCode}; +use core::panic::PanicInfo; + +#[no_mangle] +pub extern "C" fn _start() -> ! { + test_main(); + + loop {} +} + +pub fn test_runner(tests: &[&dyn Fn()]) { + serial_println!("Running {} tests", tests.len()); + if let Some(test) = tests.first() { + test(); + serial_println!("[test did not panic]"); + exit_qemu(QemuExitCode::Failed); + } + exit_qemu(QemuExitCode::Success); +} + +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + serial_println!("[ok]"); + exit_qemu(QemuExitCode::Success); + loop {} +} + +#[test_case] +fn should_fail() { + serial_print!("should_fail... "); + assert_eq!(0, 1); +}