diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-21 15:55:11 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-21 15:55:11 +0800 |
| commit | 770d738829076e0be2152452ab68933a47a483e2 (patch) | |
| tree | 1d4ed37639ef4aca019c5139dfaa5cabec9976b8 /mingling_cli/tmpls/lints.tmpl | |
| parent | 0056e1095e75b34f39cde7de87ce6be2cd301ff1 (diff) | |
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.
Diffstat (limited to 'mingling_cli/tmpls/lints.tmpl')
| -rw-r--r-- | mingling_cli/tmpls/lints.tmpl | 18 |
1 files changed, 18 insertions, 0 deletions
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<MlintReport> { 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 <<<mod_name>>>; pub use <<<mod_name>>>::linter as <<<mod_name>>>; |
