From 770d738829076e0be2152452ab68933a47a483e2 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 21 Jul 2026 15:55:11 +0800 Subject: feat: add testing macros and unit tests for linters Add `assert_detected!` and `assert_not_detected!` macros to simplify writing lint tests, along with initial test coverage for the unnecessary render result creation linter. --- mingling_cli/tmpls/lints.tmpl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'mingling_cli/tmpls') diff --git a/mingling_cli/tmpls/lints.tmpl b/mingling_cli/tmpls/lints.tmpl index 7507f98..fae1126 100644 --- a/mingling_cli/tmpls/lints.tmpl +++ b/mingling_cli/tmpls/lints.tmpl @@ -50,6 +50,24 @@ pub fn run_all_lints(file: &syn::File, source: &str) -> Vec { reports } +#[macro_export] +macro_rules! assert_detected { + ($linter:expr, $ast_type:ty => $code:tt) => { + // Parse the string into a syn::ItemFn + let ast: $ast_type = syn::parse_str(&stringify!($code)).unwrap(); + assert!(!$linter(ast, &stringify!($code).to_string()).is_empty()); + }; +} + +#[macro_export] +macro_rules! assert_not_detected { + ($linter:expr, $ast_type:ty => $code:tt) => { + // Parse the string into a syn::ItemFn + let ast: $ast_type = syn::parse_str(&stringify!($code)).unwrap(); + assert!($linter(ast, &stringify!($code).to_string()).is_empty()); + }; +} + @@@ >>> impls mod <<>>; pub use <<>>::linter as <<>>; -- cgit