From 6a6255ec67f335639948db8c62385b136809140d Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Sat, 2 Nov 2019 21:55:24 +0100 Subject: Rewrite build script --- kernel/src/lib.rs | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'kernel/src') diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 92ce010..08059ea 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -1,24 +1,52 @@ #![no_main] #![feature(compiler_builtins_lib)] +#![feature(custom_test_frameworks)] +#![test_runner(crate::test_runner)] +#![reexport_test_harness_main = "test_main"] #![no_std] extern crate compiler_builtins; mod vga_text; +use vga_text::OStream; use core::fmt::Write; +#[cfg(test)] +pub fn test_runner(tests: &[&dyn Fn(&mut OStream)]) { + let mut stdout = OStream::new(); + stdout.clear(); + write!(&mut stdout, "running {} tests\n", tests.len()); + for test in tests { + test(&mut stdout) + } +} + +#[test_case] +fn test01(stdout: &mut OStream) { + write!(stdout, "running test01 . . . OK"); +} + #[no_mangle] pub extern "C" fn _start() -> ! { + + if cfg!(test) { + #[cfg(test)] + test_main(); + loop {} + } + let mut stdout = vga_text::OStream::new(); stdout.clear(); write!(&mut stdout, "hello world!"); - panic!("i has panicing"); + // panic!("i has panicing"); core::iter::successors(Some(0), |n| Some(n + 1)) - .for_each(|n| write!(&mut stdout, "hello world {}!", n).unwrap()); + .for_each(|n| + write!(&mut stdout, "hello world {}!", n).unwrap() + ); loop {} } @@ -28,26 +56,19 @@ pub extern "C" fn _start() -> ! { pub extern "C" fn panic_handler(_info: &core::panic::PanicInfo) -> ! { let mut stderr = vga_text::OStream::new(); stderr.set_state(vga_text::CharState::from_colors( - vga_text::Color::LightRed, - vga_text::Color::Red, - )); + vga_text::Color::LightRed, vga_text::Color::Red)); stderr.clear(); stderr.print(b"uff-os"); stderr.set_row(10); stderr.set_state(vga_text::CharState::from_colors( - vga_text::Color::White, - vga_text::Color::Red, - )); + vga_text::Color::White, vga_text::Color::Red)); stderr.print_centered(b""); stderr.set_row(14); - let text = _info - .payload() + let text = _info.payload() .downcast_ref::<&str>() - .unwrap_or(&"no panic information is obtainable"); + .unwrap_or(&"no panic informations are obtainable"); stderr.set_state(vga_text::CharState::from_colors( - vga_text::Color::Cyan, - vga_text::Color::Red, - )); + vga_text::Color::Cyan, vga_text::Color::Red)); stderr.print_centered(text.as_bytes()); loop {} } -- cgit v1.2.3-54-g00ecf