From 3a0752f734f4370a05e45958499ddd9c3a4b3919 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Mon, 22 Aug 2022 21:39:16 -0700 Subject: Modularize --- src/tests.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/tests.rs (limited to 'src/tests.rs') diff --git a/src/tests.rs b/src/tests.rs new file mode 100644 index 0000000..e26c87a --- /dev/null +++ b/src/tests.rs @@ -0,0 +1,43 @@ +use crate::{serial_print,serial_println}; +use crate::qemu::*; + +/// # Testable trait +/// +/// Trait for test functions +pub trait Testable { + fn run(&self) -> (); +} + +impl Testable for T +where + T: Fn(), +{ + /// # Default run + /// + /// Run each test and print results to output + fn run(&self) { + serial_print!("{}...\t", core::any::type_name::()); + self(); + serial_println!("[ok]"); + } +} + +/// # Run tests +/// +/// Run each of the tests +#[cfg(test)] +pub fn test_runner(tests: &[&dyn Testable]) { + serial_println!("Running {} tests", tests.len()); + for test in tests { + test.run(); + } + exit_qemu(QemuExitCode::Success); +} + +/// # Trivial test +/// +/// This test ought to succeed no matter what +#[test_case] +fn trivial_assertion() { + assert_eq!(1, 1); +} -- cgit v1.2.1