aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinDefaultArgumentsFilterTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinDefaultArgumentsFilterTest.java')
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinDefaultArgumentsFilterTest.java134
1 files changed, 129 insertions, 5 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinDefaultArgumentsFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinDefaultArgumentsFilterTest.java
index 8dfa765e..2e33173c 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinDefaultArgumentsFilterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/KotlinDefaultArgumentsFilterTest.java
@@ -1,9 +1,10 @@
/*******************************************************************************
- * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
+ * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors
+ * This program and the accompanying materials are made available under
+ * the terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Evgeny Mandrikov - initial API and implementation
@@ -95,4 +96,127 @@ public class KotlinDefaultArgumentsFilterTest extends FilterTestBase {
assertIgnored();
}
+ /**
+ * <pre>
+ * open class Open {
+ * open fun foo(a: Int = 42) {
+ * }
+ * }
+ * </pre>
+ */
+ @Test
+ public void should_filter_open_functions() {
+ final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
+ Opcodes.ACC_SYNTHETIC, "foo$default",
+ "(LOpen;IILjava/lang/Object;)V", null, null);
+ context.classAnnotations
+ .add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);
+ {
+ m.visitVarInsn(Opcodes.ALOAD, 3);
+ final Label label = new Label();
+ m.visitJumpInsn(Opcodes.IFNULL, label);
+ m.visitTypeInsn(Opcodes.NEW,
+ "java/lang/UnsupportedOperationException");
+ m.visitInsn(Opcodes.DUP);
+ m.visitLdcInsn(
+ "Super calls with default arguments not supported in this target, function: foo");
+ m.visitMethodInsn(Opcodes.INVOKESPECIAL,
+ "java/lang/UnsupportedOperationException", "<init>",
+ "(Ljava/lang/String;)V", false);
+ m.visitInsn(Opcodes.ATHROW);
+ m.visitLabel(label);
+ }
+ {
+ m.visitVarInsn(Opcodes.ILOAD, 2);
+ m.visitInsn(Opcodes.ICONST_1);
+ m.visitInsn(Opcodes.IAND);
+ final Label label = new Label();
+ m.visitJumpInsn(Opcodes.IFEQ, label);
+ // default argument
+ m.visitLdcInsn(Integer.valueOf(42));
+ m.visitVarInsn(Opcodes.ISTORE, 1);
+ m.visitLabel(label);
+
+ m.visitVarInsn(Opcodes.ALOAD, 0);
+ m.visitVarInsn(Opcodes.ILOAD, 1);
+ m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Open", "foo", "(I)V",
+ false);
+ m.visitInsn(Opcodes.RETURN);
+ }
+
+ filter.filter(m, context, output);
+
+ assertIgnored(
+ new Range(m.instructions.getFirst(), m.instructions.get(6)),
+ new Range(m.instructions.get(11), m.instructions.get(11)));
+ }
+
+ /**
+ * <pre>
+ * class C(a: Int = 42)
+ * </pre>
+ */
+ @Test
+ public void should_filter_constructors() {
+ final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
+ Opcodes.ACC_SYNTHETIC, "<init>",
+ "(IILkotlin/jvm/internal/DefaultConstructorMarker;)V", null,
+ null);
+ context.classAnnotations
+ .add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);
+
+ m.visitVarInsn(Opcodes.ILOAD, 2);
+ m.visitInsn(Opcodes.ICONST_1);
+ m.visitInsn(Opcodes.IAND);
+ Label label = new Label();
+ m.visitJumpInsn(Opcodes.IFEQ, label);
+ // default argument
+ m.visitLdcInsn(Integer.valueOf(42));
+ m.visitVarInsn(Opcodes.ISTORE, 1);
+ m.visitLabel(label);
+ m.visitVarInsn(Opcodes.ALOAD, 0);
+ m.visitVarInsn(Opcodes.ILOAD, 1);
+ m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Owner", "<init>", "(I)V",
+ false);
+ m.visitInsn(Opcodes.RETURN);
+
+ filter.filter(m, context, output);
+
+ assertIgnored(new Range(m.instructions.get(3), m.instructions.get(3)));
+ }
+
+ /**
+ * <pre>
+ * data class C(val x: Long = 42)
+ * </pre>
+ */
+ @Test
+ public void should_filter_methods_with_parameters_that_consume_two_slots() {
+ final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
+ Opcodes.ACC_SYNTHETIC, "<init>",
+ "(JILkotlin/jvm/internal/DefaultConstructorMarker;)V", null,
+ null);
+ context.classAnnotations
+ .add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);
+
+ m.visitVarInsn(Opcodes.ILOAD, 3);
+ m.visitInsn(Opcodes.ICONST_1);
+ m.visitInsn(Opcodes.IAND);
+ final Label label = new Label();
+ m.visitJumpInsn(Opcodes.IFEQ, label);
+ // default argument
+ m.visitLdcInsn(Integer.valueOf(42));
+ m.visitVarInsn(Opcodes.ISTORE, 1);
+ m.visitLabel(label);
+ m.visitVarInsn(Opcodes.ALOAD, 0);
+ m.visitVarInsn(Opcodes.ILOAD, 1);
+ m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Owner", "<init>", "(J)V",
+ false);
+ m.visitInsn(Opcodes.RETURN);
+
+ filter.filter(m, context, output);
+
+ assertIgnored(new Range(m.instructions.get(3), m.instructions.get(3)));
+ }
+
}