Trevor Gross 05c9691f15 Add a test that for_each_fn correctly lists all functions
Create a new test that checks `for_each_fn` against `ALL_FUNCTIONS`,
i.e. the manually entered function list against the automatically
collected list. If any are missing (e.g. new symbol added), then this
will produce an error.
2024-10-28 12:59:38 -05:00

61 lines
1.3 KiB
Rust

//! Ensure that `for_each_function!` isn't missing any symbols.
/// Files in `src/` that do not export a testable symbol.
const ALLOWED_SKIPS: &[&str] = &[
// Not a generic test function
"fenv",
// Nonpublic functions
"expo2",
"k_cos",
"k_cosf",
"k_expo2",
"k_expo2f",
"k_sin",
"k_sinf",
"k_tan",
"k_tanf",
"rem_pio2",
"rem_pio2_large",
"rem_pio2f",
];
macro_rules! callback {
(
fn_name: $name:ident,
CFn: $_CFn:ty,
CArgs: $_CArgs:ty,
CRet: $_CRet:ty,
RustFn: $_RustFn:ty,
RustArgs: $_RustArgs:ty,
RustRet: $_RustRet:ty,
extra: [$push_to:ident],
) => {
$push_to.push(stringify!($name));
};
}
#[test]
fn test_for_each_function_all_included() {
let mut included = Vec::new();
let mut missing = Vec::new();
libm_macros::for_each_function! {
callback: callback,
extra: [included],
};
for f in libm_test::ALL_FUNCTIONS {
if !included.contains(f) && !ALLOWED_SKIPS.contains(f) {
missing.push(f)
}
}
if !missing.is_empty() {
panic!(
"missing tests for the following: {missing:#?} \
\nmake sure any new functions are entered in \
`ALL_FUNCTIONS` (in `libm-macros`)."
);
}
}