Class TestUtilities
java.lang.Object
org.checkerframework.framework.test.TestUtilities
Utilities for testing.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
True if the JVM is version 11 or above.static final boolean
True if the JVM is version 17 or above.static final boolean
True if the JVM is version 18 or above.static final boolean
True if the JVM is version 9 or above.static final boolean
True if the JVM is version 11 or lower.static final boolean
True if the JVM is version 17 or lower.static final boolean
True if the JVM is version 18 or lower. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
assertTestDidNotFail
(TypecheckResult testResult) If the given TypecheckResult has unexpected or missing diagnostics, fail the running JUnit test.deeplyEnclosedJavaTestFiles
(File directory) Returns all the Java files that are descendants of the given directory.diagnosticsToStrings
(Iterable<Diagnostic<? extends JavaFileObject>> actualDiagnostics, boolean usingAnomsgtxt) diagnosticToString
(Diagnostic<? extends JavaFileObject> diagnostic, boolean usingAnomsgtxt) static void
Create the directory (and its parents) if it does not exist.static File
findComparisonFile
(File testFile) findFilesInParent
(File parent, String... fileNames) Prepends a file to the beginning of each filename.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.findNestedJavaTestFiles
(String... dirNames) findRelativeNestedJavaFiles
(File parent, String... dirNames) findRelativeNestedJavaFiles
(String parent, String... dirNames) getJavaFilesAsArgumentList
(File... dirs) Traverses the directories listed looking for Java test files.static boolean
Returns the value of system property "emit.test.debug".static File
getTestFile
(String fileRelativeToTestsDir) static boolean
isJavaFile
(File file) static boolean
isJavaTestFile
(File file) optionMapToList
(Map<String, @Nullable String> options) static String
summarizeSourceFiles
(List<File> javaFiles) Return the file absolute pathnames, separated by commas.static void
writeDiagnostics
(File file, File testFile, List<String> expected, List<String> actual, List<String> unexpected, List<String> missing, boolean usingNoMsgText, boolean testFailed) static void
writeJavacArguments
(File file, Iterable<? extends JavaFileObject> files, Iterable<String> options, Iterable<String> processors) static void
writeLines
(File file, Iterable<?> lines) Write all the lines in the given Iterable to the given File.static void
writeTestConfiguration
(File file, TestConfiguration config) Append a test configuration to the end of a file.
-
Field Details
-
IS_AT_LEAST_9_JVM
public static final boolean IS_AT_LEAST_9_JVMTrue if the JVM is version 9 or above. -
IS_AT_LEAST_11_JVM
public static final boolean IS_AT_LEAST_11_JVMTrue if the JVM is version 11 or above. -
IS_AT_MOST_11_JVM
public static final boolean IS_AT_MOST_11_JVMTrue if the JVM is version 11 or lower. -
IS_AT_LEAST_17_JVM
public static final boolean IS_AT_LEAST_17_JVMTrue if the JVM is version 17 or above. -
IS_AT_MOST_17_JVM
public static final boolean IS_AT_MOST_17_JVMTrue if the JVM is version 17 or lower. -
IS_AT_LEAST_18_JVM
public static final boolean IS_AT_LEAST_18_JVMTrue if the JVM is version 18 or above. -
IS_AT_MOST_18_JVM
public static final boolean IS_AT_MOST_18_JVMTrue if the JVM is version 18 or lower.
-
-
Constructor Details
-
TestUtilities
public TestUtilities()
-
-
Method Details
-
findNestedJavaTestFiles
-
findRelativeNestedJavaFiles
-
findRelativeNestedJavaFiles
-
findJavaFilesPerDirectory
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 directoriesdirNames
- names of directories to search- Returns:
- list where each item is a list of Java test files grouped by directory
-
findFilesInParent
Prepends a file to the beginning of each filename.- Parameters:
parent
- a file to prepend to each filenamefileNames
- file names- Returns:
- the file names, each with
parent
prepended
-
getJavaFilesAsArgumentList
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
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
-
isJavaTestFile
-
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
Return the file absolute pathnames, separated by commas.- Parameters:
javaFiles
- a list of Java files- Returns:
- the file absolute pathnames, separated by commas
-
getTestFile
-
findComparisonFile
-
optionMapToList
-
writeLines
Write all the lines in the given Iterable to the given File.- Parameters:
file
- where to write the lineslines
- what lines to write
-
writeDiagnostics
-
writeTestConfiguration
Append a test configuration to the end of a file.- Parameters:
file
- the file to write toconfig
- the configuration to append to the end of the file
-
writeJavacArguments
-
assertTestDidNotFail
If the given TypecheckResult has unexpected or missing diagnostics, fail the running JUnit test.- Parameters:
testResult
- the result of type-checking
-
ensureDirectoryExists
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"
-