Skip to content

Commit

Permalink
make mutants available to history coverage limit
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoles committed Dec 16, 2024
1 parent 10bc017 commit 5a41bf9
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@
public interface History {

void initialize();

default Predicate<ClassName> limitTests(List<MutationDetails> mutants) {
return limitTests();
}

@Deprecated
default Predicate<ClassName> limitTests() {
return c -> true;
}

void processCoverage(CoverageDatabase coverageData);

List<MutationResult> analyse(List<MutationDetails> mutationsForClasses);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ public int priority() {
return Integer.MAX_VALUE;
}

@Override
public Collection<MutationDetails> mutants() {
return mutations;
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.pitest.mutationtest.build;

import java.util.Collection;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import org.pitest.mutationtest.MutationMetaData;
import org.pitest.mutationtest.MutationResult;
import org.pitest.mutationtest.engine.MutationDetails;
import org.pitest.util.Log;

public class KnownStatusMutationTestUnit implements MutationAnalysisUnit {
Expand All @@ -30,4 +33,11 @@ public int priority() {
return Integer.MAX_VALUE;
}

@Override
public Collection<MutationDetails> mutants() {
return mutations.stream()
.map(MutationResult::getDetails)
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.pitest.mutationtest.build;

import java.util.Collection;
import java.util.concurrent.Callable;

import org.pitest.mutationtest.MutationMetaData;
import org.pitest.mutationtest.engine.MutationDetails;

/**
* A unit of mutation analysis
Expand All @@ -11,4 +13,5 @@ public interface MutationAnalysisUnit extends Callable<MutationMetaData> {

int priority();

Collection<MutationDetails> mutants();
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public int priority() {
return this.availableMutations.size();
}

@Override
public Collection<MutationDetails> mutants() {
return availableMutations;
}

private void runTestsInSeperateProcess(final MutationStatusMap mutations)
throws IOException, InterruptedException {
while (mutations.hasUnrunMutations()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.pitest.mutationtest.build.WorkerFactory;
import org.pitest.mutationtest.config.ReportOptions;
import org.pitest.mutationtest.config.SettingsFactory;
import org.pitest.mutationtest.engine.MutationDetails;
import org.pitest.mutationtest.engine.MutationEngine;
import org.pitest.mutationtest.execute.MutationAnalysisExecutor;
import org.pitest.mutationtest.incremental.HistoryListener;
Expand Down Expand Up @@ -133,7 +134,15 @@ public CombinedStatistics runReport() throws IOException {
return emptyStatistics();
}

return runAnalysis(runtime, t0, args, engine, issues);
// Extract mutants from analysis units. Advanced history implementations can
// use this data to reduce the number of tests run during coverage.
// This is list of mutants is potentially larger than the one finally
// assessed, as no filters have been run across it.
List<MutationDetails> unfilteredMutants = preScanMutations.stream()
.flatMap(unit -> unit.mutants().stream())
.collect(Collectors.toList());

return runAnalysis(runtime, t0, args, engine, issues, unfilteredMutants);

}

Expand All @@ -142,11 +151,11 @@ private CombinedStatistics emptyStatistics() {
return new CombinedStatistics(mutationStatistics, new CoverageSummary(0,0), Collections.emptyList());
}

private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments args, MutationEngine engine, List<BuildMessage> issues) {
private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments args, MutationEngine engine, List<BuildMessage> issues, List<MutationDetails> unfilteredMutants) {
History history = this.strategies.history();
history.initialize();

CoverageDatabase coverageData = coverage().calculateCoverage(history.limitTests());
CoverageDatabase coverageData = coverage().calculateCoverage(history.limitTests(unfilteredMutants));
history.processCoverage(coverageData);

LOG.fine("Used memory after coverage calculation "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.junit.Test;
import org.pitest.mutationtest.MutationMetaData;
import org.pitest.mutationtest.engine.MutationDetails;

public class AnalyisPriorityComparatorTest {

Expand Down Expand Up @@ -50,6 +53,11 @@ public MutationMetaData call() throws Exception {
return null;
}

@Override
public Collection<MutationDetails> mutants() {
return Collections.emptyList();
}

};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -112,7 +113,7 @@ public void setUp() {
when(
this.listenerFactory.getListener(any(),
any(ListenerArguments.class))).thenReturn(this.listener);
when(history.limitTests()).thenReturn(c -> true);
when(history.limitTests(anyList())).thenReturn(c -> true);
mockMutationEngine();
}

Expand Down

0 comments on commit 5a41bf9

Please sign in to comment.