Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delay test class identification #1248

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.pitest.mutationtest.build;

import org.pitest.classinfo.ClassName;
import org.pitest.coverage.TestInfo;
import org.pitest.functional.FCollection;
import org.pitest.functional.prelude.Prelude;
import org.pitest.mutationtest.DetectionStatus;
Expand All @@ -25,10 +24,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -96,22 +92,11 @@ private MutationAnalysisUnit makePreAnalysedUnit(

private MutationAnalysisUnit makeUnanalysedUnit(
final Collection<MutationDetails> needAnalysis) {
final Set<ClassName> uniqueTestClasses = new HashSet<>();
FCollection.flatMapTo(needAnalysis, mutationDetailsToTestClass(),
uniqueTestClasses);

return new MutationTestUnit(needAnalysis, uniqueTestClasses,
this.workerFactory);
return new MutationTestUnit(needAnalysis, this.workerFactory);
}

private static Predicate<MutationResult> statusNotKnown() {
return a -> a.getStatus() == DetectionStatus.NOT_STARTED;
}

private static Function<MutationDetails, Iterable<ClassName>> mutationDetailsToTestClass() {
return a -> a.getTestsInOrder().stream()
.map(TestInfo.toDefiningClassName())
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

import java.io.IOException;
import java.util.Collection;
import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import org.pitest.classinfo.ClassName;
import org.pitest.coverage.TestInfo;
import org.pitest.mutationtest.DetectionStatus;
import org.pitest.mutationtest.MutationMetaData;
import org.pitest.mutationtest.MutationStatusMap;
Expand All @@ -34,12 +37,9 @@ public class MutationTestUnit implements MutationAnalysisUnit {
private final Collection<MutationDetails> availableMutations;
private final WorkerFactory workerFactory;

private final Collection<ClassName> testClasses;

public MutationTestUnit(final Collection<MutationDetails> availableMutations,
final Collection<ClassName> testClasses, final WorkerFactory workerFactory) {
public MutationTestUnit(Collection<MutationDetails> availableMutations, WorkerFactory workerFactory) {
this.availableMutations = availableMutations;
this.testClasses = testClasses;
this.workerFactory = workerFactory;
}

Expand Down Expand Up @@ -76,7 +76,7 @@ private void runTestInSeperateProcessForMutationRange(
final Collection<MutationDetails> remainingMutations = mutations
.getUnrunMutations();
final MutationTestProcess worker = this.workerFactory.createWorker(
remainingMutations, this.testClasses);
remainingMutations, testClassesFor(remainingMutations));
worker.start();

setFirstMutationToStatusOfStartedInCaseMinionFailsAtBoot(mutations,
Expand All @@ -88,6 +88,12 @@ private void runTestInSeperateProcessForMutationRange(
correctResultForProcessExitCode(mutations, exitCode);
}

private Set<ClassName> testClassesFor(Collection<MutationDetails> remainingMutations) {
return remainingMutations.stream()
.flatMap(m -> m.getTestsInOrder().stream().map(TestInfo.toDefiningClassName()))
.collect(Collectors.toSet());
}

private static ExitCode waitForMinionToDie(final MutationTestProcess worker) {
final ExitCode exitCode = worker.waitToDie();
LOG.fine("Exit code was - " + exitCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.pitest.mutationtest.engine.MutationEngine;
import org.pitest.process.JavaAgent;
import org.pitest.process.LaunchOptions;
import org.pitest.testapi.Configuration;
import org.pitest.util.Verbosity;

public class MutationTestUnitTest {
Expand All @@ -34,9 +33,6 @@ public class MutationTestUnitTest {
private List<MutationDetails> mutations;
private Collection<ClassName> tests;

@Mock
private Configuration config;

private MutationConfig mutationConfig;

@Mock
Expand All @@ -55,7 +51,7 @@ public void setUp() {
this.javaAgent));
this.mutations = new ArrayList<>();
this.tests = new ArrayList<>();
this.testee = new MutationTestUnit(this.mutations, this.tests,
this.testee = new MutationTestUnit(this.mutations,
new WorkerFactory(null, TestPluginArguments.defaults(), this.mutationConfig, EngineArguments.arguments(), this.timeout,
Verbosity.DEFAULT, false, null));

Expand All @@ -75,7 +71,7 @@ public void shouldReportWhenMutationsNotCoveredByAnyTest() throws Exception {
public void shouldReportPriorityBasedOnNumberOfMutations() {
this.mutations.add(MutationDetailsMother.aMutationDetail().build());
this.testee = new MutationTestUnit(MutationDetailsMother.aMutationDetail()
.build(42), this.tests, null);
.build(42), null);
assertThat(this.testee.priority()).isEqualTo(42);
}

Expand Down