From 78b28dc8463c301b207c60f0394251d4f2ae9aba Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Tue, 27 Nov 2018 13:16:14 +0100 Subject: Report code coverage correctly for Kotlin methods with default arguments (#774) --- .../kotlin/KotlinDefaultArgumentsTest.java | 26 ++++++++++++++++ .../kotlin/targets/KotlinDefaultArgumentsTarget.kt | 36 ++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinDefaultArgumentsTest.java create mode 100644 org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDefaultArgumentsTarget.kt (limited to 'org.jacoco.core.test.validation.kotlin') diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinDefaultArgumentsTest.java b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinDefaultArgumentsTest.java new file mode 100644 index 00000000..4199cf7c --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinDefaultArgumentsTest.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2009, 2018 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 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin; + +import org.jacoco.core.test.validation.ValidationTestBase; +import org.jacoco.core.test.validation.kotlin.targets.KotlinDefaultArgumentsTarget; + +/** + * Test of functions with default arguments. + */ +public class KotlinDefaultArgumentsTest extends ValidationTestBase { + + public KotlinDefaultArgumentsTest() { + super(KotlinDefaultArgumentsTarget.class); + } + +} diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDefaultArgumentsTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDefaultArgumentsTarget.kt new file mode 100644 index 00000000..6943f206 --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDefaultArgumentsTarget.kt @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2009, 2018 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 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +/** + * Test target for functions with default arguments. + */ +object KotlinDefaultArgumentsTarget { + + private fun f(a: String = "a", b: String = "b") { // assertFullyCovered(0, 0) + } + + private fun branch(a: Boolean, b: String = if (a) "a" else "b") { // assertFullyCovered(0, 2) + } + + @JvmStatic + fun main(args: Array) { + f(a = "a") + f(b = "b") + /* next invocation doesn't use synthetic method: */ + f("a", "b") + + branch(false) + branch(true) + } + +} -- cgit v1.2.3