Class DiagnosticTestHelper
java.lang.Object
com.google.errorprone.DiagnosticTestHelper
Utility class for tests which need to assert on the diagnostics produced during compilation.
- Author:
- alexeagle@google.com (Alex Eagle)
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal com.google.errorprone.DiagnosticTestHelper.ClearableDiagnosticCollector<JavaFileObject> static final com.google.common.truth.Correspondence<Diagnostic<? extends JavaFileObject>, String> -
Constructor Summary
ConstructorsConstructorDescriptionConstruct aDiagnosticTestHelpernot associated with a specific check.DiagnosticTestHelper(String checkName) Construct aDiagnosticTestHelperfor a check with the given name. -
Method Summary
Modifier and TypeMethodDescriptionvoidassertHasDiagnosticOnAllMatchingLines(JavaFileObject source, com.google.errorprone.DiagnosticTestHelper.LookForCheckNameInDiagnostic lookForCheckNameInDiagnostic) Asserts that the diagnostics contain a diagnostic on each line of the source file that matches our bug marker pattern.voiddescribe()static org.hamcrest.Matcher<Diagnostic<? extends JavaFileObject>> diagnosticOnLine(URI fileUri, long line) static org.hamcrest.Matcher<Diagnostic<? extends JavaFileObject>> diagnosticOnLine(URI fileUri, long line, Predicate<? super String> matcher) voidexpectErrorMessage(String key, Predicate<? super String> matcher) Expects an error message matchingmatcherat the line below a comment matching the key.List<Diagnostic<? extends JavaFileObject>> Returns the lookup keys that weren't used.
-
Field Details
-
collector
public final com.google.errorprone.DiagnosticTestHelper.ClearableDiagnosticCollector<JavaFileObject> collector -
DIAGNOSTIC_CONTAINING
public static final com.google.common.truth.Correspondence<Diagnostic<? extends JavaFileObject>, String> DIAGNOSTIC_CONTAINING
-
-
Constructor Details
-
DiagnosticTestHelper
public DiagnosticTestHelper()Construct aDiagnosticTestHelpernot associated with a specific check. -
DiagnosticTestHelper
Construct aDiagnosticTestHelperfor a check with the given name.
-
-
Method Details
-
getDiagnostics
-
clearDiagnostics
public void clearDiagnostics() -
describe
-
diagnosticOnLine
public static org.hamcrest.Matcher<Diagnostic<? extends JavaFileObject>> diagnosticOnLine(URI fileUri, long line) -
diagnosticOnLine
public static org.hamcrest.Matcher<Diagnostic<? extends JavaFileObject>> diagnosticOnLine(URI fileUri, long line, Predicate<? super String> matcher) -
expectErrorMessage
Expects an error message matchingmatcherat the line below a comment matching the key. For example, given the source// BUG: Diagnostic matches: X a = b + c;
... you can useexpectErrorMessage("X", Predicates.containsPattern("Can't add b to c"));Error message keys that don't match any diagnostics will cause test to fail.
-
assertHasDiagnosticOnAllMatchingLines
public void assertHasDiagnosticOnAllMatchingLines(JavaFileObject source, com.google.errorprone.DiagnosticTestHelper.LookForCheckNameInDiagnostic lookForCheckNameInDiagnostic) throws IOException Asserts that the diagnostics contain a diagnostic on each line of the source file that matches our bug marker pattern. Parses the bug marker pattern for the specific string to look for in the diagnostic. The failure message names every line that fails, each with the first expectation it fails.- Parameters:
source- File in which to find matching lines- Throws:
IOException
-
getUnusedLookupKeys
-