Package randoop.main

Class GenTests

    • Constructor Detail

      • GenTests

        public GenTests()
        GenTests constructor that uses default messages.
    • Method Detail

      • readSideEffectFreeMethods

        public static MultiMap<Type,​TypedClassOperation> readSideEffectFreeMethods()
        Read side-effect-free methods from the default JDK side-effect-free method list, and from a user-provided method list if provided.
        Returns:
        a map from a Type to a set of side-effect-free methods that take that type as their only argument
      • isNonFlaky

        private static boolean isNonFlaky​(TypedClassOperation op)
        Returns true if the operation is definitely non-flaky.
        Parameters:
        op - an operation
        Returns:
        true if the operation is definitely non-flaky
      • processAndOutputFlakyMethods

        private void processAndOutputFlakyMethods​(List<ExecutableSequence> flakySequences,
                                                  List<ExecutableSequence> sequences,
                                                  MultiMap<Type,​TypedClassOperation> sideEffectFreeMethodsByType,
                                                  OmitMethodsPredicate omitMethodsPredicate,
                                                  AccessibilityPredicate accessibilityPredicate)
        Outputs names of suspected flaky methods by using the tf-idf metric (Term Frequency - Inverse Document Frequency), which is:
        (number of flaky tests M occurs in) / (number of total tests M occurs in)
        Parameters:
        flakySequences - the flaky test sequences
        sequences - all the sequences (flaky and non-flaky)
        sideEffectFreeMethodsByType - side-effect-free methods to use in assertions
        omitMethodsPredicate - the user-supplied predicate for which methods should not be used during test generation
        accessibilityPredicate - accessibility predicate for side-effect-free methods
      • testNamesToSequences

        private List<ExecutableSequence> testNamesToSequences​(Iterable<String> testNames,
                                                              List<ExecutableSequence> sequences)
        Given a collection of test names of the form "test005", returns the corresponding elements from the given list.
        Parameters:
        testNames - names of the form "test005"
        sequences - test sequences (error or regression), numbered sequentially
        Returns:
        the sequences corresponding to the test names
      • countSequencesPerOperation

        private Map<TypedClassOperation,​Integer> countSequencesPerOperation​(List<ExecutableSequence> sequences,
                                                                                  MultiMap<Type,​TypedClassOperation> assertableSideEffectFreeMethods)
        Counts the number of sequences each operation occurs in.
        Parameters:
        sequences - a list of sequences
        assertableSideEffectFreeMethods - a map from a type to all its side-effect-free methods that can be used in assertions
        Returns:
        a map from operation to the number of sequences in which the operation occurs at least once
      • getOperationsInSequence

        private Set<TypedClassOperation> getOperationsInSequence​(ExecutableSequence es)
        Constructs a set of method-call operations appearing in an Executable Sequence. Non-method-call operations are excluded.
        Parameters:
        es - an ExecutableSequence
        Returns:
        the set of method call operations in es
      • convertClasspathToAbsolute

        private String convertClasspathToAbsolute​(String classpath)
        Convert each element of the given classpath from a relative to an absolute path.
        Parameters:
        classpath - the classpath to replace
        Returns:
        a version of classpath with relative paths replaced by absolute paths
      • readPatterns

        private List<Pattern> readPatterns​(Path path)
        Returns patterns read from the given user-provided file.
        Parameters:
        path - the file to read from, may be null (in which case this returns an empty list)
        Returns:
        contents of the file, as a list of Patterns
      • readPatternsFromResource

        private List<Pattern> readPatternsFromResource​(String filename)
        Returns patterns read from the given resource.
        Parameters:
        filename - the resource from which to read
        Returns:
        contents of the resource, as a list of Patterns
      • readPatterns

        private List<Pattern> readPatterns​(InputStream is,
                                           String filename)
        Returns patterns read from the given stream.
        Parameters:
        is - the stream from which to read
        filename - the file name to use in diagnostic messages
        Returns:
        contents of the file, as a list of Patterns
      • readPatterns

        private List<Pattern> readPatterns​(org.plumelib.util.EntryReader er)
        Returns patterns read from the given EntryReader.
        Parameters:
        er - the EntryReader to read from
        Returns:
        contents of the file, as a list of Patterns
      • createPatternsFromSignatures

        private List<Pattern> createPatternsFromSignatures​(List<String> signatures)
        Creates a list of signature strings (see RawSignature.toString() to a list of Pattern.
        Parameters:
        signatures - the list of signature strings
        Returns:
        the list of patterns for the signature strings
      • signatureToPattern

        private static Pattern signatureToPattern​(String signatureString)
        Converts a signature string (see RawSignature.toString() to a Pattern that matches that string.
        Parameters:
        signatureString - the string representation of a signature
        Returns:
        the pattern to match signatureString
      • printSequenceExceptionError

        private void printSequenceExceptionError​(AbstractGenerator explorer,
                                                 SequenceExceptionError e)
        Prints information about a SequenceExceptionError that indicates a flaky test has been found. Prints information to help user identify source of flakiness, including exception, statement that threw the exception, the full sequence where exception was thrown, and the input subsequence.
        Parameters:
        explorer - the test generator
        e - the sequence exception
      • createTestOutputPredicate

        public Predicate<ExecutableSequence> createTestOutputPredicate​(Set<Sequence> excludeSet,
                                                                       Set<Class<?>> coveredClasses,
                                                                       Pattern includePattern)
        Builds the test predicate that determines whether a particular sequence will be included in the output based on command-line arguments. A true result means the test is a candidate for output.
        Parameters:
        excludeSet - the set of sequences to exclude
        coveredClasses - the list of classes to test for coverage
        includePattern - the pattern for method name inclusion
        Returns:
        the predicate
      • createTestCheckGenerator

        public static TestCheckGenerator createTestCheckGenerator​(AccessibilityPredicate accessibility,
                                                                  ContractSet contracts,
                                                                  MultiMap<Type,​TypedClassOperation> sideEffectFreeMethodsByType,
                                                                  OmitMethodsPredicate omitMethodsPredicate)
        Creates the test check generator for this run based on the command-line arguments. The goal of the generator is to produce all appropriate checks for each sequence it is applied to.

        The generator always contains validity and contract checks. If regression tests are to be generated, it also contains the regression checks generator.

        Parameters:
        accessibility - the accessibility predicate
        contracts - the contract checks
        sideEffectFreeMethodsByType - the map from types to side-effect-free methods
        omitMethodsPredicate - the user-supplied predicate for which methods should not be used during test generation
        Returns:
        the TestCheckGenerator that reflects command line arguments
      • usage

        private static void usage​(String format,
                                  Object... args)
        Print message, then print usage information, then exit.
        Parameters:
        format - the string format
        args - the arguments
      • getFileText

        private static @PolyNull List<String> getFileText​(@PolyNull String filename)
        Return the text of the given file, as a list of lines. Returns null if the filename argument is null. Terminates execution if the filename file cannot be read.
        Parameters:
        filename - the file to read
        Returns:
        the contents of filename, as a list of strings
      • getJDKSpecificationFiles

        private Collection<? extends Path> getJDKSpecificationFiles()
        Returns the list of JDK specification files from the specifications/jdk resources directory in the Randoop jar file.
        Returns:
        the list of JDK specification files
        Throws:
        RandoopBug - if there is an error locating the specification files
      • getResourceDirectoryPath

        private Path getResourceDirectoryPath​(String resourceDirectory)
        Returns the path for the resource directory in the jar file.
        Parameters:
        resourceDirectory - the resource directory relative to the root of the jar file, should start with "/"
        Returns:
        the Path for the resource directory
        Throws:
        RandoopBug - if an error occurs when locating the directory
      • incrementSequenceCompileFailureCount

        public void incrementSequenceCompileFailureCount()
        Increments the count of sequence compilation failures.