Class DiagnosticTestHelper

java.lang.Object
com.google.errorprone.DiagnosticTestHelper

public class DiagnosticTestHelper extends Object
Utility class for tests which need to assert on the diagnostics produced during compilation.
Author:
alexeagle@google.com (Alex Eagle)
  • Field Details

    • collector

      public final com.google.errorprone.DiagnosticTestHelper.ClearableDiagnosticCollector<JavaFileObject> collector
  • Constructor Details

    • DiagnosticTestHelper

      public DiagnosticTestHelper()
      Construct a DiagnosticTestHelper not associated with a specific check.
    • DiagnosticTestHelper

      public DiagnosticTestHelper(String checkName)
      Construct a DiagnosticTestHelper for a check with the given name.
  • Method Details

    • suggestsRemovalOfLine

      public static org.hamcrest.Matcher<Diagnostic<? extends JavaFileObject>> suggestsRemovalOfLine(URI fileUri, int line)
    • getDiagnostics

      public List<Diagnostic<? extends JavaFileObject>> getDiagnostics()
    • clearDiagnostics

      public void clearDiagnostics()
    • describe

      public String describe()
    • diagnosticLineAndColumn

      public static org.hamcrest.Matcher<Diagnostic<? extends JavaFileObject>> diagnosticLineAndColumn(long line, long column)
    • 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)
    • diagnosticMessage

      public static org.hamcrest.Matcher<Diagnostic<? extends JavaFileObject>> diagnosticMessage(org.hamcrest.Matcher<String> matcher)
    • expectErrorMessage

      public void expectErrorMessage(String key, Predicate<? super String> matcher)
      Expects an error message matching matcher at the line below a comment matching the key. For example, given the source
         // BUG: Diagnostic matches: X
         a = b + c;
       
      ... you can use expectErrorMessage("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

      public Set<String> getUnusedLookupKeys()
      Returns the lookup keys that weren't used.