Print test names in test_runner

Based on os.phil-opp.com Testing chapter.
This commit is contained in:
Berkus Decker 2020-12-02 01:06:01 +02:00
parent 601cf7a784
commit 50e955c6a7
1 changed files with 18 additions and 4 deletions

View File

@ -5,14 +5,28 @@
//============================================================================ //============================================================================
// Testing environment // Testing environment
//============================================================================ //============================================================================
use crate::{println, qemu}; use crate::{print, println, qemu};
pub trait TestFn {
fn run(&self) -> ();
}
impl<T> TestFn for T
where
T: Fn(),
{
fn run(&self) {
print!("*TEST* {}...\t", core::any::type_name::<T>());
self();
println!("[ok]\n");
}
}
#[cfg(test)] #[cfg(test)]
pub fn test_runner(tests: &[&dyn Fn()]) { pub fn test_runner(tests: &[&dyn TestFn]) {
println!("Running {} tests", tests.len()); println!("Running {} tests", tests.len());
for test in tests { for test in tests {
test(); test.run();
println!("\n[ok]\n");
} }
println!("\n[success]\n"); println!("\n[success]\n");
qemu::semihosting::exit_success(); qemu::semihosting::exit_success();