Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.
Open
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
67 changes: 36 additions & 31 deletions pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<kotlin.version>1.3.61</kotlin.version>
<assertj.version>2.8.0</assertj.version>
<junit.version>4.13.1</junit.version>
<mockito.version>2.7.6</mockito.version>
<pitest.version>1.4.1</pitest.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<kotlin.version>1.4.10</kotlin.version>
<assertj.version>3.9.0</assertj.version>
<mockito.version>3.6.0</mockito.version>
<pitest.version>1.5.2</pitest.version>
<junit-jupiter.version>5.6.3</junit-jupiter.version>
</properties>

<scm>
Expand Down Expand Up @@ -114,12 +114,26 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest</artifactId>
Expand All @@ -134,17 +148,9 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>


<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
Expand Down Expand Up @@ -172,15 +178,18 @@
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
Expand All @@ -195,33 +204,29 @@
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.2</version>
<version>2.5.3</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>1.9.4</version>
<version>1.11.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<version>3.2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0-M1</version>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<version>3.8.1</version>
<executions>
<execution>
<id>compile</id>
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/org/pitest/kotlin/KotlinInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class KotlinInterceptor implements MutationInterceptor {
private ClassTree currentClass;
private boolean isKotlinClass;


private static final boolean DEBUG = false;

private static final Slot<AbstractInsnNode> MUTATED_INSTRUCTION = Slot.create(AbstractInsnNode.class);
Expand All @@ -52,7 +51,7 @@ public class KotlinInterceptor implements MutationInterceptor {
.or(nullCast())
.or(safeNullCallOrElvis())
.or(safeCast())
.then(containMutation(FOUND))
.then(containMutation())
.zeroOrMore(QueryStart.match(anyInstruction()))
.compile(QueryParams.params(AbstractInsnNode.class)
.withIgnores(notAnInstruction())
Expand All @@ -63,7 +62,7 @@ private static SequenceQuery<AbstractInsnNode> nullCast() {
return QueryStart
.any(AbstractInsnNode.class)
.then(opCode(Opcodes.IFNONNULL).and(mutationPoint()))
.then(methodCallTo(ClassName.fromString("kotlin/jvm/internal/Intrinsics"), "throwNpe").and(mutationPoint()));
.then(methodCallTo(ClassName.fromString("kotlin/jvm/internal/Intrinsics"), "throwJavaNpe").and(mutationPoint()));
}

private static SequenceQuery<AbstractInsnNode> safeCast() {
Expand Down Expand Up @@ -144,9 +143,7 @@ public InterceptorType type() {
public void begin(ClassTree clazz) {
currentClass = clazz;
isKotlinClass = clazz.annotations().stream()
.filter(annotationNode -> annotationNode.desc.equals("Lkotlin/Metadata;"))
.findFirst()
.isPresent();
.anyMatch(annotationNode -> annotationNode.desc.equals("Lkotlin/Metadata;"));
}

@Override
Expand All @@ -172,8 +169,8 @@ private static Match<AbstractInsnNode> mutationPoint() {
return recordTarget(MUTATED_INSTRUCTION.read(), FOUND.write());
}

private static Match<AbstractInsnNode> containMutation(final Slot<Boolean> found) {
return (context, node) -> context.retrieve(found.read()).isPresent();
private static Match<AbstractInsnNode> containMutation() {
return (context, node) -> context.retrieve(KotlinInterceptor.FOUND.read()).isPresent();
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/test/kotlin/org/pitest/kotlin/KotlinSupportTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.pitest.kotlin

import com.example.NotDestructuringBecauseIAmJava
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
import org.pitest.mutationtest.build.InterceptorType
import org.pitest.mutationtest.build.intercept.javafeatures.FilterTester
import org.pitest.mutationtest.engine.gregor.mutators.NullMutateEverything
Expand All @@ -12,7 +12,6 @@ class KotlinSupportTest {
private val testee = KotlinInterceptor()
private val verifier = FilterTester("", testee, NullMutateEverything.asList())


@Test
fun `declares type as filter`() {
assertThat(testee.type()).isEqualTo(InterceptorType.FILTER)
Expand All @@ -34,9 +33,8 @@ class KotlinSupportTest {
}

@Test
fun `filters mutations to !! null casts`() {
// condtional and intrinsic method call
verifier.assertFiltersMutationAtNLocations(2, HasNullCast::class.java)
fun `does not filter mutations to !! null casts as it throws the java NPE`() {
verifier.assertFiltersMutationAtNLocations(0, HasNullCast::class.java)
}

@Test
Expand Down Expand Up @@ -162,4 +160,4 @@ class HasSafeCast {

interface LongReturn {
fun getALong() : Long
}
}