aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core.test/src/org/jacoco/core
diff options
context:
space:
mode:
authorEvgeny Mandrikov <138671+Godin@users.noreply.github.com>2021-04-08 11:30:06 +0200
committerGitHub <noreply@github.com>2021-04-08 11:30:06 +0200
commitb68fe1a0a7fb86f12cda689ec473fd6633699b55 (patch)
tree7a6cbfe736fdeadecbfd147ea63cf94160af1dd5 /org.jacoco.core.test/src/org/jacoco/core
parent9a88237cc399ecd5ba149c56de56130bf99d0385 (diff)
downloadjacoco-b68fe1a0a7fb86f12cda689ec473fd6633699b55.tar.gz
Update filter for Kotlin 1.5 when-expressions with String (#1172)
Diffstat (limited to 'org.jacoco.core.test/src/org/jacoco/core')
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchFilterTest.java (renamed from org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/StringSwitchEcjFilterTest.java)119
1 files changed, 116 insertions, 3 deletions
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
index 79c353a0..44bb10f1 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.AbstractInsnNode;
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 class StringSwitchEcjFilterTest extends FilterTestBase {
assertIgnored(new Range(switchNode.getNext(), expectedToInclusive));
}
+ /**
+ * <pre>
+ * fun example(p: String) {
+ * when (p) {
+ * "a" -> return
+ * "\u0000a" -> return
+ * "b" -> return
+ * "\u0000b" -> return
+ * "c" -> return
+ * "\u0000c" -> return
+ * }
+ * }
+ * </pre>
+ */
+ @Test
+ public void should_filter_Kotlin_1_5() {
+ final Set<AbstractInsnNode> expectedNewTargets = new HashSet<AbstractInsnNode>();
+
+ final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0,
+ "example", "()V", null, null);
+
+ final Label h1 = new Label();
+ final Label h2 = new Label();
+ final Label h3 = new Label();
+ final Label defaultCase = new Label();
+ final Label case1 = new Label();
+ final Label case2 = new Label();
+ final Label case3 = new Label();
+ final Label case4 = new Label();
+ final Label case5 = new Label();
+ final Label case6 = new Label();
+
+ m.visitVarInsn(Opcodes.ALOAD, 1);
+ m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode",
+ "()I", false);
+ m.visitTableSwitchInsn(97, 99, defaultCase, h1, h2, h3);
+
+ m.visitLabel(h1);
+ final AbstractInsnNode expectedFromInclusive = m.instructions.getLast();
+ m.visitVarInsn(Opcodes.ALOAD, 1);
+ m.visitLdcInsn("a");
+ m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
+ "(Ljava/lang/Object;)Z", false);
+ m.visitJumpInsn(Opcodes.IFNE, case1);
+
+ m.visitVarInsn(Opcodes.ALOAD, 1);
+ m.visitLdcInsn("\u0000a");
+ m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
+ "(Ljava/lang/Object;)Z", false);
+ m.visitJumpInsn(Opcodes.IFNE, case2);
+
+ m.visitJumpInsn(Opcodes.GOTO, defaultCase);
+
+ m.visitLabel(h2);
+ m.visitVarInsn(Opcodes.ALOAD, 1);
+ m.visitLdcInsn("b");
+ m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
+ "(Ljava/lang/Object;)Z", false);
+ m.visitJumpInsn(Opcodes.IFNE, case3);
+
+ m.visitVarInsn(Opcodes.ALOAD, 1);
+ m.visitLdcInsn("\u0000b");
+ m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
+ "(Ljava/lang/Object;)Z", false);
+ m.visitJumpInsn(Opcodes.IFNE, case4);
+
+ m.visitJumpInsn(Opcodes.GOTO, defaultCase);
+
+ m.visitLabel(h3);
+ m.visitVarInsn(Opcodes.ALOAD, 1);
+ m.visitLdcInsn("c");
+ m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
+ "(Ljava/lang/Object;)Z", false);
+ m.visitJumpInsn(Opcodes.IFNE, case5);
+
+ m.visitVarInsn(Opcodes.ALOAD, 1);
+ m.visitLdcInsn("\u0000c");
+ m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
+ "(Ljava/lang/Object;)Z", false);
+ m.visitJumpInsn(Opcodes.IFNE, case6);
+
+ m.visitJumpInsn(Opcodes.GOTO, defaultCase);
+ final AbstractInsnNode expectedToInclusive = m.instructions.getLast();
+
+ m.visitLabel(case1);
+ m.visitInsn(Opcodes.RETURN);
+ expectedNewTargets.add(m.instructions.getLast());
+ m.visitLabel(case2);
+ m.visitInsn(Opcodes.RETURN);
+ expectedNewTargets.add(m.instructions.getLast());
+ m.visitLabel(case3);
+ m.visitInsn(Opcodes.RETURN);
+ expectedNewTargets.add(m.instructions.getLast());
+ m.visitLabel(case4);
+ m.visitInsn(Opcodes.RETURN);
+ expectedNewTargets.add(m.instructions.getLast());
+ m.visitLabel(case5);
+ m.visitInsn(Opcodes.RETURN);
+ expectedNewTargets.add(m.instructions.getLast());
+ m.visitLabel(case6);
+ m.visitInsn(Opcodes.RETURN);
+ expectedNewTargets.add(m.instructions.getLast());
+ m.visitLabel(defaultCase);
+ m.visitInsn(Opcodes.RETURN);
+ expectedNewTargets.add(m.instructions.getLast());
+
+ filter.filter(m, context, output);
+
+ assertIgnored(new Range(expectedFromInclusive, expectedToInclusive));
+ assertReplacedBranches(expectedFromInclusive.getPrevious(),
+ expectedNewTargets);
+ }
+
@Test
public void should_not_filter_empty_lookup_switch() {
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0,