public class TestUtilities extends Object
Modifier and Type | Field and Description |
---|---|
static boolean |
IS_AT_LEAST_11_JVM
True if the JVM is version 11 or above.
|
static boolean |
IS_AT_LEAST_17_JVM
True if the JVM is version 17 or above.
|
static boolean |
IS_AT_LEAST_18_JVM
True if the JVM is version 18 or above.
|
static boolean |
IS_AT_LEAST_9_JVM
True if the JVM is version 9 or above.
|
static boolean |
IS_AT_MOST_11_JVM
True if the JVM is version 11 or lower.
|
static boolean |
IS_AT_MOST_17_JVM
True if the JVM is version 17 or lower.
|
static boolean |
IS_AT_MOST_18_JVM
True if the JVM is version 18 or lower.
|
Constructor and Description |
---|
TestUtilities() |
Modifier and Type | Method and Description |
---|---|
static void |
assertTestDidNotFail(TypecheckResult testResult)
If the given TypecheckResult has unexpected or missing diagnostics, fail the running JUnit
test.
|
static List<File> |
deeplyEnclosedJavaTestFiles(File directory)
Returns all the Java files that are descendants of the given directory.
|
static Set<String> |
diagnosticsToStrings(Iterable<Diagnostic<? extends JavaFileObject>> actualDiagnostics,
boolean usingAnomsgtxt) |
static @Nullable String |
diagnosticToString(Diagnostic<? extends JavaFileObject> diagnostic,
boolean usingAnomsgtxt) |
static void |
ensureDirectoryExists(String dir)
Create the directory (and its parents) if it does not exist.
|
static File |
findComparisonFile(File testFile) |
static List<Object[]> |
findFilesInParent(File parent,
String... fileNames)
Prepends a file to the beginning of each filename.
|
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.
|
static List<File> |
findNestedJavaTestFiles(String... dirNames) |
static List<File> |
findRelativeNestedJavaFiles(File parent,
String... dirNames) |
static List<File> |
findRelativeNestedJavaFiles(String parent,
String... dirNames) |
static List<File> |
getJavaFilesAsArgumentList(File... dirs)
Traverses the directories listed looking for Java test files.
|
static boolean |
getShouldEmitDebugInfo()
Returns the value of system property "emit.test.debug".
|
static File |
getTestFile(String fileRelativeToTestsDir) |
static boolean |
isJavaFile(File file) |
static boolean |
isJavaTestFile(File file) |
static List<String> |
optionMapToList(Map<String,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.
|
public static final boolean IS_AT_LEAST_9_JVM
public static final boolean IS_AT_LEAST_11_JVM
public static final boolean IS_AT_MOST_11_JVM
public static final boolean IS_AT_LEAST_17_JVM
public static final boolean IS_AT_MOST_17_JVM
public static final boolean IS_AT_LEAST_18_JVM
public static final boolean IS_AT_MOST_18_JVM
public static List<File> findRelativeNestedJavaFiles(String parent, String... dirNames)
public static List<File> findRelativeNestedJavaFiles(File parent, String... dirNames)
public static List<List<File>> findJavaFilesPerDirectory(File parent, String... dirNames)
parent
- parent directory of the dirNames directoriesdirNames
- names of directories to searchpublic static List<Object[]> findFilesInParent(File parent, String... fileNames)
parent
- a file to prepend to each filenamefileNames
- file namesparent
prependedpublic static List<File> getJavaFilesAsArgumentList(File... dirs)
dirs
- directories in which to search for Java test filespublic static List<File> deeplyEnclosedJavaTestFiles(File directory)
directory
- a directorypublic static boolean isJavaFile(File file)
public static boolean isJavaTestFile(File file)
public static @Nullable String diagnosticToString(Diagnostic<? extends JavaFileObject> diagnostic, boolean usingAnomsgtxt)
public static Set<String> diagnosticsToStrings(Iterable<Diagnostic<? extends JavaFileObject>> actualDiagnostics, boolean usingAnomsgtxt)
public static String summarizeSourceFiles(List<File> javaFiles)
javaFiles
- a list of Java filespublic static void writeLines(File file, Iterable<?> lines)
file
- where to write the lineslines
- what lines to writepublic static void writeDiagnostics(File file, File testFile, List<String> expected, List<String> actual, List<String> unexpected, List<String> missing, boolean usingNoMsgText, boolean testFailed)
public static void writeTestConfiguration(File file, TestConfiguration config)
file
- the file to write toconfig
- the configuration to append to the end of the filepublic static void writeJavacArguments(File file, Iterable<? extends JavaFileObject> files, Iterable<String> options, Iterable<String> processors)
public static void assertTestDidNotFail(TypecheckResult testResult)
testResult
- the result of type-checkingpublic static void ensureDirectoryExists(String dir)
dir
- the directory to createpublic static boolean getShouldEmitDebugInfo()