Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 2694ac6

Browse files
committed
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.
1 parent fc1391c commit 2694ac6

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

crates/libm-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ musl-bitwise-tests = ["rand"]
1313

1414
[dependencies]
1515
libm = { path = "../.." }
16+
libm-macros = { path = "../libm-macros" }
1617

1718
[build-dependencies]
1819
rand = { version = "0.8.5", optional = true }
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//! Ensure that `for_each_function!` isn't missing any symbols.
2+
3+
/// Files in `src/` that do not export a testable symbol.
4+
const ALLOWED_SKIPS: &[&str] = &[
5+
// Not a generic test function
6+
"fenv",
7+
// Nonpublic functions
8+
"expo2",
9+
"k_cos",
10+
"k_cosf",
11+
"k_expo2",
12+
"k_expo2f",
13+
"k_sin",
14+
"k_sinf",
15+
"k_tan",
16+
"k_tanf",
17+
"rem_pio2",
18+
"rem_pio2_large",
19+
"rem_pio2f",
20+
];
21+
22+
macro_rules! callback {
23+
(
24+
fn_name: $name:ident,
25+
CFn: $_CFn:ty,
26+
CArgs: $_CArgs:ty,
27+
CRet: $_CRet:ty,
28+
RustFn: $_RustFn:ty,
29+
RustArgs: $_RustArgs:ty,
30+
RustRet: $_RustRet:ty,
31+
extra: [$push_to:ident],
32+
) => {
33+
$push_to.push(stringify!($name));
34+
};
35+
}
36+
37+
#[test]
38+
fn test_for_each_function_all_included() {
39+
let mut included = Vec::new();
40+
let mut missing = Vec::new();
41+
42+
libm_macros::for_each_function! {
43+
callback: callback,
44+
extra: [included],
45+
};
46+
47+
for f in libm_test::ALL_FUNCTIONS {
48+
if !included.contains(f) && !ALLOWED_SKIPS.contains(f) {
49+
missing.push(f)
50+
}
51+
}
52+
53+
if !missing.is_empty() {
54+
panic!(
55+
"missing tests for the following: {missing:#?} \
56+
\nmake sure any new functions are entered in \
57+
`ALL_FUNCTIONS` (in `libm-macros`)."
58+
);
59+
}
60+
}

0 commit comments

Comments
 (0)