diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/build/CompoundInterceptorFactory.java b/pitest-entry/src/main/java/org/pitest/mutationtest/build/CompoundInterceptorFactory.java index 00f5c0c6d..9b6cb9477 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/build/CompoundInterceptorFactory.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/build/CompoundInterceptorFactory.java @@ -20,7 +20,7 @@ public CompoundInterceptorFactory(List features, this.features = new FeatureSelector<>(features, filters); } - public MutationInterceptor createInterceptor( + public CompoundMutationInterceptor createInterceptor( ReportOptions data, CoverageDatabase coverage, ClassByteArraySource source) { diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/build/CompoundMutationInterceptor.java b/pitest-entry/src/main/java/org/pitest/mutationtest/build/CompoundMutationInterceptor.java index ca18a3040..c929c3d0d 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/build/CompoundMutationInterceptor.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/build/CompoundMutationInterceptor.java @@ -1,15 +1,17 @@ package org.pitest.mutationtest.build; -import static java.util.Comparator.comparing; +import org.pitest.bytecode.analysis.ClassTree; +import org.pitest.mutationtest.engine.Mutater; +import org.pitest.mutationtest.engine.MutationDetails; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Collectors; -import org.pitest.bytecode.analysis.ClassTree; -import org.pitest.mutationtest.engine.Mutater; -import org.pitest.mutationtest.engine.MutationDetails; +import static java.util.Comparator.comparing; public class CompoundMutationInterceptor implements MutationInterceptor { @@ -24,6 +26,12 @@ public static MutationInterceptor nullInterceptor() { return new CompoundMutationInterceptor(Collections.emptyList()); } + public CompoundMutationInterceptor filter(Predicate p) { + return new CompoundMutationInterceptor(children.stream() + .filter(p) + .collect(Collectors.toList())); + } + @Override public void begin(ClassTree clazz) { this.children.forEach(each -> each.begin(clazz)); diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java index 68b368da8..0a990a89d 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java @@ -35,6 +35,7 @@ import org.pitest.mutationtest.MutationAnalyser; import org.pitest.mutationtest.MutationConfig; import org.pitest.mutationtest.MutationResultListener; +import org.pitest.mutationtest.build.InterceptorType; import org.pitest.mutationtest.build.MutationAnalysisUnit; import org.pitest.mutationtest.build.MutationGrouper; import org.pitest.mutationtest.build.MutationInterceptor; @@ -67,6 +68,7 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; @@ -158,7 +160,7 @@ private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments this.timings.registerStart(Timings.Stage.BUILD_MUTATION_TESTS); final List tus = buildMutationTests(coverageData, history, - engine, args); + engine, args, allInterceptors()); this.timings.registerEnd(Timings.Stage.BUILD_MUTATION_TESTS); LOG.info("Created " + tus.size() + " mutation test units"); @@ -186,6 +188,10 @@ private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments coverageData.createSummary()); } + private Predicate allInterceptors() { + return i -> true; + } + private List findMutations(MutationEngine engine, EngineArguments args) { // Run mutant discovery without coverage data or history. // Ideally we'd ony discover mutants once, but the process is currently tightly @@ -194,11 +200,15 @@ private List findMutations(MutationEngine engine, EngineAr // an initial run here we are able to skip coverage generation when no mutants // are found, e.g if pitest is being run against diffs. this.timings.registerStart(Timings.Stage.MUTATION_PRE_SCAN); - List mutants = buildMutationTests(new NoCoverage(), new NullHistoryStore(), engine, args); + List mutants = buildMutationTests(new NoCoverage(), new NullHistoryStore(), engine, args, noReports()); this.timings.registerEnd(Timings.Stage.MUTATION_PRE_SCAN); return mutants; } + private Predicate noReports() { + return i -> !i.type().equals(InterceptorType.REPORT); + } + private void checkExcludedRunners() { final Collection excludedRunners = this.data.getExcludedRunners(); @@ -289,7 +299,8 @@ private void printStats(final MutationStatisticsListener stats) { private List buildMutationTests(CoverageDatabase coverageData, HistoryStore history, MutationEngine engine, - EngineArguments args) { + EngineArguments args, + Predicate interceptorFilter) { final MutationConfig mutationConfig = new MutationConfig(engine, coverage() .getLaunchOptions()); @@ -302,7 +313,8 @@ private List buildMutationTests(CoverageDatabase coverageD coverageData); final MutationInterceptor interceptor = this.settings.getInterceptor() - .createInterceptor(this.data, coverageData, bas); + .createInterceptor(this.data, coverageData, bas) + .filter(interceptorFilter); final MutationSource source = new MutationSource(mutationConfig, testPrioritiser, bas, interceptor); diff --git a/pitest-entry/src/test/java/org/pitest/mutationtest/build/CompoundMutationInterceptorTest.java b/pitest-entry/src/test/java/org/pitest/mutationtest/build/CompoundMutationInterceptorTest.java index 30b914c30..d2bee41eb 100644 --- a/pitest-entry/src/test/java/org/pitest/mutationtest/build/CompoundMutationInterceptorTest.java +++ b/pitest-entry/src/test/java/org/pitest/mutationtest/build/CompoundMutationInterceptorTest.java @@ -1,14 +1,5 @@ package org.pitest.mutationtest.build; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.pitest.mutationtest.engine.MutationDetailsMother.aMutationDetail; - -import java.util.Arrays; -import java.util.Collection; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -18,6 +9,16 @@ import org.pitest.mutationtest.engine.Mutater; import org.pitest.mutationtest.engine.MutationDetails; +import java.util.Arrays; +import java.util.Collection; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.pitest.mutationtest.engine.MutationDetailsMother.aMutationDetail; + @RunWith(MockitoJUnitRunner.class) public class CompoundMutationInterceptorTest { @@ -60,6 +61,16 @@ public void shouldNotifyAllChildrenOfNewClass() { verify(this.filterChild).begin(aClass); } + @Test + public void shouldFilterChildren() { + this.testee = new CompoundMutationInterceptor(Arrays.asList(this.modifyChild,this.filterChild)); + final ClassTree aClass = new ClassTree(null); + + this.testee.filter(i -> i == modifyChild).begin(aClass); + verify(this.modifyChild).begin(aClass); + verify(this.filterChild, never()).begin(aClass); + } + @Test public void shouldChainModifiedMutantListsThroughChildrenInCorrectOrder() { @@ -99,4 +110,5 @@ public void shouldNotifyAllChildrenOfEnd() { verify(this.filterChild).end(); } + }