public final class ContractCheckingGenerator extends TestCheckGenerator
If execution of the visited sequence is normal, it will generate checks for contracts over the
values from the execution. Contracts will be checked on all values except for boxed primitives or
Strings. For each contract violation, the visitor adds a Check to the TestChecks
object that is returned.
If the execution throws an exception considered to be an error, the visitor generates a NoExceptionCheck indicating that the statement should not throw the exception.
| Modifier and Type | Field and Description |
|---|---|
private ContractSet |
contracts |
| Constructor and Description |
|---|
ContractCheckingGenerator(ContractSet contracts)
Create a new visitor that checks the given contracts after the last statement in a sequence is
executed.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) Check |
checkContracts(java.util.List<ObjectContract> contracts,
ExecutableSequence eseq,
TupleSet<ReferenceValue> tuples)
If a contract fails for some tuple, returns some such failing check.
|
TestChecks<?> |
generateTestChecks(ExecutableSequence eseq)
Generate a
TestChecks object for the executed sequence eseq based on the
criteria of this generator. |
private static java.lang.Object[] |
getValues(java.util.List<ReferenceValue> tuple)
Creates an
Object array for the given value list. |
private TestChecks<?> |
singletonTestCheck(Check check)
Return a TestChecks that contains only the given check.
|
static boolean |
typesMatch(TypeTuple inputTypes,
java.util.List<ReferenceValue> valueTuple)
Indicates whether the given list of values matches the types in the type tuple.
|
hasGeneratorprivate ContractSet contracts
public ContractCheckingGenerator(ContractSet contracts)
contracts - expected to be unary contracts, i.e. for each contract c, c.getArity() == 1.public TestChecks<?> generateTestChecks(ExecutableSequence eseq)
TestChecks object for the executed sequence eseq based on the
criteria of this generator.
Adds checks to final statement of sequence. Looks for failure exceptions, and violations of
contracts in contracts.
generateTestChecks in class TestCheckGeneratoreseq - the sequence for which checks are generatedprivate TestChecks<?> singletonTestCheck(Check check)
check - the sole member of the singleton TestChecksCheck checkContracts(java.util.List<ObjectContract> contracts, ExecutableSequence eseq, TupleSet<ReferenceValue> tuples)
contracts - the contracts to checkeseq - the executable sequence that is the source of values for checking contractstuples - the value tuples to use as input to the contractsCheck of the first contract+tuple that did not succeed, or null if all
contracts succeeded. More specifically, returns a ObjectCheck if a contract fails,
an InvalidExceptionCheck if a contract throws an exception indicating that the
sequence is invalid, null otherwise.public static boolean typesMatch(TypeTuple inputTypes, java.util.List<ReferenceValue> valueTuple)
inputTypes - the expected types for contract inputvalueTuple - the values to match against input typesprivate static java.lang.Object[] getValues(java.util.List<ReferenceValue> tuple)
Object array for the given value list.tuple - the list of values