From 584aa7b38dde14fdfb19030741a1333a5e726ce9 Mon Sep 17 00:00:00 2001 From: Conzer Date: Tue, 3 Dec 2024 16:56:36 -0500 Subject: [PATCH] add base test functiuon --- .cargo/config.toml | 1 + Cargo.toml | 2 +- src/main.rs | 21 ++++++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index a697a9f..07e59d7 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,6 +1,7 @@ [unstable] build-std-features = ["compiler-builtins-mem"] build-std = ["core", "compiler_builtins"] +panic-abort-tests = true [build] target = ["x86_64-donald.json"] diff --git a/Cargo.toml b/Cargo.toml index 3b7fe70..41f3157 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2018" [profile.dev] -panic = "abort" + [profile.release] panic = "abort" diff --git a/src/main.rs b/src/main.rs index dce2f87..92fc77b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,17 @@ #![allow()] #![no_std] #![no_main] +#![feature(custom_test_frameworks)] +#![test_runner(crate::test_runner)] +#![reexport_test_harness_main = "test_main"] + +#[cfg(test)] +pub fn test_runner(tests: &[&dyn Fn()]) { + println!("Running {} tests", tests.len()); + for test in tests { + test(); + } +} mod vga_buffer; use core::panic::PanicInfo; @@ -14,7 +25,15 @@ fn panic(info: &PanicInfo) -> ! { #[no_mangle] pub extern "C" fn _start() -> ! { println!("Hello World!"); - panic!("Nothing to do."); + #[cfg(test)] + test_main(); loop {} } + +#[test_case] +fn trivial_assertion() { + print!("trivial assertion... "); + assert_eq!(1, 1); + println!("[ok]"); +}