// Randoop's default behavior is to output as failing test cases sequences // that lead to a few select number of exceptions, including NPEs or assertion // violations; any other exceptions are conservatively assumed to be normal behavior. private boolean failureRevealingException(ExceptionalExecution exec) { if (exec.getException().getClass().equals(NullPointerException.class)) return true; if (exec.getException().getClass().equals(AssertionError.class)) return true; if (exec.getException().getClass().equals(StackOverflowError.class)) return true; return false; }
private void checkUnary(ExecutableSequence s, ObjectContract c, Set<Integer> values, int idx) { for (Integer i : values) { ExecutionOutcome result = s.getResult(i); assert result instanceof NormalExecution : s; ExecutionOutcome exprOutcome = ObjectContractUtils.execute(c, ((NormalExecution) result).getRuntimeValue()); if (exprOutcome instanceof NormalExecution) { NormalExecution e = (NormalExecution) exprOutcome; if (e.getRuntimeValue().equals(true)) { continue; // Behavior ok. } } else { // Execution of contract resulted in exception. Do not create // a contract-violation decoration. assert exprOutcome instanceof ExceptionalExecution; ExceptionalExecution e = (ExceptionalExecution) exprOutcome; if (e.getException().equals(BugInRandoopException.class)) { throw new BugInRandoopException(e.getException()); } if (!c.evalExceptionMeansFailure()) { // Exception thrown, but not considered a failure. // Will not record behavior. continue; } } // If we get here, either the contract returned false or resulted // in an exception that is considered a failure. Add // a contract violation check. // Create an check that records the actual value // returned by the expression, marking it as invalid // behavior. Check obs = new ObjectCheck(c, i, s.sequence.getVariable(i)); s.addCheck(idx, obs, false); } }