diff options
| author | Christian Cunningham <c@localhost> | 2022-08-22 21:39:16 -0700 |
|---|---|---|
| committer | Christian Cunningham <c@localhost> | 2022-08-22 21:39:16 -0700 |
| commit | 3a0752f734f4370a05e45958499ddd9c3a4b3919 (patch) | |
| tree | 5ee9794f7f9804ef961b9d5126ea0171b8739668 /src/tests.rs | |
| parent | c238b2ea1dff60a5be6a796f44e533e89a346199 (diff) | |
Modularize
Diffstat (limited to 'src/tests.rs')
| -rw-r--r-- | src/tests.rs | 43 |
1 files changed, 43 insertions, 0 deletions
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<T> 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::<T>()); + 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); +} |
