private void exportMutantDetails(Mutater m, List<MutationDetails> indexable, int i) throws IOException { final MutationDetails md = indexable.get(i); final Path mutantFolder = this.mutantsDir.resolve("" + i); Files.createDirectories(mutantFolder); final Mutant mutant = m.getMutation(md.getId()); writeMutantToDisk(mutant, mutantFolder); writeBytecodeToDisk(mutant.getBytes(), mutantFolder); writeDetailsToDisk(md, mutantFolder); }
private Boolean shortCutEquals(MethodTree tree, MutationDetails a, Mutater m) { if (!mutatesAConditionalJump(tree, a.getInstructionIndex())) { return false; } final ClassTree mutant = ClassTree.fromBytes(m.getMutation(a.getId()).getBytes()); final MethodTree mutantEquals = mutant.methods().stream() .filter(MethodMatchers.forLocation(tree.asLocation())) .findFirst() .get(); return ALWAYS_FALSE.matches(mutantEquals.instructions()); }
private boolean isInfiniteLoop(MutationDetails each, Mutater m) { final ClassTree mutantClass = ClassTree.fromBytes(m.getMutation(each.getId()).getBytes()); final Optional<MethodTree> mutantMethod = mutantClass.methods().stream() .filter(forLocation(each.getId().getLocation())) .findFirst(); return infiniteLoopMatcher().matches(mutantMethod.get().instructions()); }
private void processMutation(final Reporter r, final TimeOutDecoratedTestSource testSource, final MutationDetails mutationDetails) throws IOException { final MutationIdentifier mutationId = mutationDetails.getId(); final Mutant mutatedClass = this.mutater.getMutation(mutationId); // For the benefit of mocking frameworks such as PowerMock // mess with the internals of Javassist so our mutated class // bytes are returned JavassistInterceptor.setMutant(mutatedClass); if (DEBUG) { LOG.fine("mutating method " + mutatedClass.getDetails().getMethod()); } final List<TestUnit> relevantTests = testSource .translateTests(mutationDetails.getTestsInOrder()); r.describe(mutationId); final MutationStatusTestPair mutationDetected = handleMutation( mutationDetails, mutatedClass, relevantTests); r.report(mutationId, mutationDetected); if (DEBUG) { LOG.fine("Mutation " + mutationId + " detected = " + mutationDetected); } }
@Test public void shouldReportErrorWhenOneOccursDuringAnalysis() { this.mutations.add(new MutationDetails(aMutationId().withIndex(0) .withMutator("foo").build(), "file", "desc", 0, 0)); when(this.mutater.getMutation(any(MutationIdentifier.class))).thenThrow( new PitError("foo")); this.testee.run(); verify(this.reporter).done(ExitCode.UNKNOWN_ERROR); }
public MutationDetails makeMutant(final String clazz, final int index) { final MutationIdentifier id = aMutationId() .withLocation(aLocation().withClass(ClassName.fromString(clazz))) .withIndex(index).withMutator("mutator").build(); final MutationDetails md = new MutationDetails(id, "sourceFile", "desc", 42, 0); when(this.mutater.getMutation(md.getId())).thenReturn( new Mutant(md, new byte[0])); return md; }
private void processMutation(final Reporter r, final TimeOutDecoratedTestSource testSource, final MutationDetails mutationDetails) throws IOException { final MutationIdentifier mutationId = mutationDetails.getId(); final Mutant mutatedClass = this.mutater.getMutation(mutationId); // For the benefit of mocking frameworks such as PowerMock // mess with the internals of Javassist so our mutated class // bytes are returned JavassistInterceptor.setMutant(mutatedClass); if (DEBUG) { LOG.fine("mutating method " + mutatedClass.getDetails().getMethod()); } final List<TestUnit> relevantTests = testSource .translateTests(mutationDetails.getTestsInOrder()); r.describe(mutationId); final MutationStatusTestPair mutationDetected = handleMutation( mutationDetails, mutatedClass, relevantTests); r.report(mutationId, mutationDetected); if (DEBUG) { LOG.fine("Mutation " + mutationId + " detected = " + mutationDetected); } }