blob: 746c0dd7e742b33db819311759c136951e738fdc [file] [log] [blame]
Andrew Walbran13d5ebc2022-11-29 18:20:08 +00001//! Test harness which supports ignoring tests at runtime.
2
3pub mod runner;
4
5#[doc(hidden)]
6pub use libtest_mimic as _libtest_mimic;
7#[doc(hidden)]
8pub use paste as _paste;
9
10/// Macro to generate the main function for the test harness.
11#[macro_export]
12macro_rules! test_main {
13 ($tests:expr) => {
14 #[cfg(test)]
15 fn main() {
16 ignorabletest::runner::main($tests)
17 }
18 };
19}
20
21/// Macro to generate a function which returns a list of tests to be run.
22///
23/// # Usage
24/// ```
25/// list_tests!{all_tests: [test_this, test_that]};
26///
27/// test!(test_this);
28/// fn test_this() {
29/// // ...
30/// }
31///
32/// test!(test_that);
33/// fn test_that() {
34/// // ...
35/// }
36/// ```
37#[macro_export]
38macro_rules! list_tests {
39 {$function_name:ident: [$( $test_name:ident ),* $(,)? ]} => {
40 pub fn $function_name() -> ::std::vec::Vec<$crate::_libtest_mimic::Trial> {
41 vec![
42 $( $crate::_paste::paste!([<__test_ $test_name>]()) ),*
43 ]
44 }
45 };
46}
47
48/// Macro to generate a wrapper function for a single test.
49///
50/// # Usage
51///
52/// ```
53/// test!(test_string_equality);
54/// fn test_string_equality() {
55/// assert_eq!("", "");
56/// }
57/// ```
58#[macro_export]
59macro_rules! test {
60 ($test_name:ident) => {
61 $crate::_paste::paste!(
62 fn [< __test_ $test_name >]() -> $crate::_libtest_mimic::Trial {
63 $crate::_libtest_mimic::Trial::test(
64 ::std::stringify!($test_name),
65 move || ignorabletest::runner::run($test_name),
66 )
67 }
68 );
69 };
70 ($test_name:ident, ignore_if: $ignore_expr:expr) => {
71 $crate::_paste::paste!(
72 fn [< __test_ $test_name >]() -> $crate::_libtest_mimic::Trial {
73 $crate::_libtest_mimic::Trial::test(
74 ::std::stringify!($test_name),
75 move || ignorabletest::runner::run($test_name),
76 ).with_ignored_flag($ignore_expr)
77 }
78 );
79 };
80}