Print test names in test_runner
Based on os.phil-opp.com Testing chapter.
This commit is contained in:
parent
601cf7a784
commit
50e955c6a7
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue