-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1121 from hcoles/feature/remove_gregor_classinfo
- Loading branch information
Showing
20 changed files
with
293 additions
and
296 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
pitest-entry/src/main/java/org/pitest/mutationtest/build/intercept/groovy/GroovyFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.pitest.mutationtest.build.intercept.groovy; | ||
|
||
import org.pitest.bytecode.analysis.ClassTree; | ||
import org.pitest.mutationtest.build.InterceptorType; | ||
import org.pitest.mutationtest.build.MutationInterceptor; | ||
import org.pitest.mutationtest.engine.Mutater; | ||
import org.pitest.mutationtest.engine.MutationDetails; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
/** | ||
* Prevents mutation of groovy code since we can't properly handle it | ||
*/ | ||
public class GroovyFilter implements MutationInterceptor { | ||
|
||
boolean isGroovyClass = false; | ||
|
||
@Override | ||
public Collection<MutationDetails> intercept( | ||
Collection<MutationDetails> mutations, Mutater m) { | ||
if (isGroovyClass) { | ||
return Collections.emptyList(); | ||
} | ||
return mutations; | ||
} | ||
|
||
@Override | ||
public InterceptorType type() { | ||
return InterceptorType.FILTER; | ||
} | ||
|
||
@Override | ||
public void begin(ClassTree clazz) { | ||
isGroovyClass = isGroovyClass(clazz); | ||
} | ||
|
||
@Override | ||
public void end() { | ||
isGroovyClass = false; | ||
} | ||
|
||
private boolean isGroovyClass(ClassTree clazz) { | ||
return clazz.rawNode().interfaces != null && clazz.rawNode().interfaces.stream() | ||
.anyMatch(a -> a.startsWith("groovy/lang/") || a.startsWith("org/codehaus/groovy/runtime")); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...try/src/main/java/org/pitest/mutationtest/build/intercept/groovy/GroovyFilterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.pitest.mutationtest.build.intercept.groovy; | ||
|
||
import org.pitest.mutationtest.build.InterceptorParameters; | ||
import org.pitest.mutationtest.build.MutationInterceptor; | ||
import org.pitest.mutationtest.build.MutationInterceptorFactory; | ||
import org.pitest.plugin.Feature; | ||
|
||
public class GroovyFilterFactory implements MutationInterceptorFactory { | ||
|
||
@Override | ||
public String description() { | ||
return "Groovy junk mutations filter"; | ||
} | ||
|
||
@Override | ||
public MutationInterceptor createInterceptor(InterceptorParameters params) { | ||
return new GroovyFilter(); | ||
} | ||
|
||
@Override | ||
public Feature provides() { | ||
return Feature.named("FGROOVY") | ||
.withDescription("Filters out junk mutations in groovy code") | ||
.withOnByDefault(true); | ||
} | ||
|
||
} |
53 changes: 0 additions & 53 deletions
53
...main/java/org/pitest/mutationtest/build/intercept/javafeatures/EnumConstructorFilter.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...-entry/src/main/java/org/pitest/mutationtest/build/intercept/javafeatures/EnumFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.pitest.mutationtest.build.intercept.javafeatures; | ||
|
||
import org.pitest.bytecode.analysis.ClassTree; | ||
import org.pitest.mutationtest.build.InterceptorType; | ||
import org.pitest.mutationtest.build.MutationInterceptor; | ||
import org.pitest.mutationtest.engine.Location; | ||
import org.pitest.mutationtest.engine.Mutater; | ||
import org.pitest.mutationtest.engine.MutationDetails; | ||
|
||
import java.util.Collection; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Filters out mutations in Enum constructors, these are called only once | ||
* per instance so are effectively static initializers. | ||
* | ||
* This overlaps with the StaticInitializerInterceptor, and could | ||
* probably be removed. Left in place for now as it is computationally less | ||
* expensive. | ||
* | ||
* Also filters mutants is the compiler generated valueOf and values methods. | ||
*/ | ||
public class EnumFilter implements MutationInterceptor { | ||
|
||
private boolean isEnum; | ||
private ClassTree currentClass; | ||
|
||
@Override | ||
public InterceptorType type() { | ||
return InterceptorType.FILTER; | ||
} | ||
|
||
@Override | ||
public void begin(ClassTree clazz) { | ||
this.isEnum = clazz.rawNode().superName.equals("java/lang/Enum"); | ||
this.currentClass = clazz; | ||
} | ||
|
||
@Override | ||
public Collection<MutationDetails> intercept( | ||
Collection<MutationDetails> mutations, Mutater m) { | ||
if (isEnum) { | ||
return mutations.stream() | ||
.filter(makeMethodFilter(currentClass).negate()) | ||
.collect(Collectors.toList()); | ||
} | ||
return mutations; | ||
|
||
} | ||
|
||
private Predicate<MutationDetails> makeMethodFilter(ClassTree currentClass) { | ||
Location valueOf = Location.location(currentClass.name(), "valueOf", "(Ljava/lang/String;)L" + currentClass.name().asInternalName() + ";"); | ||
Location values = Location.location(currentClass.name(), "values", "()[L" + currentClass.name().asInternalName() + ";"); | ||
|
||
return m -> isInEnumConstructor(m) || m.getId().getLocation().equals(valueOf) || m.getId().getLocation().equals(values); | ||
} | ||
|
||
private boolean isInEnumConstructor(MutationDetails m) { | ||
return m.getMethod().equals("<init>"); | ||
} | ||
|
||
@Override | ||
public void end() { | ||
isEnum = false; | ||
currentClass = null; | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...src/test/java/org/pitest/mutationtest/build/intercept/groovy/GroovyFilterFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.pitest.mutationtest.build.intercept.groovy; | ||
|
||
import org.junit.Test; | ||
import org.pitest.mutationtest.build.InterceptorType; | ||
import org.pitest.mutationtest.build.intercept.exclude.FirstLineInterceptorFactory; | ||
import org.pitest.mutationtest.build.intercept.staticinitializers.StaticInitializerInterceptorFactory; | ||
import org.pitest.mutationtest.engine.gregor.mutators.NullMutateEverything; | ||
import org.pitest.verifier.interceptors.FactoryVerifier; | ||
import org.pitest.verifier.interceptors.InterceptorVerifier; | ||
import org.pitest.verifier.interceptors.VerifierStart; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class GroovyFilterFactoryTest { | ||
@Test | ||
public void isOnChain() { | ||
FactoryVerifier.confirmFactory(new FirstLineInterceptorFactory()) | ||
.isOnChain(); | ||
} | ||
|
||
@Test | ||
public void isOffByDefault() { | ||
FactoryVerifier.confirmFactory(new FirstLineInterceptorFactory()) | ||
.isOffByDefault(); | ||
} | ||
|
||
|
||
@Test | ||
public void featureIsCalledNoFirstLine() { | ||
FactoryVerifier.confirmFactory(new FirstLineInterceptorFactory()) | ||
.featureName().isEqualTo("nofirstline"); | ||
} | ||
|
||
@Test | ||
public void createsFilters() { | ||
FactoryVerifier.confirmFactory(new FirstLineInterceptorFactory()) | ||
.createsInterceptorsOfType(InterceptorType.FILTER); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...-entry/src/test/java/org/pitest/mutationtest/build/intercept/groovy/GroovyFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.pitest.mutationtest.build.intercept.groovy; | ||
|
||
import com.example.coverage.execute.samples.exceptions.CoveredBeforeExceptionTestee; | ||
import org.junit.Test; | ||
import org.pitest.mutationtest.engine.gregor.config.Mutator; | ||
import org.pitest.mutationtest.engine.gregor.mutators.NullMutateEverything; | ||
import org.pitest.util.ResourceFolderByteArraySource; | ||
import org.pitest.verifier.interceptors.InterceptorVerifier; | ||
import org.pitest.verifier.interceptors.VerifierStart; | ||
import org.pitest.verifier.mutants.MutatorVerifierStart; | ||
|
||
public class GroovyFilterTest { | ||
|
||
InterceptorVerifier v = VerifierStart.forInterceptorFactory(new GroovyFilterFactory()) | ||
.usingMutator(new NullMutateEverything()); | ||
|
||
@Test | ||
public void doesNotFilterMutationsInJavaClasses() { | ||
v.forClass(CoveredBeforeExceptionTestee.class) | ||
.forAnyCode() | ||
.mutantsAreGenerated() | ||
.noMutantsAreFiltered() | ||
.verify(); | ||
} | ||
|
||
@Test | ||
public void filtersMutantsInGroovyClasses() { | ||
v.usingResourceFolder("groovy") | ||
.forClass("SomeGroovyCode") | ||
.forAnyCode() | ||
.mutantsAreGenerated() | ||
.allMutantsAreFiltered() | ||
.verify(); | ||
} | ||
|
||
@Test | ||
public void filtersMutantsInGroovyClosures() { | ||
v.usingResourceFolder("groovy") | ||
.forClass("SomeGroovyCode$_mapToString_closure2") | ||
.forAnyCode() | ||
.mutantsAreGenerated() | ||
.allMutantsAreFiltered() | ||
.verify(); | ||
} | ||
} |
Oops, something went wrong.