[del] 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 e694c33c61
commit 591292c186
1 changed files with 18 additions and 4 deletions

View File

@ -5,14 +5,28 @@
//============================================================================
// 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)]
pub fn test_runner(tests: &[&dyn Fn()]) {
pub fn test_runner(tests: &[&dyn TestFn]) {
println!("Running {} tests", tests.len());
for test in tests {
test();
println!("\n[ok]\n");
test.run();
}
println!("\n[success]\n");
qemu::semihosting::exit_success();