Class CheckerFrameworkPerFileTest
- java.lang.Object
-
- org.checkerframework.framework.test.CheckerFrameworkPerFileTest
-
public abstract class CheckerFrameworkPerFileTest extends java.lang.Object
Compiles all test files individually. UseCheckerFrameworkPerDirectoryTest
to compile all files in a test directory together.To use this class you must do two things:
- Create exactly 1 constructor in the subclass with exactly 1 argument of type java.io.File. This File will be the Java file that is compiled and whose output is verified.
- Create one of the following 2 public static methods with the annotation
org.junit.runners.Parameterized.Parameters. The method name and signature must match
exactly.
@Parameters public static String [] getTestDirs()
getTestDir must return an array of directories that exist in the test folder, e.g.
@Parameters public static String [] getTestDirs() { return new String[]{"all-systems", "flow"}; }
The directories can contain more path information (e.g., "myTestDir/moreTests") but note, the test suite will find all of the Java test files that exists below the listed directories. It is unnecessary to list child directories of a directory you have already listed.@Parameters public static List<File> getTestFiles()
The method returns a List of Java files. There are methods like
TestUtilities.findNestedJavaTestFiles(java.lang.String...)
to help you construct this List. The PerDirectorySuite will then instantiate the subclass once for each file returned by getTestFiles and execute the run method. An example of this method is:@Parameters public static List<File> getTestFiles() { return TestUtilities.findNestedJavaTestFiles("aggregate"); }
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Class<?>
checker
The checker to use for tests.protected java.util.List<java.lang.String>
checkerOptions
Extra options to pass to javac when running the checker.protected java.lang.String
testDir
The path, relative to the test root directory (seeCheckerFrameworkRootedTest.resolveTestDirectory()
), to the directory containing test inputs.protected java.io.File
testFile
The file containing test code, which will be type-checked.
-
Constructor Summary
Constructors Modifier Constructor Description protected
CheckerFrameworkPerFileTest(java.io.File testFile, java.lang.Class<? extends javax.annotation.processing.AbstractProcessor> checker, java.lang.String testDir, java.lang.String... checkerOptions)
Creates a new checker test.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkResult(TypecheckResult typecheckResult)
Check that theTypecheckResult
did not fail.java.util.List<java.lang.String>
customizeOptions(java.util.List<java.lang.String> previousOptions)
Override this method if you would like to supply a checker command-line option that depends on the Java file passed to the test.protected java.io.File
resolveTestDirectory()
Resolves the test root directory from the optionalTestRootDirectory
annotation or falls back to the default ofcurrentDir/tests
.void
run()
-
-
-
Field Detail
-
testFile
protected final java.io.File testFile
The file containing test code, which will be type-checked.
-
checker
protected final java.lang.Class<?> checker
The checker to use for tests.
-
testDir
protected final java.lang.String testDir
The path, relative to the test root directory (seeCheckerFrameworkRootedTest.resolveTestDirectory()
), to the directory containing test inputs.
-
checkerOptions
protected final java.util.List<java.lang.String> checkerOptions
Extra options to pass to javac when running the checker.
-
-
Constructor Detail
-
CheckerFrameworkPerFileTest
protected CheckerFrameworkPerFileTest(java.io.File testFile, java.lang.Class<? extends javax.annotation.processing.AbstractProcessor> checker, java.lang.String testDir, java.lang.String... checkerOptions)
Creates a new checker test.TestConfigurationBuilder.getDefaultConfigurationBuilder(String, File, String, Iterable, Iterable, List, boolean)
adds additional checker options.- Parameters:
testFile
- the file containing test code, which will be type-checkedchecker
- the class for the checker to usetestDir
- the path, relative to currentDir/tests, to the directory of test inputscheckerOptions
- options to pass to the compiler when running tests
-
-
Method Detail
-
run
public void run()
-
customizeOptions
public java.util.List<java.lang.String> customizeOptions(java.util.List<java.lang.String> previousOptions)
Override this method if you would like to supply a checker command-line option that depends on the Java file passed to the test. That file name is available in fieldtestFile
.If you want to specify the same command-line option for all tests of a particular checker, then pass it to the
CheckerFrameworkPerFileTest
constructor.- Parameters:
previousOptions
- the options specified in the constructor of the test previousOptions is unmodifiable- Returns:
- a new list of options or the original passed through
-
resolveTestDirectory
protected java.io.File resolveTestDirectory()
Resolves the test root directory from the optionalTestRootDirectory
annotation or falls back to the default ofcurrentDir/tests
.- Returns:
- the resolved directory
-
checkResult
public void checkResult(TypecheckResult typecheckResult)
Check that theTypecheckResult
did not fail.- Parameters:
typecheckResult
- result to check
-
-