Skip to main content

count_tests

Function count_tests 

Source
pub fn count_tests(src: &str) -> u64
Expand description

Heuristic count of test functions in a Rust source: attributes whose final path segment is test#[test], #[tokio::test], #[test_case::test], and the like. A comprehension aid, not a parser: it does not discount attributes inside strings or comments, and #[cfg(test)] (a module gate, not a test) is deliberately excluded. Always reported as a heuristic value.

§Examples

use coding_tools::survey::count_tests;

assert_eq!(count_tests("#[test]\nfn a() {}\n#[tokio::test]\nasync fn b() {}"), 2);
// `#[cfg(test)]` gates a module; it is not a test.
assert_eq!(count_tests("#[cfg(test)]\nmod tests { fn helper() {} }"), 0);
assert_eq!(count_tests("fn not_a_test() {}"), 0);