diff options
author | Dennis Kobert <dennis@kobert.dev> | 2019-11-09 15:11:50 +0100 |
---|---|---|
committer | Dennis Kobert <dennis@kobert.dev> | 2019-11-09 15:11:50 +0100 |
commit | 26a7561196674b39f9adadcb374f36c503361adb (patch) | |
tree | 3031e026feae853f7c46b91975beaa4e20cf755c /kernel/src/testing/panic.rs | |
parent | b17a0a41bea7789178919f4a0999ea8519e1f897 (diff) |
Add basic tests
Diffstat (limited to 'kernel/src/testing/panic.rs')
-rw-r--r-- | kernel/src/testing/panic.rs | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/kernel/src/testing/panic.rs b/kernel/src/testing/panic.rs index 7fb769b..729a45f 100644 --- a/kernel/src/testing/panic.rs +++ b/kernel/src/testing/panic.rs @@ -1,51 +1,36 @@ use crate::io::{qemu, serial, vga_text}; use core::fmt::Write; +use core::panic::PanicInfo; use qemu::{exit_qemu, QemuExitCode}; use serial::SerialStream; use vga_text::OStream; -#[cfg(test)] -pub fn serial_test_runner_panic(tests: &[&dyn Fn()]) { +pub fn serial_should_panic(info: &PanicInfo) -> ! { let mut stdout = SerialStream::new(); - write!(stdout, "Running {} tests", tests.len()).unwrap(); - for test in tests { - test(); - write!(stdout, "[test did not panic]").unwrap(); - exit_qemu(QemuExitCode::Failed); - } + write!(stdout, "\nOK\nsuccessfully panicked\n").unwrap(); exit_qemu(QemuExitCode::Success); + loop {} } -#[cfg(test)] -pub fn serial_test_runner(tests: &[&dyn Fn()]) { +pub fn serial_panic(info: &PanicInfo) -> ! { + crate::io::panic_screen::show(info.message()); let mut stdout = SerialStream::new(); - write!(stdout, "Running {} tests", tests.len()).unwrap(); - for test in tests { - test(); - write!(stdout, "[test did not panic]").unwrap(); - } - exit_qemu(QemuExitCode::Success); + write!( + stdout, + "\nERR\nPanicked execute without -serial for more details\n{}", + info + ) + .unwrap(); + exit_qemu(QemuExitCode::Failed); + loop {} } -#[cfg(test)] -pub fn test_runner_panic(tests: &[&dyn Fn()]) { - let mut stdout = OStream::new(); - write!(stdout, "Running {} tests", tests.len()).unwrap(); - for test in tests { - test(); - write!(stdout, "[test did not panic]").unwrap(); - exit_qemu(QemuExitCode::Failed); - } +pub fn should_panic(_info: &PanicInfo) -> ! { exit_qemu(QemuExitCode::Success); + loop {} } -#[cfg(test)] -pub fn test_runner(tests: &[&dyn Fn()]) { - let mut stdout = OStream::new(); - write!(stdout, "Running {} tests", tests.len()).unwrap(); - for test in tests { - test(); - write!(stdout, "[test did not panic]").unwrap(); - } - exit_qemu(QemuExitCode::Success); +pub fn panic(info: &PanicInfo) -> ! { + crate::io::panic_screen::show(info.message()); + loop {} } |