summaryrefslogtreecommitdiff
path: root/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests.rs')
-rw-r--r--src/tests.rs43
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);
+}