public class GenTests extends GenInputsAbstract
GenInputsAbstract.BehaviorType, GenInputsAbstract.BloodhoundCoverageUpdateMode, GenInputsAbstract.ClassLiteralsMode, GenInputsAbstract.FlakyTestAction, GenInputsAbstract.InputSelectionMode, GenInputsAbstract.Limits, GenInputsAbstract.MethodSelectionMode
Modifier and Type | Field and Description |
---|---|
private com.github.javaparser.ast.stmt.BlockStmt |
afterAllFixtureBody |
private com.github.javaparser.ast.stmt.BlockStmt |
afterEachFixtureBody |
private com.github.javaparser.ast.stmt.BlockStmt |
beforeAllFixtureBody |
private com.github.javaparser.ast.stmt.BlockStmt |
beforeEachFixtureBody |
private static java.lang.String |
command |
private static java.lang.String |
commandGrammar |
private static java.lang.String |
example |
private java.util.Map<java.net.URI,java.nio.file.FileSystem> |
fileSystemCache
A cache used by
getResourceDirectoryPath(java.lang.String) , to prevent FileSystemAlreadyExistsException . |
private static java.lang.String |
input |
private static java.lang.String |
NO_OPERATIONS_TO_TEST |
private static java.util.List<RawSignature> |
nonFlakyMethods
Methods that are known to be non-flaky.
|
private static java.util.List<java.lang.String> |
notes
Explanations printed to the user.
|
private static org.plumelib.options.Options |
options |
private static java.lang.String |
output |
private static java.lang.String |
pitch |
static java.lang.String |
POSSIBLY_FLAKY_PREFIX
Is output to the user before each possibly flaky method.
|
private int |
sequenceCompileFailureCount
The count of sequences that failed to compile.
|
private static java.lang.String |
summary |
static @Regex(value=0) @Identifier java.lang.String |
TEST_METHOD_NAME_PREFIX
The prefix for test method names.
|
private static java.lang.String |
where |
alias_ratio, all_logs, attempted_limit, bloodhound_logging, bloodhound_update_mode, capture_output, check_compilable, checked_exception, classlist, clear, clear_memory, cm_exception, debug_checks, deterministic, dont_omit_replaced_methods, dont_output_tests, dontexecute, error_test_basename, fail_on_generation_error, flaky_test_behavior, forbid_null, generated_limit, grt_fuzzing, grt_fuzzing_stddev, ignore_condition_compilation_error, ignore_condition_exception, ignore_condition_exception_quiet, input_selection, junit_after_all, junit_after_each, junit_before_all, junit_before_each, junit_output_dir, junit_package_name, junit_reflection_allowed, jvm_max_memory, literals_file, literals_level, log, maxsize, method_selection, methodlist, minimize_error_test, ncdf_exception, no_error_revealing_tests, no_regression_assertions, no_regression_tests, nondeterministic_methods_to_output, npe_on_non_null_input, npe_on_null_input, null_ratio, omit_classes, omit_classes_file, omit_classes_no_defaults, omit_field, omit_field_file, omit_field_list, omit_methods, omit_methods_file, omit_methods_no_defaults, only_test_public_members, oom_exception, operation_history_log, output_limit, print_non_compiling_file, progressdisplay, progressintervalmillis, PROGRESSINTERVALMILLIS_DEFAULT, progressintervalsteps, randomseed, regression_test_basename, repeat_heuristic, require_classname_in_test, require_covered_classes, selection_log, side_effect_free_methods, silently_ignore_bad_class_names, sof_exception, specifications, stop_on_error_test, string_maxlen, system_props, test_package, testclass, testjar, testsperfile, time_limit, unchecked_exception, use_jdk_specifications, visitor
Constructor and Description |
---|
GenTests()
GenTests constructor that uses default messages.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
convertClasspathToAbsolute(java.lang.String classpath)
Convert each element of the given classpath from a relative to an absolute path.
|
private java.util.Map<TypedClassOperation,java.lang.Integer> |
countSequencesPerOperation(java.util.List<ExecutableSequence> sequences,
MultiMap<Type,TypedClassOperation> assertableSideEffectFreeMethods)
Counts the number of sequences each operation occurs in.
|
private java.util.List<java.util.regex.Pattern> |
createPatternsFromSignatures(java.util.List<java.lang.String> signatures)
Creates a list of signature strings (see
RawSignature.toString() to a list of Pattern . |
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.
|
java.util.function.Predicate<ExecutableSequence> |
createTestOutputPredicate(java.util.Set<Sequence> excludeSet,
java.util.Set<java.lang.Class<?>> coveredClasses,
java.util.regex.Pattern includePattern)
Builds the test predicate that determines whether a particular sequence will be included in the
output based on command-line arguments.
|
private static @PolyNull java.util.List<java.lang.String> |
getFileText(@PolyNull java.lang.String filename)
Return the text of the given file, as a list of lines.
|
private boolean |
getFixtureCode()
Create fixture code from
GenInputsAbstract.junit_after_all , GenInputsAbstract.junit_after_each , GenInputsAbstract.junit_before_all , and GenInputsAbstract.junit_before_each and set fixture body variables. |
private java.util.Collection<? extends java.nio.file.Path> |
getJDKSpecificationFiles()
Returns the list of JDK specification files from the
specifications/jdk resources
directory in the Randoop jar file. |
private java.util.Set<TypedClassOperation> |
getOperationsInSequence(ExecutableSequence es)
Constructs a set of method-call operations appearing in an Executable Sequence.
|
private java.nio.file.Path |
getResourceDirectoryPath(java.lang.String resourceDirectory)
Returns the path for the resource directory in the jar file.
|
boolean |
handle(java.lang.String[] args) |
void |
incrementSequenceCompileFailureCount()
Increments the count of sequence compilation failures.
|
private static boolean |
isNonFlaky(TypedClassOperation op)
Returns true if the operation is definitely non-flaky.
|
private void |
printSequenceExceptionError(AbstractGenerator explorer,
SequenceExceptionError e)
Prints information about a
SequenceExceptionError that indicates a flaky test has been
found. |
private void |
processAndOutputFlakyMethods(java.util.List<ExecutableSequence> flakySequences,
java.util.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:
|
private java.util.List<java.util.regex.Pattern> |
readPatterns(org.plumelib.util.EntryReader er)
Returns patterns read from the given EntryReader.
|
private java.util.List<java.util.regex.Pattern> |
readPatterns(java.io.InputStream is,
java.lang.String filename)
Returns patterns read from the given stream.
|
private java.util.List<java.util.regex.Pattern> |
readPatterns(java.nio.file.Path path)
Returns patterns read from the given user-provided file.
|
private java.util.List<java.util.regex.Pattern> |
readPatternsFromResource(java.lang.String filename)
Returns patterns read from the given resource.
|
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.
|
private static java.util.regex.Pattern |
signatureToPattern(java.lang.String signatureString)
Converts a signature string (see
RawSignature.toString() to a Pattern that
matches that string (with spaces removed). |
private java.util.List<ExecutableSequence> |
testNamesToSequences(java.lang.Iterable<java.lang.String> testNames,
java.util.List<ExecutableSequence> sequences)
Given a collection of test names of the form "test005", returns the corresponding elements from
the given list.
|
private static void |
usage(java.lang.String format,
java.lang.Object... args)
Print message, then print usage information, then exit.
|
private void |
writeTestFiles(JUnitCreator junitCreator,
java.util.List<ExecutableSequence> testSequences,
CodeWriter codeWriter,
java.lang.String classNamePrefix,
java.lang.String testKind)
Creates the test classes for the test sequences using the
JUnitCreator and then writes
the files using the CodeWriter . |
checkOptionsValid, getClassnamesFromArgs, getClassNamesFromFile, getClassnamesFromJarFile, getStringSetFromFile, getStringSetFromFile, validateClassName
handles, printHTML, usageMessage
private static final java.lang.String NO_OPERATIONS_TO_TEST
private static final java.lang.String command
private static final java.lang.String pitch
private static final java.lang.String commandGrammar
private static final java.lang.String where
private static final java.lang.String summary
private static final java.lang.String input
private static final java.lang.String output
private static final java.lang.String example
private static final java.util.List<java.lang.String> notes
public static final @Regex(value=0) @Identifier java.lang.String TEST_METHOD_NAME_PREFIX
private com.github.javaparser.ast.stmt.BlockStmt afterAllFixtureBody
private com.github.javaparser.ast.stmt.BlockStmt afterEachFixtureBody
private com.github.javaparser.ast.stmt.BlockStmt beforeAllFixtureBody
private com.github.javaparser.ast.stmt.BlockStmt beforeEachFixtureBody
private static org.plumelib.options.Options options
private int sequenceCompileFailureCount
public static final java.lang.String POSSIBLY_FLAKY_PREFIX
private static final java.util.List<RawSignature> nonFlakyMethods
private java.util.Map<java.net.URI,java.nio.file.FileSystem> fileSystemCache
getResourceDirectoryPath(java.lang.String)
, to prevent FileSystemAlreadyExistsException
.public boolean handle(java.lang.String[] args)
handle
in class CommandHandler
public static MultiMap<Type,TypedClassOperation> readSideEffectFreeMethods()
private static boolean isNonFlaky(TypedClassOperation op)
op
- an operationprivate void processAndOutputFlakyMethods(java.util.List<ExecutableSequence> flakySequences, java.util.List<ExecutableSequence> sequences, MultiMap<Type,TypedClassOperation> sideEffectFreeMethodsByType, OmitMethodsPredicate omitMethodsPredicate, AccessibilityPredicate accessibilityPredicate)
(number of flaky tests M occurs in) / (number of total tests M occurs in)
flakySequences
- the flaky test sequencessequences
- all the sequences (flaky and non-flaky)sideEffectFreeMethodsByType
- side-effect-free methods to use in assertionsomitMethodsPredicate
- the user-supplied predicate for which methods should not be used
during test generationaccessibilityPredicate
- accessibility predicate for side-effect-free methodsprivate java.util.List<ExecutableSequence> testNamesToSequences(java.lang.Iterable<java.lang.String> testNames, java.util.List<ExecutableSequence> sequences)
testNames
- names of the form "test005"sequences
- test sequences (error or regression), numbered sequentiallyprivate java.util.Map<TypedClassOperation,java.lang.Integer> countSequencesPerOperation(java.util.List<ExecutableSequence> sequences, MultiMap<Type,TypedClassOperation> assertableSideEffectFreeMethods)
sequences
- a list of sequencesassertableSideEffectFreeMethods
- a map from a type to all its side-effect-free methods
that can be used in assertionsprivate java.util.Set<TypedClassOperation> getOperationsInSequence(ExecutableSequence es)
es
- an ExecutableSequencees
private java.lang.String convertClasspathToAbsolute(java.lang.String classpath)
classpath
- the classpath to replaceprivate void writeTestFiles(JUnitCreator junitCreator, java.util.List<ExecutableSequence> testSequences, CodeWriter codeWriter, java.lang.String classNamePrefix, java.lang.String testKind)
JUnitCreator
and then writes
the files using the CodeWriter
. Writes the test suite if GenInputsAbstract.junit_reflection_allowed
is true, or the test driver, otherwise.
Class names are numbered with classNamePrefix
as the prefix. The package for tests
is GenInputsAbstract.junit_package_name
.
junitCreator
- the JUnitCreator
to create the test class sourcetestSequences
- a list of ExecutableSequence
objects for test methodscodeWriter
- the CodeWriter
to output the test classesclassNamePrefix
- the prefix for the class nametestKind
- a String
indicating the kind of tests for logging and error messagesprivate boolean getFixtureCode()
GenInputsAbstract.junit_after_all
, GenInputsAbstract.junit_after_each
, GenInputsAbstract.junit_before_all
, and GenInputsAbstract.junit_before_each
and set fixture body variables.private java.util.List<java.util.regex.Pattern> readPatterns(java.nio.file.Path path)
path
- the file to read from, may be null (in which case this returns an empty list)private java.util.List<java.util.regex.Pattern> readPatternsFromResource(java.lang.String filename)
filename
- the resource from which to readprivate java.util.List<java.util.regex.Pattern> readPatterns(java.io.InputStream is, java.lang.String filename)
is
- the stream from which to readfilename
- the file name to use in diagnostic messagesprivate java.util.List<java.util.regex.Pattern> readPatterns(org.plumelib.util.EntryReader er)
er
- the EntryReader to read fromprivate java.util.List<java.util.regex.Pattern> createPatternsFromSignatures(java.util.List<java.lang.String> signatures)
RawSignature.toString()
to a list of Pattern
.signatures
- the list of signature stringsprivate static java.util.regex.Pattern signatureToPattern(java.lang.String signatureString)
RawSignature.toString()
to a Pattern
that
matches that string (with spaces removed).signatureString
- the string representation of a signaturesignatureString
private void printSequenceExceptionError(AbstractGenerator explorer, SequenceExceptionError e)
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.explorer
- the test generatore
- the sequence exceptionpublic java.util.function.Predicate<ExecutableSequence> createTestOutputPredicate(java.util.Set<Sequence> excludeSet, java.util.Set<java.lang.Class<?>> coveredClasses, java.util.regex.Pattern includePattern)
excludeSet
- the set of sequences to excludecoveredClasses
- the list of classes to test for coverageincludePattern
- the pattern for method name inclusionpublic static TestCheckGenerator createTestCheckGenerator(AccessibilityPredicate accessibility, ContractSet contracts, MultiMap<Type,TypedClassOperation> sideEffectFreeMethodsByType, OmitMethodsPredicate omitMethodsPredicate)
The generator always contains validity and contract checks. If regression tests are to be generated, it also contains the regression checks generator.
accessibility
- the accessibility predicatecontracts
- the contract checkssideEffectFreeMethodsByType
- the map from types to side-effect-free methodsomitMethodsPredicate
- the user-supplied predicate for which methods should not be used
during test generationTestCheckGenerator
that reflects command line argumentsprivate static void usage(java.lang.String format, java.lang.Object... args)
format
- the string formatargs
- the argumentsprivate static @PolyNull java.util.List<java.lang.String> getFileText(@PolyNull java.lang.String filename)
filename
argument is null. Terminates execution if the filename
file cannot be read.filename
- the file to readfilename
, as a list of stringsprivate java.util.Collection<? extends java.nio.file.Path> getJDKSpecificationFiles()
specifications/jdk
resources
directory in the Randoop jar file.RandoopBug
- if there is an error locating the specification filesprivate java.nio.file.Path getResourceDirectoryPath(java.lang.String resourceDirectory)
resourceDirectory
- the resource directory relative to the root of the jar file, should
start with "/"Path
for the resource directoryRandoopBug
- if an error occurs when locating the directorypublic void incrementSequenceCompileFailureCount()