From 50e955c6a7c274de154bff3844fd6d82b6033290 Mon Sep 17 00:00:00 2001 From: Berkus Decker Date: Wed, 2 Dec 2020 01:06:01 +0200 Subject: [PATCH] Print test names in test_runner Based on os.phil-opp.com Testing chapter. --- nucleus/src/tests.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/nucleus/src/tests.rs b/nucleus/src/tests.rs index 58fe785..7fe9835 100644 --- a/nucleus/src/tests.rs +++ b/nucleus/src/tests.rs @@ -5,14 +5,28 @@ //============================================================================ // Testing environment //============================================================================ -use crate::{println, qemu}; +use crate::{print, println, qemu}; + +pub trait TestFn { + fn run(&self) -> (); +} + +impl TestFn for T +where + T: Fn(), +{ + fn run(&self) { + print!("*TEST* {}...\t", core::any::type_name::()); + 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();