Browse Source

First pass of using custom test runner

It works!
pull/41/head
Ian Chamberlain 3 years ago
parent
commit
4ea3ab4769
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 6
      ctru-rs/src/lib.rs
  2. 46
      ctru-rs/src/test_runner.rs

6
ctru-rs/src/lib.rs

@ -1,5 +1,8 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
#![crate_name = "ctru"] #![crate_name = "ctru"]
#![feature(test)]
#![feature(custom_test_frameworks)]
#![test_runner(test_runner::test_runner)]
/// Call this somewhere to force Rust to link some required crates /// Call this somewhere to force Rust to link some required crates
/// This is also a setup for some crate integration only available at runtime /// This is also a setup for some crate integration only available at runtime
@ -61,6 +64,9 @@ cfg_if::cfg_if! {
} }
} }
#[cfg(test)]
mod test_runner;
pub use crate::error::{Error, Result}; pub use crate::error::{Error, Result};
pub use crate::gfx::Gfx; pub use crate::gfx::Gfx;

46
ctru-rs/src/test_runner.rs

@ -0,0 +1,46 @@
//! Custom test runner for building/running unit tests on the 3DS.
extern crate test;
use test::TestFn;
use crate::console::Console;
use crate::gfx::Gfx;
use crate::services::hid::{Hid, KeyPad};
/// A custom runner to be used with `#[test_runner]`. This simple implementation
/// runs all tests in series, "failing" on the first one to panic (really, the
/// panic is just treated the same as any normal application panic).
pub(crate) fn test_runner(test_cases: &[&test::TestDescAndFn]) {
crate::init();
let gfx = Gfx::default();
let hid = Hid::init().expect("Couldn't obtain HID controller");
let _console = Console::init(gfx.top_screen.borrow_mut());
// TODO: may want to use some more features of standard testing framework,
// like output capture, filtering, panic handling, etc.
// For now this is works without too much setup.
for test_info in test_cases {
if let TestFn::StaticTestFn(testfn) = test_info.testfn {
println!("Running test {}", test_info.desc.name);
testfn();
} else {
println!(
"unsupported test type for {}: {:?}",
test_info.desc.name, test_info.testfn
);
}
}
println!("All tests passed! Press START to exit.");
// TODO: do we need apt.main_loop() here?
loop {
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
break;
}
}
}
Loading…
Cancel
Save