diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinWhenExpressionTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinWhenExpressionTarget.kt index 882bac63af..13f7e20d1e 100644 --- a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinWhenExpressionTarget.kt +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinWhenExpressionTarget.kt @@ -50,23 +50,27 @@ object KotlinWhenExpressionTarget { else -> throw NoWhenBranchMatchedException() // assertNotCovered() } // assertFullyCovered() - private fun whenString(p: String): Int = when (p) { // assertFullyCovered(0, 5) + private fun whenString(p: String): Int = when (p) { // assertFullyCovered(0, 7) "a" -> 1 // assertFullyCovered() "b" -> 2 // assertFullyCovered() - "\u0000a" -> 3 // assertFullyCovered() - "\u0000b" -> 4 // assertFullyCovered() - else -> 5 // assertFullyCovered() + "c" -> 3 // assertFullyCovered() + "\u0000a" -> 4 // assertFullyCovered() + "\u0000b" -> 5 // assertFullyCovered() + "\u0000c" -> 6 // assertFullyCovered() + else -> 7 // assertFullyCovered() } // assertFullyCovered() /** * Unlike [whenString] * in this example first case is the only case with biggest hashCode value. */ - private fun whenStringBiggestHashCodeFirst(p: String): Int = when (p) { // assertFullyCovered(0, 4) - "b" -> 1 // assertFullyCovered() - "a" -> 2 // assertFullyCovered() - "\u0000a" -> 3 // assertFullyCovered() - else -> 4 // assertFullyCovered() + private fun whenStringBiggestHashCodeFirst(p: String): Int = when (p) { // assertFullyCovered(0, 6) + "c" -> 1 // assertFullyCovered() + "b" -> 2 // assertFullyCovered() + "\u0000b" -> 3 // assertFullyCovered() + "a" -> 4 // assertFullyCovered() + "\u0000a" -> 5 // assertFullyCovered() + else -> 6 // assertFullyCovered() } // assertFullyCovered() @JvmStatic @@ -86,13 +90,17 @@ object KotlinWhenExpressionTarget { whenString("") whenString("a") whenString("b") + whenString("c") whenString("\u0000a") whenString("\u0000b") + whenString("\u0000c") whenStringBiggestHashCodeFirst("") whenStringBiggestHashCodeFirst("a") whenStringBiggestHashCodeFirst("b") + whenStringBiggestHashCodeFirst("c") whenStringBiggestHashCodeFirst("\u0000a") + whenStringBiggestHashCodeFirst("\u0000b") } } diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchEcjFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchFilterTest.java similarity index 59% rename from org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchEcjFilterTest.java rename to org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchFilterTest.java index 79c353a093..44bb10f150 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchEcjFilterTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchFilterTest.java @@ -23,11 +23,11 @@ import org.objectweb.asm.tree.MethodNode; /** - * Unit tests for {@link StringSwitchEcjFilter}. + * Unit tests for {@link StringSwitchFilter}. */ -public class StringSwitchEcjFilterTest extends FilterTestBase { +public class StringSwitchFilterTest extends FilterTestBase { - private final IFilter filter = new StringSwitchEcjFilter(); + private final IFilter filter = new StringSwitchFilter(); @Test public void should_filter() { @@ -156,6 +156,119 @@ public void should_filter_when_default_is_first() { assertIgnored(new Range(switchNode.getNext(), expectedToInclusive)); } + /** + *
+ * fun example(p: String) { + * when (p) { + * "a" -> return + * "\u0000a" -> return + * "b" -> return + * "\u0000b" -> return + * "c" -> return + * "\u0000c" -> return + * } + * } + *+ */ + @Test + public void should_filter_Kotlin_1_5() { + final Set
switch
statement
- * with a String
.
+ * with a String
and by Kotlin compiler 1.5 and above for a
+ * when
expression with a String
.
*/
-public final class StringSwitchEcjFilter implements IFilter {
+public final class StringSwitchFilter implements IFilter {
public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
@@ -42,7 +43,8 @@ private static class Matcher extends AbstractMatcher {
public void match(final AbstractInsnNode start,
final IFilterOutput output) {
- if (Opcodes.ASTORE != start.getOpcode()) {
+ if (start.getOpcode() != /* ECJ */ Opcodes.ASTORE
+ && start.getOpcode() != /* Kotlin */ Opcodes.ALOAD) {
return;
}
cursor = start;
diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html
index 15dfe2c732..2f8ab6fcbc 100644
--- a/org.jacoco.doc/docroot/doc/changes.html
+++ b/org.jacoco.doc/docroot/doc/changes.html
@@ -39,8 +39,12 @@ lateinit
property is filtered out during generation of report
(GitHub #1166).when
expressions on kotlin.String
values
+ when
expressions on kotlin.String
values
+ is filtered out during generation of report
+ (GitHub #1172).when
expressions on kotlin.String
values
(GitHub #1156).