Skip to content

Instantly share code, notes, and snippets.

@nmarley
Last active January 8, 2023 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmarley/0831cf27ca12ce7e6b1234af8162e94e to your computer and use it in GitHub Desktop.
Save nmarley/0831cf27ca12ce7e6b1234af8162e94e to your computer and use it in GitHub Desktop.
Rust macro testing

Rust macro testing

rustc --test test2.rs
macro_rules! test_battery {
($($t:ty as $name:ident),*) => {
$(
mod $name {
#[test]
fn frobnified() { assert_eq!(true, true); }
#[test]
fn unfrobnified() { assert_eq!(false, false); }
}
)*
}
}
// seems to work
test_battery! (u8 as u8_tests, u128 as u128_tests);
// seems to work
test_battery! {u8 as u8_tests2, u128 as u128_tests2}
// seems to have a problem
test_battery! {u8 as u8_tests3, u128 as u128_tests3};
fn main() {
println!("Hello, world!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment