1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// in src/lib.rs

#![no_std]
#![cfg_attr(test, no_main)]
#![feature(custom_test_frameworks)]
#![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"]

//! mango_test
//! ----------
//!
//! Test framework for mango operating system.

#[allow(missing_docs)]
pub trait Testable
{
  fn run(&self) -> ();
}

impl<T> Testable for T
where
  T: Fn(),
{
  fn run(&self)
  {
    mango_core::print!("{}...\t", core::any::type_name::<T>());
    self();
    mango_core::println!("[ok]");
  }
}

#[allow(missing_docs)]
pub fn test_runner(tests: &[&dyn Testable])
{
  mango_core::println!("Running {} tests", tests.len());
  for test in tests
  {
    test.run();
  }
  #[cfg(feature = "qemu")]
  mango_core::qemu::exit_qemu(mango_core::qemu::QemuExitCode::Success);
}