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.
This commit is contained in:
parent
0acb3e2b50
commit
05c9691f15
2 changed files with 61 additions and 0 deletions
|
|
@ -13,6 +13,7 @@ test-musl-serialized = ["rand"]
|
|||
|
||||
[dependencies]
|
||||
libm = { path = "../.." }
|
||||
libm-macros = { path = "../libm-macros" }
|
||||
|
||||
[build-dependencies]
|
||||
rand = { version = "0.8.5", optional = true }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
//! 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`)."
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue