datatest_stable/
macros.rs#[macro_export]
macro_rules! harness {
( $( { $($args:tt)* } ),+ $(,)* ) => {
fn main() -> ::std::process::ExitCode {
let mut requirements = Vec::new();
use $crate::data_source_kinds::*;
use $crate::test_kinds::*;
$(
$crate::harness_collect!(@gather_test requirements, { $($args)*, } => { });
)+
$crate::runner(&requirements)
}
};
( $( $name:path, $root:expr, $pattern:expr ),+ $(,)* ) => {
const _: () = {
compile_error!(
concat!(r"this format is no longer supported -- please switch to specifying as:
datatest_stable::harness! {
",
$(concat!(" { test = ", stringify!($name), ", root = ", stringify!($root), ", pattern = ", stringify!($pattern), " },\n"),)+
r"}
note: patterns are now evaluated relative to the provided root, not to the crate root
"));
};
}
}
#[macro_export]
#[doc(hidden)]
macro_rules! harness_collect {
(@gather_test
$requirements:expr,
{ test = $test:path, $($rest:tt)* } =>
{ }
) => {
$crate::harness_collect!(@gather_root
$requirements,
{ $($rest)* } =>
{ test = $test, }
);
};
(@gather_test
$requirements:expr,
{ $key:ident $($rest:tt)* } =>
{ }
) => {
compile_error!(concat!("expected `test`, found `", stringify!($key), "`"));
};
(@gather_test
$requirements:expr,
{ $(,)* } =>
{ }
) => {
compile_error!("expected `test`, but ran out of arguments");
};
(@gather_test
$requirements:expr,
{ $($rest:tt)* } =>
{ }
) => {
compile_error!(concat!("expected `test`, found non-identifier token: (rest: ", stringify!($($rest)*), ")"));
};
(@gather_root
$requirements:expr,
{ root = $root:expr, $($rest:tt)* } =>
{ $($collected:tt)* }
) => {
$crate::harness_collect!(@gather_pattern
$requirements,
{ $($rest)* } =>
{ $($collected)* root = $root, }
);
};
(@gather_root
$requirements:expr,
{ $key:ident $($rest:tt)* } =>
{ $($collected:tt)* }
) => {
compile_error!(concat!("expected `root`, found `", stringify!($key), "`"));
};
(@gather_root
$requirements:expr,
{ $(,)* } =>
{ $($collected:tt)* }
) => {
compile_error!(concat!("expected `root`, but ran out of arguments (collected: ", stringify!($($collected)*), ")"));
};
(@gather_root
$requirements:expr,
{ $($rest:tt)* } =>
{ $($collected:tt)* }
) => {
compile_error!(concat!("expected `root`, found non-identifier token (rest: ", stringify!($($rest)*), ")"));
};
(@gather_pattern
$requirements:expr,
{ pattern = $pattern:expr, $($rest:tt)* } =>
{ $($collected:tt)* }
) => {
$crate::harness_collect!(@finish
$requirements,
{ $($rest)* } =>
{ $($collected)* pattern = $pattern, }
);
};
(@gather_pattern
$requirements:expr,
{ $key:ident $($rest:tt)* } =>
{ $($collected:tt)* }
) => {
compile_error!(concat!("expected `pattern`, found `", stringify!($key), "`"));
};
(@gather_pattern
$requirements:expr,
{ $(,)* } =>
{ $($collected:tt)* }
) => {
$crate::harness_collect!(@finish
$requirements,
{ } =>
{ $($collected)* pattern = ".*", }
);
};
(@gather_pattern
$requirements:expr,
{ $($rest:tt)* } =>
{ $($collected:tt)* }
) => {
compile_error!(concat!("expected `pattern`, found non-identifier token (rest: ", stringify!($($rest)*), ")"));
};
(@finish
$requirements:expr,
{ $(,)* } =>
{ test = $test:path, root = $root:expr, pattern = $pattern:expr, }
) => {
$requirements.push(
$crate::Requirements::new(
$test.kind().resolve($test),
stringify!($test).to_string(),
$root.resolve_data_source(),
$pattern.to_string()
)
);
};
(@finish
$requirements:expr,
{ $($unexpected:tt)+ } =>
{ $($collected:tt)* }
) => {
compile_error!(concat!("unexpected extra arguments: ", stringify!($($unexpected)+)));
};
}