diff options
Diffstat (limited to 'org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets')
13 files changed, 481 insertions, 0 deletions
diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinCallableReferenceTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinCallableReferenceTarget.kt new file mode 100644 index 00000000..b0240674 --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinCallableReferenceTarget.kt @@ -0,0 +1,33 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +import org.jacoco.core.test.validation.targets.Stubs.nop + +/** + * Test target for callable references. + */ +object KotlinCallableReferenceTarget { + + @JvmStatic + fun main(args: Array<String>) { + + /* + Since Kotlin 1.3.30 + anonymous class generated for callable reference is marked as synthetic + https://youtrack.jetbrains.com/issue/KT-28453 + */ + nop(::main) // assertFullyCovered(0, 0) + + } + +} diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinCoroutineTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinCoroutineTarget.kt new file mode 100644 index 00000000..6a56570f --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinCoroutineTarget.kt @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +import kotlinx.coroutines.runBlocking +import org.jacoco.core.test.validation.targets.Stubs.nop + +/** + * Test target for coroutines. + */ +object KotlinCoroutineTarget { + + private suspend fun suspendingFunction() { // assertEmpty() + anotherSuspendingFunction() // assertFullyCovered() + nop() // assertFullyCovered() + } // assertFullyCovered() + + private suspend fun anotherSuspendingFunction() { + nop() // assertFullyCovered() + } + + @JvmStatic + fun main(args: Array<String>) { + + runBlocking { // assertFullyCovered() + val x = 42 + nop(x) // assertFullyCovered() + suspendingFunction() // assertFullyCovered() + nop(x) // assertFullyCovered() + } // assertFullyCovered() + + } + +} diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDataClassTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDataClassTarget.kt new file mode 100644 index 00000000..2af6fb09 --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDataClassTarget.kt @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Fabian Mastenbroek - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +import org.jacoco.core.test.validation.targets.Stubs.nop + +/** + * This test target is `data class`. + */ +object KotlinDataClassTarget { + + data class DataClass( // assertFullyCovered() + val valNoRead: Int, // assertNotCovered() + val valRead: Int, // assertFullyCovered() + var varNoReadNoWrite: Int, // assertNotCovered() + var varNoWrite: Int, // assertPartlyCovered() + var varNoRead: Int, // assertPartlyCovered() + var varReadWrite: Int // assertFullyCovered() + ) // assertEmpty() + + data class DataClassOverrideNotCovered(val v: Int) { + override fun toString(): String = "" // assertNotCovered() + } + + data class DataClassOverrideCovered(val v: Int) { + override fun toString(): String = "" // assertFullyCovered() + } + + @JvmStatic + fun main(args: Array<String>) { + val d = DataClass(0, 0, 0, 0, 0, 0) + nop(d.valRead) + nop(d.varNoWrite) + d.varNoRead = 1 + nop(d.varReadWrite) + d.varReadWrite = 1 + + DataClassOverrideNotCovered(0) + DataClassOverrideCovered(0).toString() + } +} 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..0a11d7da --- /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, 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 + * + * 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<String>) { + f(a = "a") + f(b = "b") + /* next invocation doesn't use synthetic method: */ + f("a", "b") + + branch(false) + branch(true) + } + +} diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinElvisOperatorTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinElvisOperatorTarget.kt new file mode 100644 index 00000000..5457433b --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinElvisOperatorTarget.kt @@ -0,0 +1,29 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +/** + * Test target for elvis operator. + */ +object KotlinElvisOperatorTarget { + + private fun example(x: String?): String { + return x ?: "" // assertFullyCovered(0, 2) + } + + @JvmStatic + fun main(args: Array<String>) { + example("") + example(null) + } + +} diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinInlineTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinInlineTarget.kt new file mode 100644 index 00000000..e6344f56 --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinInlineTarget.kt @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +import org.jacoco.core.test.validation.targets.Stubs.nop +import org.jacoco.core.test.validation.targets.Stubs.t + +/** + * Test target for `inline` functions. + */ +fun main(args: Array<String>) { + KotlinInlineTarget.main(args) +} + +inline fun inlined_top_level() { + nop() // assertNotCovered() +} + +object KotlinInlineTarget { + + inline fun inlined() { + nop() // assertNotCovered() + } + + @JvmStatic + fun main(args: Array<String>) { + + inlined_top_level() // assertFullyCovered() + + inlined() // assertFullyCovered() + + /* Following inlined method for some reasons doesn't appear in SMAP: */ + assert(t()) // assertPartlyCovered(2, 2) + + } + +} diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinLateinitTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinLateinitTarget.kt new file mode 100644 index 00000000..349a230b --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinLateinitTarget.kt @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Fabian Mastenbroek - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +import org.jacoco.core.test.validation.targets.Stubs.nop + +/** + * This test target is `lateinit` property. + */ +object KotlinLateinitTarget { + private lateinit var x: String + + @JvmStatic + fun main(args: Array<String>) { + x = "" + nop(x) // assertFullyCovered() + } +} diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinNotNullOperatorTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinNotNullOperatorTarget.kt new file mode 100644 index 00000000..91f5420f --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinNotNullOperatorTarget.kt @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +/** + * Test target for not-null assertion operator. + */ +object KotlinNotNullOperatorTarget { + + private fun example(x: String?): Int { + return x!!.length // assertFullyCovered() + } + + @JvmStatic + fun main(args: Array<String>) { + example("") + try { + example(null) + } catch (e: NullPointerException) { + } + } + +} diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinSafeCallOperatorTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinSafeCallOperatorTarget.kt new file mode 100644 index 00000000..d29e5eb3 --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinSafeCallOperatorTarget.kt @@ -0,0 +1,29 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +/** + * Test target for safe call operator. + */ +object KotlinSafeCallOperatorTarget { + + private fun example(x: String?): Int? { + return x?.length // assertFullyCovered(0, 2) + } + + @JvmStatic + fun main(args: Array<String>) { + example("") + example(null) + } + +} diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinSafeCastTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinSafeCastTarget.kt new file mode 100644 index 00000000..ddcc7b05 --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinSafeCastTarget.kt @@ -0,0 +1,29 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +/** + * Test target for "safe" cast operator. + */ +object KotlinSafeCastTarget { + + private fun example(x: Any?): String? { + return x as? String // assertFullyCovered(0, 2) + } + + @JvmStatic + fun main(args: Array<String>) { + example("") + example(1) + } + +} diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinTopLevelFunctionTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinTopLevelFunctionTarget.kt new file mode 100644 index 00000000..e9e5264d --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinTopLevelFunctionTarget.kt @@ -0,0 +1,18 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +/** + * This test target is top level function. + */ +fun main(args: Array<String>) { +} // assertFullyCovered() diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinUnsafeCastOperatorTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinUnsafeCastOperatorTarget.kt new file mode 100644 index 00000000..aa493d73 --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinUnsafeCastOperatorTarget.kt @@ -0,0 +1,28 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +/** + * This test target is "unsafe" cast operator. + */ +object KotlinUnsafeCastOperatorTarget { + + private fun nullable(): String? { + return "" + } + + @JvmStatic + fun main(args: Array<String>) { + nullable() as String // assertFullyCovered() + } + +} 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 new file mode 100644 index 00000000..00ea5e2e --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinWhenExpressionTarget.kt @@ -0,0 +1,81 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +/** + * This test target is `when` expression. + */ +object KotlinWhenExpressionTarget { + + private sealed class Sealed { + object Sealed1 : Sealed() + object Sealed2 : Sealed() + } + + private fun whenSealed(p: Sealed): Int = when (p) { // assertFullyCovered() + is Sealed.Sealed1 -> 1 // assertFullyCovered(0, 2) + is Sealed.Sealed2 -> 2 // assertFullyCovered() + } // assertFullyCovered() + + @Suppress("REDUNDANT_ELSE_IN_WHEN") + private fun whenSealedRedundantElse(p: Sealed): Int = when (p) { // assertFullyCovered() + is Sealed.Sealed1 -> 1 // assertFullyCovered(0, 2) + is Sealed.Sealed2 -> 2 // assertFullyCovered(1, 1) + else -> throw NoWhenBranchMatchedException() // assertNotCovered() + } // assertFullyCovered() + + private enum class Enum { + A, B + } + + private fun whenEnum(p: Enum): Int = when (p) { // assertFullyCovered(0, 2) + Enum.A -> 1 // assertFullyCovered() + Enum.B -> 2 // assertFullyCovered() + } // assertFullyCovered() + + @Suppress("REDUNDANT_ELSE_IN_WHEN") + private fun whenEnumRedundantElse(p: Enum): Int = when (p) { // assertFullyCovered(1, 2) + Enum.A -> 1 // assertFullyCovered() + Enum.B -> 2 // assertFullyCovered() + else -> throw NoWhenBranchMatchedException() // assertNotCovered() + } // assertFullyCovered() + + private fun whenString(p: String): Int = when (p) { // assertFullyCovered(0, 5) + "a" -> 1 // assertFullyCovered() + "b" -> 2 // assertFullyCovered() + "\u0000a" -> 3 // assertFullyCovered() + "\u0000b" -> 4 // assertFullyCovered() + else -> 5 // assertFullyCovered() + } // assertFullyCovered() + + @JvmStatic + fun main(args: Array<String>) { + whenSealed(Sealed.Sealed1) + whenSealed(Sealed.Sealed2) + + whenSealedRedundantElse(Sealed.Sealed1) + whenSealedRedundantElse(Sealed.Sealed2) + + whenEnum(Enum.A) + whenEnum(Enum.B) + + whenEnumRedundantElse(Enum.A) + whenEnumRedundantElse(Enum.B) + + whenString("") + whenString("a") + whenString("b") + whenString("\u0000a") + whenString("\u0000b") + } + +} |