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

pitest-descartes #22: added pseudoTestedThreshold and #14

Merged
merged 2 commits into from
Aug 3, 2018
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
19 changes: 8 additions & 11 deletions src/main/java/eu/stamp_project/PmpContext.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package eu.stamp_project.plugins;
package eu.stamp_project;

// **********************************************************************
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.io.File;
import java.util.List;
import java.util.Set;

import org.apache.maven.project.MavenProject;
import org.apache.maven.artifact.Artifact;

import org.pitest.maven.AbstractPitMojo;
import org.pitest.classpath.DirectoryClassPathRoot;
import org.apache.maven.project.MavenProject;
import org.pitest.classinfo.ClassName;

import org.pitest.classpath.DirectoryClassPathRoot;
import org.pitest.maven.PmpMojo;

import eu.stamp_project.plugins.PmpProject;

// **********************************************************************
public class PmpContext
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package eu.stamp_project.plugins;

// **********************************************************************
import java.io.File;
import java.util.function.Predicate;

import org.apache.maven.project.MavenProject;
import java.util.function.Predicate;

import eu.stamp_project.PmpContext;

// **********************************************************************
public class PmpNonEmptyProjectCheck implements Predicate<MavenProject>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
package eu.stamp_project.plugins;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
// **********************************************************************
import java.util.List;
import java.util.Set;
import java.util.ArrayList;
import java.util.Iterator;
import java.io.File;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
// import org.apache.maven.model.Model;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;

import org.apache.maven.project.MavenProject;
import org.pitest.maven.MojoToReportOptionsConverter;
import org.pitest.maven.PmpMojo;
import org.pitest.maven.SurefireConfigConverter;
import org.pitest.mutationtest.config.ReportOptions;
import org.pitest.mutationtest.config.PluginServices;
import org.pitest.mutationtest.tooling.AnalysisResult;
import org.pitest.mutationtest.tooling.CombinedStatistics;
import org.pitest.mutationtest.tooling.EntryPoint;
import org.pitest.mutationtest.tooling.AnalysisResult;
import org.pitest.maven.MojoToReportOptionsConverter;
import org.pitest.maven.SurefireConfigConverter;
import org.pitest.classpath.DirectoryClassPathRoot;

import org.pitest.maven.AbstractPitMojo;

import org.pitest.maven.PmpMojo;
import eu.stamp_project.PmpContext;

// **********************************************************************
public class PmpProject
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/eu/stamp_project/report/MethodThresholds.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package eu.stamp_project.report;

public class MethodThresholds {
private static MethodThresholds instance;

private int pseudoTestedThresold;

private int partialyTestedThresold;

private MethodThresholds() {
}

public static MethodThresholds getInstance() {
if (instance == null) {
instance = new MethodThresholds();
}
return instance;
}

public int getPseudoTestedThresold() {
return pseudoTestedThresold;
}

public void setPseudoTestedThresold(int pseudoTestedThresold) {
this.pseudoTestedThresold = pseudoTestedThresold;
}

public int getPartialyTestedThresold() {
return partialyTestedThresold;
}

public void setPartialyTestedThresold(int partialyTestedThresold) {
this.partialyTestedThresold = partialyTestedThresold;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package eu.stamp_project.report;

import org.pitest.mutationtest.ListenerArguments;
import org.pitest.mutationtest.MutationResultListener;
import org.pitest.mutationtest.MutationResultListenerFactory;

import java.util.Properties;

public class PseudoPartialyTestingFactory implements MutationResultListenerFactory {


public MutationResultListener getListener(Properties props, ListenerArguments args) {
return new PseudoPartialyTestingListener(args);
}

public String name() {
return "CHECKTHRESHOLDS";
}

public String description() {
return "Check if Pseudo/Partially Tested scores are above thresholds parameters";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package eu.stamp_project.report;

import org.pitest.mutationtest.ClassMutationResults;
import org.pitest.mutationtest.ListenerArguments;
import org.pitest.mutationtest.MutationResultListener;

import eu.stamp_project.mutationtest.descartes.reporting.models.MethodRecord;

public class PseudoPartialyTestingListener implements MutationResultListener {
private Integer tested = 0;
private Integer notCovered = 0;
private Integer psedudoTested = 0;
private Integer partiallyTested = 0;

private ListenerArguments args;

public PseudoPartialyTestingListener(final ListenerArguments args) {
this.args = args;
}

public ListenerArguments getArguments() {
return args;
}

@Override
public void runStart() {
}

@Override
public void handleMutationResult(ClassMutationResults results) {
MethodRecord.getRecords(results).forEach(this::checkMethod);
}

@Override
public void runEnd() {
throwErrorIfPseudoTestedAboveThreshold(psedudoTested);
throwErrorIfPartiallyTestedAboveThreshold(partiallyTested);
}

private void throwErrorIfPartiallyTestedAboveThreshold(Integer partiallyTested) {
if ((MethodThresholds.getInstance().getPartialyTestedThresold() != 0)
&& (partiallyTested > MethodThresholds.getInstance().getPartialyTestedThresold())) {
throw new RuntimeException("Partially Tested score of " + partiallyTested + " is above threshold of "
+ MethodThresholds.getInstance().getPartialyTestedThresold());
}
}

private void throwErrorIfPseudoTestedAboveThreshold(Integer psedudoTested) {
if ((MethodThresholds.getInstance().getPartialyTestedThresold() != 0)
&& (psedudoTested > MethodThresholds.getInstance().getPseudoTestedThresold())) {
throw new RuntimeException("Pseudo Tested score of " + psedudoTested + " is above threshold of "
+ MethodThresholds.getInstance().getPseudoTestedThresold());
}
}

private void checkMethod(MethodRecord method) {
switch (method.getClassification()) {
case TESTED:
tested++;
break;
case NOT_COVERED:
notCovered++;
break;
case PSEUDO_TESTED:
psedudoTested++;
break;
case PARTIALLY_TESTED:
partiallyTested++;
break;
}
}
}
74 changes: 40 additions & 34 deletions src/main/java/org/pitest/maven/PmpDescartesMojo.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,51 @@
package org.pitest.maven;

// **********************************************************************
import java.util.List;
import java.util.Set;
import java.util.ArrayList;
import java.io.File;
import java.util.logging.Logger;
import java.util.Collection;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.plugins.annotations.LifecyclePhase;

import java.util.Optional;
import java.util.function.Predicate;
import org.pitest.mutationtest.config.PluginServices;
import org.pitest.mutationtest.tooling.CombinedStatistics;
import org.pitest.maven.MojoToReportOptionsConverter;
import org.pitest.maven.SurefireConfigConverter;
import org.pitest.maven.AbstractPitMojo;
import org.pitest.maven.RunPitStrategy;
import org.pitest.maven.DependencyFilter;
import org.pitest.util.Log;
import org.pitest.mutationtest.config.ReportOptions;

import eu.stamp_project.plugins.*;
import eu.stamp_project.PmpContext;

// **********************************************************************
@Mojo(name = "descartes", defaultPhase = LifecyclePhase.VERIFY,
requiresDependencyResolution = ResolutionScope.TEST, threadSafe
= true)
public class PmpDescartesMojo extends PmpMojo
{
// **********************************************************************
// ******** methods
@Override
public void updateTargetClasses()
{
super.updateTargetClasses();
PmpContext.getInstance().getCurrentProject().setPmpMutationEngine("descartes");
}
@Mojo(name = "descartes", defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
public class PmpDescartesMojo extends PmpMojo {

/**
* Pseudo Tested threshold at which to fail build
*/
@Parameter(defaultValue = "0", property = "pseudoTestedThreshold")
private int pseudoTestedThreshold;

/**
* Partially Tested threshold at which to fail build
*/
@Parameter(defaultValue = "0", property = "partiallyTestedThreshold")
private int partiallyTestedThreshold;

// **********************************************************************
// ******** methods
@Override
public void updateTargetClasses() {
super.updateTargetClasses();
System.out
.println("MUTATION ENGINE >>> " + PmpContext.getInstance().getCurrentProject().getPmpMutationEngine());
PmpContext.getInstance().getCurrentProject().setPmpMutationEngine("descartes");
ReportOptions reportOptions = PmpContext.getInstance().getCurrentProject().getPitOptions();
Collection<String> outputFormats = null;
if (reportOptions != null) {
outputFormats = reportOptions.getOutputFormats();
} else {
reportOptions = new ReportOptions();
outputFormats = new ArrayList<String>();
}
outputFormats.add("METHODS");
reportOptions.addOutputFormats(outputFormats);
PmpContext.getInstance().getCurrentProject().setPitOptions(reportOptions);

}
}
42 changes: 25 additions & 17 deletions src/main/java/org/pitest/maven/PmpMojo.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
package org.pitest.maven;

// **********************************************************************
import java.util.List;
import java.util.Set;
import java.util.ArrayList;
import java.io.File;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.Optional;
import java.util.function.Predicate;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.plugins.annotations.LifecyclePhase;

import java.util.Optional;
import java.util.function.Predicate;
import org.apache.maven.project.MavenProject;
import org.pitest.mutationtest.config.PluginServices;
import org.pitest.mutationtest.tooling.CombinedStatistics;
import org.pitest.maven.MojoToReportOptionsConverter;
import org.pitest.maven.SurefireConfigConverter;
import org.pitest.maven.AbstractPitMojo;
import org.pitest.maven.RunPitStrategy;
import org.pitest.maven.DependencyFilter;
import org.pitest.util.Log;

import eu.stamp_project.plugins.*;
import eu.stamp_project.PmpContext;
import eu.stamp_project.plugins.PmpNonEmptyProjectCheck;
import eu.stamp_project.plugins.PmpProject;
import eu.stamp_project.report.MethodThresholds;

// **********************************************************************
@Mojo(name = "run", defaultPhase = LifecyclePhase.VERIFY,
requiresDependencyResolution = ResolutionScope.TEST, threadSafe
= true)

public class PmpMojo extends AbstractPitMojo
{
// **********************************************************************
Expand All @@ -47,6 +40,18 @@ public class PmpMojo extends AbstractPitMojo
@Parameter(defaultValue = "false", property = "shouldDisplayOnly")
protected boolean _ShouldDisplayOnly;

/**
* Pseudo Tested threshold at which to fail build
*/
@Parameter(defaultValue = "0", property = "pseudoTestedThreshold")
private int pseudoTestedThreshold;

/**
* Partially Tested threshold at which to fail build
*/
@Parameter(defaultValue = "0", property = "partiallyTestedThreshold")
private int partiallyTestedThreshold;

// **********************************************************************
// public
// **********************************************************************
Expand Down Expand Up @@ -194,6 +199,9 @@ protected Optional<CombinedStatistics> analyse()
@Override
protected RunDecision shouldRun()
{
MethodThresholds.getInstance().setPartialyTestedThresold(partiallyTestedThreshold);
MethodThresholds.getInstance().setPseudoTestedThresold(pseudoTestedThreshold);

RunDecision theDecision;
PmpProject myPmpProject;
String projectName = getProject().getArtifactId();
Expand Down