Class CheckerFrameworkPerDirectoryTest

  • Direct Known Subclasses:
    CheckerFrameworkWPIPerDirectoryTest

    public abstract class CheckerFrameworkPerDirectoryTest
    extends java.lang.Object
    Compiles all test files in a test directory together. Use CheckerFrameworkPerFileTest to compile each test file in a test directory individually. A CheckerFrameworkPerDirectoryTest is faster than an equivalent CheckerFrameworkPerFileTest, but can only test that processor errors or warnings are issued.

    To create a CheckerFrameworkPerDirectoryTest, create a new class that extends this class. The new class must do the following:

    1. Declare a constructor taking 1 parameter of type java.util.List<java.io.File>. This is a list of the files that will be compiled.
    2. Declare the following method:
      @Parameters public static String [] getTestDirs()

      getTestDir must return an array of directories that exist in the test folder. 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.

    
     public class MyTest extends CheckerFrameworkPerDirectoryTest {
       /** @param testFiles the files containing test code, which will be type-checked */
       public MyTest(List<File> testFiles) {
         super(testFiles, MyChecker.class, "", "Anomsgtext");
       }
      @Parameters
       public static String [] getTestDirs() {
         return new String[]{"all-systems"};
       }
     }
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List<@BinaryName java.lang.String> checkerNames
      The binary names of the checkers to run.
      protected java.util.List<java.lang.String> checkerOptions
      Extra options to pass to javac when running the checker.
      protected java.util.List<java.lang.String> classpathExtra
      Extra entries for the classpath.
      protected java.lang.String testDir
      The path, relative to the test root directory (see CheckerFrameworkRootedTest.resolveTestDirectory()), to the directory containing test inputs.
      protected java.util.List<java.io.File> testFiles
      The files containing test code, which will be type-checked.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected CheckerFrameworkPerDirectoryTest​(java.util.List<java.io.File> testFiles, java.lang.Class<? extends javax.annotation.processing.AbstractProcessor> checker, java.lang.String testDir, java.lang.String... checkerOptions)
      Creates a new checker test.
      protected CheckerFrameworkPerDirectoryTest​(java.util.List<java.io.File> testFiles, java.lang.Class<? extends javax.annotation.processing.AbstractProcessor> checker, java.lang.String testDir, java.util.List<java.lang.String> classpathExtra, java.lang.String... checkerOptions)
      Creates a new checker test.
      protected CheckerFrameworkPerDirectoryTest​(java.util.List<java.io.File> testFiles, java.util.List<@BinaryName java.lang.String> checkerNames, java.lang.String testDir, java.util.List<java.lang.String> classpathExtra, java.lang.String... checkerOptions)
      Creates a new checker test.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TypecheckResult adjustTypecheckResult​(TypecheckResult testResult)
      This method is called before issuing assertions about a TypecheckResult.
      void checkResult​(TypecheckResult typecheckResult)
      Check that the TypecheckResult 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 files passed to the test.
      protected java.io.File resolveTestDirectory()
      Resolves the test root directory from the optional TestRootDirectory annotation or falls back to the default of currentDir/tests.
      void run()
      Run the tests.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • testFiles

        protected final java.util.List<java.io.File> testFiles
        The files containing test code, which will be type-checked.
      • checkerNames

        protected final java.util.List<@BinaryName java.lang.String> checkerNames
        The binary names of the checkers to run.
      • testDir

        protected final java.lang.String testDir
        The path, relative to the test root directory (see CheckerFrameworkRootedTest.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.
      • classpathExtra

        protected final java.util.List<java.lang.String> classpathExtra
        Extra entries for the classpath.
    • Constructor Detail

      • CheckerFrameworkPerDirectoryTest

        protected CheckerFrameworkPerDirectoryTest​(java.util.List<java.io.File> testFiles,
                                                   java.lang.Class<? extends javax.annotation.processing.AbstractProcessor> checker,
                                                   java.lang.String testDir,
                                                   java.lang.String... checkerOptions)
        Parameters:
        testFiles - the files containing test code, which will be type-checked
        checker - the class for the checker to use
        testDir - the path, relative to currentDir/tests, to the directory of test inputs
        checkerOptions - options to pass to the compiler when running tests
      • CheckerFrameworkPerDirectoryTest

        protected CheckerFrameworkPerDirectoryTest​(java.util.List<java.io.File> testFiles,
                                                   java.lang.Class<? extends javax.annotation.processing.AbstractProcessor> checker,
                                                   java.lang.String testDir,
                                                   java.util.List<java.lang.String> classpathExtra,
                                                   java.lang.String... checkerOptions)
        Parameters:
        testFiles - the files containing test code, which will be type-checked
        checker - the class for the checker to use
        testDir - the path, relative to currentDir/tests, to the directory of test inputs
        classpathExtra - extra entries for the classpath, relative to a directory such as checker-framework/checker
        checkerOptions - options to pass to the compiler when running tests
      • CheckerFrameworkPerDirectoryTest

        protected CheckerFrameworkPerDirectoryTest​(java.util.List<java.io.File> testFiles,
                                                   java.util.List<@BinaryName java.lang.String> checkerNames,
                                                   java.lang.String testDir,
                                                   java.util.List<java.lang.String> classpathExtra,
                                                   java.lang.String... checkerOptions)
        Parameters:
        testFiles - the files containing test code, which will be type-checked
        checkerNames - the binary names of the checkers to run
        testDir - the path, relative to currentDir/tests, to the directory of test inputs
        classpathExtra - extra entries for the classpath, relative to a directory such as checker-framework/checker
        checkerOptions - options to pass to the compiler when running tests
    • Method Detail

      • run

        public void run()
        Run the tests.
      • adjustTypecheckResult

        public TypecheckResult adjustTypecheckResult​(TypecheckResult testResult)
        This method is called before issuing assertions about a TypecheckResult. Subclasses can override it to customize behavior.
        Parameters:
        testResult - a test result to possibly change
        Returns:
        a TypecheckResult to use instead, which may be the unmodified argument
      • resolveTestDirectory

        protected java.io.File resolveTestDirectory()
        Resolves the test root directory from the optional TestRootDirectory annotation or falls back to the default of currentDir/tests.
        Returns:
        the resolved directory
      • checkResult

        public void checkResult​(TypecheckResult typecheckResult)
        Check that the TypecheckResult did not fail.
        Parameters:
        typecheckResult - result to check