Macro run_test_for_aspects
run_test_for_aspects!() { /* proc-macro */ }
chili
only.Expand description
Run a particularly structured test multiple times for combinations of aspects
The tests which we would like to run are macros that will
be given as one argument to this proc_macro
.
These tests need to adhere to a strict format.
macro_rules! some_test(
(
name:$test_name:ident,
aspects:[$($asp:ident),*]
) => {
// Any code can be run here.
// For example, we can create a docstring test by using
/// ```
/// assert_eq!(0_usize, 10_usize - 10_usize);
$(#[doc = concat!("println!(\"", stringify!($asp), "\")")])*
/// ```
fn $test_name () {}
}
);
// This is how you would call the test by hand
some_test!(
name:my_test_name,
aspects: [Mechanics, Interaction]
);
In the next step, we can use run_test_for_aspects
to run this automatically generated
docstring test for every combination of aspects that we specify.
run_test_for_aspects!(
test: some_test,
aspects: [Mechanics, Interaction]
);
This will have generated the following code:
some_test!(
name:mechanics,
aspects: [Mechanics]
);
some_test!(
name:interaction,
aspects: [Interaction]
);
some_test!(
name:mechanics_interaction,
aspects: [Mechanics, Interaction]
);
some_test!(
name:interaction_mechanics,
aspects: [Interaction, Mechanics]
);
§Minimum Combinations
It is possible to specify a minimum number of combinations to test.
This means if we specify N aspects but only want to test combinations of M (where M<N)
different aspects, we can set the min_combinations
variable of this macro.
run_test_for_aspects!(
test: some_test,
aspects: [Mechanics, Interaction, Cycle, Reactions],
min_combinations: 3,
);
§Unsorted Combinations
By default all generated combinations of simulation aspects are sorted and will thus not
produce different tests when being reordered.
This means we assume that aspects: [Mechanics, Interaction]
is identical to aspects: [Interaction, Mechanics]
.
In the case where we also want to test the unsorted cases, we can specify the sorted
keyword.
run_test_for_aspects!(
test: some_test,
aspects: [Mechanics, Interaction],
sorted: false,
);