Create a testable trait for printing test messages automatically

This commit is contained in:
Philipp Oppermann
2020-06-08 11:04:03 +02:00
parent a1c7931a77
commit 9f9ff59489
4 changed files with 19 additions and 17 deletions

View File

@@ -9,10 +9,25 @@ use core::panic::PanicInfo;
pub mod serial;
pub mod vga_buffer;
pub fn test_runner(tests: &[&dyn Fn()]) {
pub trait Testable {
fn run(&self) -> ();
}
impl<T> Testable for T
where
T: Fn(),
{
fn run(&self) {
serial_print!("{}...\t", core::any::type_name::<T>());
self();
serial_println!("[ok]");
}
}
pub fn test_runner(tests: &[&dyn Testable]) {
serial_println!("Running {} tests", tests.len());
for test in tests {
test();
test.run();
}
exit_qemu(QemuExitCode::Success);
}