diff --git a/.github/.cspell/project-dictionary.txt b/.github/.cspell/project-dictionary.txt index cf44990f..fe1b805b 100644 --- a/.github/.cspell/project-dictionary.txt +++ b/.github/.cspell/project-dictionary.txt @@ -72,6 +72,7 @@ lqarx lrcpc lwsync machdep +metavar mfence mgba mipsn diff --git a/tests/avr/src/main.rs b/tests/avr/src/main.rs index a8b20944..8adfc9aa 100644 --- a/tests/avr/src/main.rs +++ b/tests/avr/src/main.rs @@ -2,6 +2,7 @@ #![no_std] #![warn(rust_2018_idioms, single_use_lifetimes, unsafe_op_in_unsafe_fn)] #![feature(lang_items)] +#![feature(macro_metavar_expr)] #![feature(panic_info_message)] #![allow(clippy::empty_loop)] // this test crate is #![no_std] @@ -19,59 +20,88 @@ fn main() -> ! { let pins = arduino_hal::pins!(dp); let mut serial = arduino_hal::default_serial!(dp, pins, 57600); - macro_rules! print { - ($($tt:tt)*) => {{ - let _ = ufmt::uwrite!(serial, $($tt)*); - }}; - } - macro_rules! println { - ($($tt:tt)*) => {{ - let _ = ufmt::uwriteln!(serial, $($tt)*); - }}; - } - macro_rules! test_atomic_int { ($int_type:ident) => { paste::paste! { - fn []() { + fn [](serial: &mut impl ufmt::uWrite) { + macro_rules! print { + ($$($tt:tt)*) => {{ + let _ = ufmt::uwrite!(serial, $$($tt)*); + }}; + } + macro_rules! println { + ($$($tt:tt)*) => {{ + let _ = ufmt::uwriteln!(serial, $$($tt)*); + }}; + } + print!("test test_atomic_{} ... ", stringify!($int_type)); __test_atomic_int!([], $int_type); + println!("ok"); } - print!("test test_atomic_{} ... ", stringify!($int_type)); - [](); - println!("ok"); + [](&mut serial); } }; } macro_rules! test_atomic_float { ($float_type:ident) => { paste::paste! { - fn []() { + fn [](serial: &mut impl ufmt::uWrite) { + macro_rules! print { + ($$($tt:tt)*) => {{ + let _ = ufmt::uwrite!(serial, $$($tt)*); + }}; + } + macro_rules! println { + ($$($tt:tt)*) => {{ + let _ = ufmt::uwriteln!(serial, $$($tt)*); + }}; + } + print!("test test_atomic_{} ... ", stringify!($float_type)); __test_atomic_float!([], $float_type); + println!("ok"); } - print!("test test_atomic_{} ... ", stringify!($float_type)); - [](); - println!("ok"); + [](&mut serial); } }; } macro_rules! test_atomic_bool { () => { - fn test_atomic_bool() { + fn test_atomic_bool(serial: &mut impl ufmt::uWrite) { + macro_rules! print { + ($$($tt:tt)*) => {{ + let _ = ufmt::uwrite!(serial, $$($tt)*); + }}; + } + macro_rules! println { + ($$($tt:tt)*) => {{ + let _ = ufmt::uwriteln!(serial, $$($tt)*); + }}; + } + print!("test test_atomic_bool ... "); __test_atomic_bool!(AtomicBool); + println!("ok"); } - print!("test test_atomic_bool ... "); - test_atomic_bool(); - println!("ok"); + test_atomic_bool(&mut serial); }; } macro_rules! test_atomic_ptr { () => { - fn test_atomic_ptr() { + fn test_atomic_ptr(serial: &mut impl ufmt::uWrite) { + macro_rules! print { + ($$($tt:tt)*) => {{ + let _ = ufmt::uwrite!(serial, $$($tt)*); + }}; + } + macro_rules! println { + ($$($tt:tt)*) => {{ + let _ = ufmt::uwriteln!(serial, $$($tt)*); + }}; + } + print!("test test_atomic_ptr ... "); __test_atomic_ptr!(AtomicPtr); + println!("ok"); } - print!("test test_atomic_ptr ... "); - test_atomic_ptr(); - println!("ok"); + test_atomic_ptr(&mut serial); }; }