@@ -10,18 +10,32 @@ declare_clippy_lint! {
1010 /// ### What it does
1111 /// Checks for test functions with an empty body.
1212 ///
13- /// ### Why restrict this?
14- /// Empty tests do not verify behavior. However, they can serve as temporary placeholders while
15- /// a test is being developed.
13+ /// ### Why is this bad?
14+ /// Empty tests pass automatically without asserting any behavior. They often represent
15+ /// unfinished work or forgotten stubs, giving a false sense of completeness without
16+ /// adding any coverage to the code
1617 ///
1718 /// ### Example
1819 /// ```no_run
20+ /// fn add(left: i32, right: i32) -> i32 {
21+ /// left + right
22+ /// }
23+ ///
1924 /// #[test]
20- /// fn empty_test () {}
25+ /// fn adds_numbers () {}
2126 /// ```
2227 ///
23- /// Remove the test if it is no longer needed, or add assertions that exercise the behavior it
24- /// is intended to test.
28+ /// Use instead:
29+ /// ```no_run
30+ /// fn add(left: i32, right: i32) -> i32 {
31+ /// left + right
32+ /// }
33+ ///
34+ /// #[test]
35+ /// fn adds_numbers() {
36+ /// assert_eq!(add(1, 2), 3);
37+ /// }
38+ /// ```
2539 #[ clippy:: version = "1.100.0" ]
2640 pub EMPTY_TEST ,
2741 restriction,
@@ -40,9 +54,11 @@ impl LateLintPass<'_> for EmptyTest {
4054 span : Span ,
4155 fn_def_id : LocalDefId ,
4256 ) {
43- if matches ! ( kind, FnKind :: ItemFn ( ..) )
57+ if let ExprKind :: Block ( block, _) = body. value . kind
58+ && block. stmts . is_empty ( )
59+ && block. expr . is_none ( )
60+ && matches ! ( kind, FnKind :: ItemFn ( ..) )
4461 && is_test_function ( cx. tcx , fn_def_id)
45- && matches ! ( body. value. kind, ExprKind :: Block ( block, _) if block. stmts. is_empty( ) && block. expr. is_none( ) )
4662 {
4763 span_lint ( cx, EMPTY_TEST , span, "empty test function" ) ;
4864 }
0 commit comments