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
Modifier and TypeFieldDescriptionfinal com.google.errorprone.DiagnosticTestHelper.ClearableDiagnosticCollector
<JavaFileObject> static final com.google.common.truth.Correspondence
<Diagnostic<? extends JavaFileObject>, String> -
Constructor Summary
ConstructorDescriptionConstruct aDiagnosticTestHelper
not associated with a specific check.DiagnosticTestHelper
(String checkName) Construct aDiagnosticTestHelper
for a check with the given name. -
Method Summary
Modifier and TypeMethodDescriptionvoid
assertHasDiagnosticOnAllMatchingLines
(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.void
describe()
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) void
expectErrorMessage
(String key, Predicate<? super String> matcher) Expects an error message matchingmatcher
at 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 aDiagnosticTestHelper
not associated with a specific check. -
DiagnosticTestHelper
Construct aDiagnosticTestHelper
for 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 matchingmatcher
at 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.- Parameters:
source
- File in which to find matching lines- Throws:
IOException
-
getUnusedLookupKeys
-