diff --git a/Cargo.toml b/Cargo.toml index 33abd1c..065d39b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,7 @@ default-members = ["ctru-rs", "ctru-sys"] resolver = "2" [patch.'https://github.com/rust3ds/ctru-rs'] -# Make sure all dependencies use the local ctru-sys package +# Make sure all dependencies use the local packages. This is needed for things +# like pthread-3ds that rely on ctru-sys, and test-runner which relies on ctru-rs +ctru-rs = { path = "ctru-rs" } ctru-sys = { path = "ctru-sys" } diff --git a/ctru-rs/Cargo.toml b/ctru-rs/Cargo.toml index 0523b27..bdd7a4d 100644 --- a/ctru-rs/Cargo.toml +++ b/ctru-rs/Cargo.toml @@ -29,13 +29,15 @@ widestring = "0.2.2" toml = "0.5" [dev-dependencies] +bytemuck = "1.12.3" +cfg-if = "1.0.0" ferris-says = "0.2.1" futures = "0.3" +lewton = "0.10.2" +# TODO: switch to rust3ds org once migrated there. Also, rename? +test-runner = { git = "https://github.com/ian-h-chamberlain/test-runner-3ds" } time = "0.3.7" tokio = { version = "1.16", features = ["rt", "time", "sync", "macros"] } -cfg-if = "1.0.0" -bytemuck = "1.12.3" -lewton = "0.10.2" [features] default = ["romfs", "big-stack"] diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index ecc7dd9..87e1343 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -22,7 +22,7 @@ #![feature(custom_test_frameworks)] #![feature(try_trait_v2)] #![feature(allocator_api)] -#![test_runner(test_runner::run)] +#![test_runner(test_runner::run_gdb)] // TODO: does this make sense to have configurable? #![doc( html_favicon_url = "https://user-images.githubusercontent.com/11131775/225929072-2fa1741c-93ae-4b47-9bdf-af70f3d59910.png" )] @@ -73,9 +73,10 @@ pub fn use_panic_handler() { /// When `test` is enabled, this function will be ignored. #[cfg(not(test))] fn panic_hook_setup() { - use crate::services::hid::{Hid, KeyPad}; use std::panic::PanicInfo; + use crate::services::hid::{Hid, KeyPad}; + let main_thread = std::thread::current().id(); // Panic Hook setup @@ -110,7 +111,4 @@ pub mod mii; pub mod prelude; pub mod services; -#[cfg(test)] -mod test_runner; - pub use crate::error::{Error, Result}; diff --git a/ctru-rs/src/test_runner.rs b/ctru-rs/src/test_runner.rs deleted file mode 100644 index 97aa5f4..0000000 --- a/ctru-rs/src/test_runner.rs +++ /dev/null @@ -1,73 +0,0 @@ -//! Custom test runner for building/running unit tests on the 3DS. - -extern crate test; - -use std::io; - -use test::{ColorConfig, OutputFormat, TestDescAndFn, TestFn, TestOpts}; - -use crate::prelude::*; - -/// 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 run(tests: &[&TestDescAndFn]) { - let gfx = Gfx::new().unwrap(); - let mut hid = Hid::new().unwrap(); - let apt = Apt::new().unwrap(); - - let mut top_screen = gfx.top_screen.borrow_mut(); - top_screen.set_wide_mode(true); - let _console = Console::new(top_screen); - - let opts = TestOpts { - force_run_in_process: true, - run_tests: true, - // TODO: color doesn't work because of TERM/TERMINFO. - // With RomFS we might be able to fake this out nicely... - color: ColorConfig::AutoColor, - format: OutputFormat::Pretty, - // Hopefully this interface is more stable vs specifying individual options, - // and parsing the empty list of args should always work, I think. - // TODO Ideally we could pass actual std::env::args() here too - ..test::test::parse_opts(&[]).unwrap().unwrap() - }; - // Use the default test implementation with our hardcoded options - let _success = run_static_tests(&opts, tests).unwrap(); - - // Make sure the user can actually see the results before we exit - println!("Press START to exit."); - - while apt.main_loop() { - gfx.wait_for_vblank(); - - hid.scan_input(); - if hid.keys_down().contains(KeyPad::START) { - break; - } - } -} - -/// Adapted from [`test::test_main_static`] and [`test::make_owned_test`]. -fn run_static_tests(opts: &TestOpts, tests: &[&TestDescAndFn]) -> io::Result { - let tests = tests.iter().map(make_owned_test).collect(); - test::run_tests_console(opts, tests) -} - -/// Clones static values for putting into a dynamic vector, which test_main() -/// needs to hand out ownership of tests to parallel test runners. -/// -/// This will panic when fed any dynamic tests, because they cannot be cloned. -fn make_owned_test(test: &&TestDescAndFn) -> TestDescAndFn { - match test.testfn { - TestFn::StaticTestFn(f) => TestDescAndFn { - testfn: TestFn::StaticTestFn(f), - desc: test.desc.clone(), - }, - TestFn::StaticBenchFn(f) => TestDescAndFn { - testfn: TestFn::StaticBenchFn(f), - desc: test.desc.clone(), - }, - _ => panic!("non-static tests passed to test::test_main_static"), - } -} diff --git a/ctru-sys/Cargo.toml b/ctru-sys/Cargo.toml index 0041d0c..552f206 100644 --- a/ctru-sys/Cargo.toml +++ b/ctru-sys/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ctru-sys" version = "22.2.0+2.2.2-1" -authors = [ "Rust3DS Org", "Ronald Kinard " ] +authors = ["Rust3DS Org", "Ronald Kinard "] description = "Raw bindings to libctru" repository = "https://github.com/rust3ds/ctru-rs" keywords = ["3ds", "libctru"] diff --git a/ctru-sys/build.rs b/ctru-sys/build.rs index 7c55caa..0bf3369 100644 --- a/ctru-sys/build.rs +++ b/ctru-sys/build.rs @@ -68,7 +68,8 @@ fn check_libctru_version() -> Result<(String, String, String), Box> { if lib_version != crate_built_version { return Err(format!( "libctru version is {lib_version} but this crate was built for {crate_built_version}" - ))?; + ) + .into()); } let Output { stdout, .. } = Command::new(pacman) diff --git a/ctru-sys/src/lib.rs b/ctru-sys/src/lib.rs index 474e1d2..98ffb1f 100644 --- a/ctru-sys/src/lib.rs +++ b/ctru-sys/src/lib.rs @@ -16,3 +16,11 @@ pub use result::*; pub unsafe fn errno() -> s32 { *__errno() } + +// TODO: not sure if there's a better way to do this, but I have gotten myself +// with this a couple times so having the hint seems nice to have. +#[cfg(test)] +compile_error!(concat!( + "ctru-sys doesn't have tests and its lib test will fail to build at link time. ", + "Try specifying `--package ctru-rs` to build those tests.", +));