Class TestUtilities

java.lang.Object
org.checkerframework.framework.test.TestUtilities

public class TestUtilities extends Object
Utilities for testing.
  • Field Details

    • IS_AT_LEAST_9_JVM

      public static final boolean IS_AT_LEAST_9_JVM
      True if the JVM is version 9 or above.
    • IS_AT_LEAST_11_JVM

      public static final boolean IS_AT_LEAST_11_JVM
      True if the JVM is version 11 or above.
    • IS_AT_MOST_11_JVM

      public static final boolean IS_AT_MOST_11_JVM
      True if the JVM is version 11 or lower.
    • IS_AT_LEAST_17_JVM

      public static final boolean IS_AT_LEAST_17_JVM
      True if the JVM is version 17 or above.
    • IS_AT_MOST_17_JVM

      public static final boolean IS_AT_MOST_17_JVM
      True if the JVM is version 17 or lower.
    • IS_AT_LEAST_18_JVM

      public static final boolean IS_AT_LEAST_18_JVM
      True if the JVM is version 18 or above.
    • IS_AT_MOST_18_JVM

      public static final boolean IS_AT_MOST_18_JVM
      True if the JVM is version 18 or lower.
  • Constructor Details

    • TestUtilities

      public TestUtilities()
  • Method Details

    • findNestedJavaTestFiles

      public static List<File> findNestedJavaTestFiles(String... dirNames)
    • findRelativeNestedJavaFiles

      public static List<File> findRelativeNestedJavaFiles(String parent, String... dirNames)
    • findRelativeNestedJavaFiles

      public static List<File> findRelativeNestedJavaFiles(File parent, String... dirNames)
    • findJavaFilesPerDirectory

      public static List<List<File>> findJavaFilesPerDirectory(File parent, String... dirNames)
      Returns a list where each item is a list of Java files, excluding any skip tests, for each directory given by dirName and also a list for any subdirectory.
      Parameters:
      parent - parent directory of the dirNames directories
      dirNames - names of directories to search
      Returns:
      list where each item is a list of Java test files grouped by directory
    • findFilesInParent

      public static List<Object[]> findFilesInParent(File parent, String... fileNames)
      Prepends a file to the beginning of each filename.
      Parameters:
      parent - a file to prepend to each filename
      fileNames - file names
      Returns:
      the file names, each with parent prepended
    • getJavaFilesAsArgumentList

      public static List<File> getJavaFilesAsArgumentList(File... dirs)
      Traverses the directories listed looking for Java test files.
      Parameters:
      dirs - directories in which to search for Java test files
      Returns:
      a list of Java test files found in the directories
    • deeplyEnclosedJavaTestFiles

      public static List<File> deeplyEnclosedJavaTestFiles(File directory)
      Returns all the Java files that are descendants of the given directory.
      Parameters:
      directory - a directory
      Returns:
      all the Java files that are descendants of the given directory
    • isJavaFile

      public static boolean isJavaFile(File file)
    • isJavaTestFile

      public static boolean isJavaTestFile(File file)
    • diagnosticToString

      public static @Nullable String diagnosticToString(Diagnostic<? extends JavaFileObject> diagnostic, boolean usingAnomsgtxt)
    • diagnosticsToStrings

      public static Set<String> diagnosticsToStrings(Iterable<Diagnostic<? extends JavaFileObject>> actualDiagnostics, boolean usingAnomsgtxt)
    • summarizeSourceFiles

      public static String summarizeSourceFiles(List<File> javaFiles)
      Return the file absolute pathnames, separated by commas.
      Parameters:
      javaFiles - a list of Java files
      Returns:
      the file absolute pathnames, separated by commas
    • getTestFile

      public static File getTestFile(String fileRelativeToTestsDir)
    • findComparisonFile

      public static File findComparisonFile(File testFile)
    • optionMapToList

      public static List<String> optionMapToList(Map<String,@Nullable String> options)
      Given an option map, return a list of option names.
      Parameters:
      options - an option map
      Returns:
      return a list of option names
    • writeLines

      public static void writeLines(File file, Iterable<?> lines)
      Write all the lines in the given Iterable to the given File.
      Parameters:
      file - where to write the lines
      lines - what lines to write
    • writeDiagnostics

      public static void writeDiagnostics(File file, File testFile, List<String> expected, List<String> actual, List<String> unexpected, List<String> missing, boolean usingNoMsgText, boolean testFailed)
    • writeTestConfiguration

      public static void writeTestConfiguration(File file, TestConfiguration config)
      Append a test configuration to the end of a file.
      Parameters:
      file - the file to write to
      config - the configuration to append to the end of the file
    • writeJavacArguments

      public static void writeJavacArguments(File file, Iterable<? extends JavaFileObject> files, Iterable<String> options, Iterable<String> processors)
    • assertTestDidNotFail

      public static void assertTestDidNotFail(TypecheckResult testResult)
      If the given TypecheckResult has unexpected or missing diagnostics, fail the running JUnit test.
      Parameters:
      testResult - the result of type-checking
    • ensureDirectoryExists

      public static void ensureDirectoryExists(String dir)
      Create the directory (and its parents) if it does not exist.
      Parameters:
      dir - the directory to create
    • getShouldEmitDebugInfo

      public static boolean getShouldEmitDebugInfo()
      Returns the value of system property "emit.test.debug".
      Returns:
      the value of system property "emit.test.debug"