From 1a5627025d43cec43e0ff72a133c49d396235c59 Mon Sep 17 00:00:00 2001 From: ghm Date: Fri, 25 Jun 2021 08:08:12 -0700 Subject: [PATCH] MissingTestCall: deal with graphVerify cases. This is a bit imperfect, as it looks for a #start call within the same test method (to avoid false positives from people assigning the stub to a variable, and then carrying on, but finally calling #start). It does catch a lot of horrors though! Flume: unknown commit PiperOrigin-RevId: 381472467 --- .../bugpatterns/MissingTestCall.java | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/MissingTestCall.java b/core/src/main/java/com/google/errorprone/bugpatterns/MissingTestCall.java index ce66780bc7c..3c9f5bc805d 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/MissingTestCall.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/MissingTestCall.java @@ -32,7 +32,6 @@ import com.google.errorprone.matchers.Description; import com.google.errorprone.matchers.JUnitMatchers; import com.google.errorprone.matchers.Matcher; -import com.google.errorprone.matchers.method.MethodMatchers.MethodClassMatcher; import com.sun.source.tree.BlockTree; import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.IdentifierTree; @@ -60,35 +59,39 @@ severity = ERROR) public final class MissingTestCall extends BugChecker implements MethodTreeMatcher { - private static final MethodClassMatcher EQUALS_TESTER = - instanceMethod().onDescendantOf("com.google.common.testing.EqualsTester"); - private static final MethodClassMatcher REFACTORING_HELPER = - instanceMethod().onDescendantOf("com.google.errorprone.BugCheckerRefactoringTestHelper"); - private static final MethodClassMatcher COMPILATION_HELPER = - instanceMethod().onDescendantOf("com.google.errorprone.CompilationTestHelper"); - private static final ImmutableSet PAIRINGS = ImmutableSet.of( MethodPairing.of( "EqualsTester", - EQUALS_TESTER.named("addEqualityGroup"), - EQUALS_TESTER.named("testEquals")), + instanceMethod() + .onDescendantOf("com.google.common.testing.EqualsTester") + .named("addEqualityGroup"), + instanceMethod() + .onDescendantOf("com.google.common.testing.EqualsTester") + .named("testEquals")), MethodPairing.of( "BugCheckerRefactoringTestHelper", - REFACTORING_HELPER.namedAnyOf( - "addInput", - "addInputLines", - "addInputFile", - "addOutput", - "addOutputLines", - "addOutputFile", - "expectUnchanged"), - REFACTORING_HELPER.named("doTest")), + instanceMethod() + .onDescendantOf("com.google.errorprone.BugCheckerRefactoringTestHelper") + .namedAnyOf( + "addInput", + "addInputLines", + "addInputFile", + "addOutput", + "addOutputLines", + "addOutputFile", + "expectUnchanged"), + instanceMethod() + .onDescendantOf("com.google.errorprone.BugCheckerRefactoringTestHelper") + .named("doTest")), MethodPairing.of( "CompilationTestHelper", - COMPILATION_HELPER.namedAnyOf( - "addSourceLines", "addSourceFile", "expectNoDiagnostics"), - COMPILATION_HELPER.named("doTest"))); + instanceMethod() + .onDescendantOf("com.google.errorprone.CompilationTestHelper") + .namedAnyOf("addSourceLines", "addSourceFile", "expectNoDiagnostics"), + instanceMethod() + .onDescendantOf("com.google.errorprone.CompilationTestHelper") + .named("doTest"))); @Override public Description matchMethod(MethodTree tree, VisitorState state) {