Skip to content

Commit

Permalink
MissingTestCall: deal with graphVerify cases.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
graememorgan authored and Error Prone Team committed Jun 25, 2021
1 parent 3ae0dd1 commit 1a56270
Showing 1 changed file with 25 additions and 22 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MethodPairing> 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) {
Expand Down

0 comments on commit 1a56270

Please sign in to comment.