Skip to content

Commit

Permalink
Merge pull request #888 from hcoles/max_mutations_cleanup
Browse files Browse the repository at this point in the history
default mutations per class feature to 1 and error if obsolete parameter used
  • Loading branch information
hcoles authored Apr 26, 2021
2 parents d0a101f + afbb985 commit 7b06d88
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,12 @@
*/
package org.pitest.mutationtest.config;

import static org.pitest.functional.prelude.Prelude.not;
import static org.pitest.functional.prelude.Prelude.or;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
import java.util.function.Predicate;

import org.pitest.classpath.ClassFilter;
import org.pitest.classpath.ClassPath;
import org.pitest.classpath.ClassPathRoot;
import org.pitest.classpath.PathFilter;
import org.pitest.classpath.ProjectClassPaths;
import org.pitest.functional.FCollection;
import java.util.Optional;
import org.pitest.functional.prelude.Prelude;
import org.pitest.help.Help;
import org.pitest.help.PitHelpError;
Expand All @@ -52,6 +33,25 @@
import org.pitest.util.ResultOutputStrategy;
import org.pitest.util.Unchecked;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.function.Predicate;

import static org.pitest.functional.prelude.Prelude.not;
import static org.pitest.functional.prelude.Prelude.or;

// FIXME move all logic to SettingsFactory and turn into simple bean

/**
Expand Down Expand Up @@ -104,8 +104,6 @@ public class ReportOptions {

private Collection<String> loggingClasses = new ArrayList<>();

private int maxMutationsPerClass;

private boolean verbose = false;
private boolean failWhenNoMutations = false;
private boolean skipFailingTests = false;
Expand Down Expand Up @@ -639,8 +637,7 @@ public String toString() {
+ ", jvmArgs=" + jvmArgs + ", numberOfThreads=" + numberOfThreads
+ ", timeoutFactor=" + timeoutFactor + ", timeoutConstant="
+ timeoutConstant + ", targetTests=" + targetTests + ", loggingClasses="
+ loggingClasses + ", maxMutationsPerClass=" + maxMutationsPerClass
+ ", verbose=" + verbose + ", failWhenNoMutations="
+ loggingClasses + ", verbose=" + verbose + ", failWhenNoMutations="
+ failWhenNoMutations + ", outputs=" + outputs + ", groupConfig="
+ groupConfig + ", fullMutationMatrix=" + fullMutationMatrix + ", mutationUnitSize=" + mutationUnitSize
+ ", shouldCreateTimestampedReports=" + shouldCreateTimestampedReports
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.pitest.mutationtest.filter;

import java.util.Optional;
import org.pitest.mutationtest.build.InterceptorParameters;
import org.pitest.mutationtest.build.MutationInterceptor;
import org.pitest.mutationtest.build.MutationInterceptorFactory;
Expand All @@ -26,11 +25,9 @@ public Feature provides() {

@Override
public MutationInterceptor createInterceptor(InterceptorParameters params) {
final Optional<Integer> max = params.getInteger(this.limit);
if (!max.isPresent()) {
throw new IllegalArgumentException("Max mutation per class filter requires a limit parameter");
}
return new LimitNumberOfMutationPerClassFilter(max.get());
final Integer max = params.getInteger(this.limit)
.orElse(1);
return new LimitNumberOfMutationPerClassFilter(max);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<configuration>
<exportLineCoverage>true</exportLineCoverage>
<outputFormats><value>XML</value></outputFormats>
<maxMutationsPerClass>6</maxMutationsPerClass>
<features>+CLASSLIMIT(limit[6])</features>
<timestampedReports>false</timestampedReports>
<targetClasses><param>sample*</param></targetClasses>
<verbose>true</verbose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<version>${pit.version}</version>
<configuration>
<exportLineCoverage>true</exportLineCoverage>
<maxMutationsPerClass>1</maxMutationsPerClass>
<features>+CLASSLIMIT(limit[1])</features>
<timestampedReports>false</timestampedReports>
<targetClasses><param>com.example*</param></targetClasses>
<verbose>true</verbose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
</excludedGroups>
<exportLineCoverage>true</exportLineCoverage>
<outputFormats><value>XML</value></outputFormats>
<maxMutationsPerClass>6</maxMutationsPerClass>
<timestampedReports>false</timestampedReports>
<targetTests><param>com.example.*</param></targetTests>
<targetClasses><param>com.example*</param></targetClasses>
<verbose>true</verbose>
<features>+CLASSLIMIT(limit[6])</features>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<outputFormats>
<value>XML</value>
</outputFormats>
<maxMutationsPerClass>1</maxMutationsPerClass>
<features>+CLASSLIMIT(limit[1])</features>
<timestampedReports>false</timestampedReports>
<mutators>
<mutator>NEGATE_CONDITIONALS</mutator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<configuration>
<testPlugin>testng</testPlugin>
<outputFormats><value>XML</value></outputFormats>
<maxMutationsPerClass>6</maxMutationsPerClass>
<features>+CLASSLIMIT(limit[6])</features>
<timestampedReports>false</timestampedReports>
<targetClasses><param>com.example*</param></targetClasses>
<verbose>true</verbose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<configuration>
<testPlugin>testng</testPlugin>
<outputFormats><value>XML</value></outputFormats>
<maxMutationsPerClass>6</maxMutationsPerClass>
<features>+CLASSLIMIT(limit[6])</features>
<timestampedReports>false</timestampedReports>
<targetClasses><param>com.example*</param></targetClasses>
<verbose>true</verbose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@
*/
package org.pitest.maven;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.model.Plugin;
Expand All @@ -32,13 +22,23 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.pitest.classinfo.ClassName;
import org.pitest.classpath.DirectoryClassPathRoot;
import java.util.function.Function;
import org.pitest.functional.FCollection;
import java.util.function.Predicate;
import org.pitest.mutationtest.config.ReportOptions;
import org.pitest.testapi.TestGroupConfig;
import org.pitest.util.Glob;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;

public class MojoToReportOptionsConverter {

private final AbstractPitMojo mojo;
Expand Down Expand Up @@ -150,9 +150,18 @@ private ReportOptions parseReportOptions(final List<String> classPath) {

data.setSkipFailingTests(this.mojo.skipFailingTests());

checkForObsoleteOptions(this.mojo);

return data;
}

private void checkForObsoleteOptions(AbstractPitMojo mojo) {
if (mojo.getMaxMutationsPerClass() > 0) {
throw new IllegalArgumentException("The max mutations per class argument is no longer supported, "
+ "use features=+CLASSLIMIT(limit[" + mojo.getMaxMutationsPerClass() + "]) instead");
}
}


private void determineHistory(final ReportOptions data) {
if (this.mojo.useHistory()) {
Expand Down Expand Up @@ -289,8 +298,7 @@ private Collection<String> useConfiguredTargetClassesOrFindOccupiedPackages(
return filters;
}
}



private Collection<String> findOccupiedPackages() {
String outputDirName = this.mojo.getProject().getBuild()
.getOutputDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.function.Predicate;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.mockito.AdditionalAnswers.returnsFirstArg;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -405,8 +406,12 @@ public void testDoesNotUseClasspathJarByDefault() {
public void testParsesUseClasspathJar() {
final ReportOptions actual = parseConfig("<useClasspathJar>true</useClasspathJar>");
assertTrue(actual.useClasspathJar());
}
}

public void testFailsIfObsoleteMaxMutationsParameterUsed() {
assertThatCode( () -> parseConfig("<maxMutationsPerClass>1</maxMutationsPerClass>"))
.hasMessageContaining("+CLASSLIMIT(limit[1])");
}

private ReportOptions parseConfig(final String xml) {
try {
Expand Down

0 comments on commit 7b06d88

Please sign in to comment.