Andrew Walbran | 13d5ebc | 2022-11-29 18:20:08 +0000 | [diff] [blame] | 1 | //! Test harness which supports ignoring tests at runtime. |
| 2 | |
| 3 | pub mod runner; |
| 4 | |
| 5 | #[doc(hidden)] |
| 6 | pub use libtest_mimic as _libtest_mimic; |
| 7 | #[doc(hidden)] |
Andrew Walbran | 7e69ba5 | 2023-05-10 14:47:49 +0000 | [diff] [blame] | 8 | pub use linkme as _linkme; |
| 9 | #[doc(hidden)] |
Andrew Walbran | 13d5ebc | 2022-11-29 18:20:08 +0000 | [diff] [blame] | 10 | pub use paste as _paste; |
| 11 | |
| 12 | /// Macro to generate the main function for the test harness. |
| 13 | #[macro_export] |
| 14 | macro_rules! test_main { |
Andrew Walbran | 7e69ba5 | 2023-05-10 14:47:49 +0000 | [diff] [blame] | 15 | () => { |
Andrew Walbran | 13d5ebc | 2022-11-29 18:20:08 +0000 | [diff] [blame] | 16 | #[cfg(test)] |
| 17 | fn main() { |
Andrew Walbran | 7e69ba5 | 2023-05-10 14:47:49 +0000 | [diff] [blame] | 18 | ignorabletest::runner::main() |
Andrew Walbran | 13d5ebc | 2022-11-29 18:20:08 +0000 | [diff] [blame] | 19 | } |
| 20 | }; |
| 21 | } |
| 22 | |
| 23 | /// Macro to generate a wrapper function for a single test. |
| 24 | /// |
| 25 | /// # Usage |
| 26 | /// |
| 27 | /// ``` |
| 28 | /// test!(test_string_equality); |
| 29 | /// fn test_string_equality() { |
| 30 | /// assert_eq!("", ""); |
| 31 | /// } |
| 32 | /// ``` |
| 33 | #[macro_export] |
| 34 | macro_rules! test { |
| 35 | ($test_name:ident) => { |
| 36 | $crate::_paste::paste!( |
Andrew Walbran | 7e69ba5 | 2023-05-10 14:47:49 +0000 | [diff] [blame] | 37 | #[$crate::_linkme::distributed_slice($crate::runner::IGNORABLETEST_TESTS)] |
Andrew Walbran | 13d5ebc | 2022-11-29 18:20:08 +0000 | [diff] [blame] | 38 | fn [< __test_ $test_name >]() -> $crate::_libtest_mimic::Trial { |
| 39 | $crate::_libtest_mimic::Trial::test( |
| 40 | ::std::stringify!($test_name), |
| 41 | move || ignorabletest::runner::run($test_name), |
| 42 | ) |
| 43 | } |
| 44 | ); |
| 45 | }; |
| 46 | ($test_name:ident, ignore_if: $ignore_expr:expr) => { |
| 47 | $crate::_paste::paste!( |
Andrew Walbran | 7e69ba5 | 2023-05-10 14:47:49 +0000 | [diff] [blame] | 48 | #[$crate::_linkme::distributed_slice($crate::runner::IGNORABLETEST_TESTS)] |
Andrew Walbran | 13d5ebc | 2022-11-29 18:20:08 +0000 | [diff] [blame] | 49 | fn [< __test_ $test_name >]() -> $crate::_libtest_mimic::Trial { |
| 50 | $crate::_libtest_mimic::Trial::test( |
| 51 | ::std::stringify!($test_name), |
| 52 | move || ignorabletest::runner::run($test_name), |
| 53 | ).with_ignored_flag($ignore_expr) |
| 54 | } |
| 55 | ); |
| 56 | }; |
| 57 | } |