mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 17:41:33 +11:00
move test runner to own module
This commit is contained in:
parent
e75adf9e67
commit
1614e46c4e
|
@ -50,6 +50,7 @@ impl BlockAllocator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub unsafe fn number_of_blocks(&self) -> u32 {
|
pub unsafe fn number_of_blocks(&self) -> u32 {
|
||||||
free(|key| {
|
free(|key| {
|
||||||
let mut state = self.state.borrow(*key).borrow_mut();
|
let mut state = self.state.borrow(*key).borrow_mut();
|
||||||
|
|
|
@ -35,6 +35,7 @@ const EWRAM_END: usize = 0x0204_0000;
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static GLOBAL_ALLOC: BlockAllocator = unsafe { BlockAllocator::new() };
|
static GLOBAL_ALLOC: BlockAllocator = unsafe { BlockAllocator::new() };
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub unsafe fn number_of_blocks() -> u32 {
|
pub unsafe fn number_of_blocks() -> u32 {
|
||||||
GLOBAL_ALLOC.number_of_blocks()
|
GLOBAL_ALLOC.number_of_blocks()
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,6 @@ mod tests {
|
||||||
|
|
||||||
display_logo(&mut gfx);
|
display_logo(&mut gfx);
|
||||||
|
|
||||||
crate::assert_image_output("gfx/test_logo.png");
|
crate::test_runner::assert_image_output("gfx/test_logo.png");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// This appears to be needed for testing to work
|
// This appears to be needed for testing to work
|
||||||
#![cfg_attr(test, no_main)]
|
#![cfg_attr(test, no_main)]
|
||||||
#![cfg_attr(test, feature(custom_test_frameworks))]
|
#![cfg_attr(test, feature(custom_test_frameworks))]
|
||||||
#![cfg_attr(test, test_runner(crate::test_runner))]
|
#![cfg_attr(test, test_runner(crate::test_runner::test_runner))]
|
||||||
#![cfg_attr(test, reexport_test_harness_main = "test_main")]
|
#![cfg_attr(test, reexport_test_harness_main = "test_main")]
|
||||||
#![deny(clippy::all)]
|
#![deny(clippy::all)]
|
||||||
#![feature(alloc_error_handler)]
|
#![feature(alloc_error_handler)]
|
||||||
|
@ -224,15 +224,19 @@ impl Gba {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[cfg(test)]
|
||||||
pub trait Testable {
|
mod test_runner {
|
||||||
fn run(&self, gba: &mut Gba);
|
use super::*;
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Testable for T
|
#[doc(hidden)]
|
||||||
where
|
pub trait Testable {
|
||||||
|
fn run(&self, gba: &mut Gba);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Testable for T
|
||||||
|
where
|
||||||
T: Fn(&mut Gba),
|
T: Fn(&mut Gba),
|
||||||
{
|
{
|
||||||
fn run(&self, gba: &mut Gba) {
|
fn run(&self, gba: &mut Gba) {
|
||||||
let mut mgba = mgba::Mgba::new().unwrap();
|
let mut mgba = mgba::Mgba::new().unwrap();
|
||||||
mgba.print(
|
mgba.print(
|
||||||
|
@ -253,11 +257,10 @@ where
|
||||||
mgba.print(format_args!("[ok]"), mgba::DebugLevel::Info)
|
mgba.print(format_args!("[ok]"), mgba::DebugLevel::Info)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
#[cfg(test)]
|
fn panic_implementation(info: &core::panic::PanicInfo) -> ! {
|
||||||
fn panic_implementation(info: &core::panic::PanicInfo) -> ! {
|
|
||||||
if let Some(mut mgba) = mgba::Mgba::new() {
|
if let Some(mut mgba) = mgba::Mgba::new() {
|
||||||
mgba.print(format_args!("[failed]"), mgba::DebugLevel::Error)
|
mgba.print(format_args!("[failed]"), mgba::DebugLevel::Error)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -266,14 +269,12 @@ fn panic_implementation(info: &core::panic::PanicInfo) -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
static mut TEST_GBA: Option<Gba> = None;
|
||||||
static mut TEST_GBA: Option<Gba> = None;
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[cfg(test)]
|
pub fn test_runner(tests: &[&dyn Testable]) {
|
||||||
pub fn test_runner(tests: &[&dyn Testable]) {
|
|
||||||
let mut mgba = mgba::Mgba::new().unwrap();
|
let mut mgba = mgba::Mgba::new().unwrap();
|
||||||
mgba.print(
|
mgba.print(
|
||||||
format_args!("Running {} tests", tests.len()),
|
format_args!("Running {} tests", tests.len()),
|
||||||
|
@ -292,19 +293,17 @@ pub fn test_runner(tests: &[&dyn Testable]) {
|
||||||
mgba::DebugLevel::Info,
|
mgba::DebugLevel::Info,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[entry]
|
||||||
#[entry]
|
fn agb_test_main(gba: Gba) -> ! {
|
||||||
fn agb_test_main(gba: Gba) -> ! {
|
|
||||||
unsafe { TEST_GBA = Some(gba) };
|
unsafe { TEST_GBA = Some(gba) };
|
||||||
test_main();
|
test_main();
|
||||||
#[allow(clippy::empty_loop)]
|
#[allow(clippy::empty_loop)]
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
pub fn assert_image_output(image: &str) {
|
||||||
fn assert_image_output(image: &str) {
|
|
||||||
display::busy_wait_for_vblank();
|
display::busy_wait_for_vblank();
|
||||||
display::busy_wait_for_vblank();
|
display::busy_wait_for_vblank();
|
||||||
let mut mgba = crate::mgba::Mgba::new().unwrap();
|
let mut mgba = crate::mgba::Mgba::new().unwrap();
|
||||||
|
@ -314,6 +313,7 @@ fn assert_image_output(image: &str) {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
display::busy_wait_for_vblank();
|
display::busy_wait_for_vblank();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue