From 7a32ae362997d20141f59ceb119563287c2485e9 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov <138671+Godin@users.noreply.github.com> Date: Fri, 26 Jul 2019 14:18:30 +0200 Subject: Add validation test for Kotlin control structures (#911) --- .../kotlin/KotlinControlStructuresTest.java | 26 ++++ .../targets/KotlinControlStructuresTarget.kt | 164 +++++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinControlStructuresTest.java create mode 100644 org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinControlStructuresTarget.kt diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinControlStructuresTest.java b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinControlStructuresTest.java new file mode 100644 index 00000000..4dab4712 --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinControlStructuresTest.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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; + +import org.jacoco.core.test.validation.ValidationTestBase; +import org.jacoco.core.test.validation.kotlin.targets.KotlinControlStructuresTarget; + +/** + * Tests of Kotlin control structures. + */ +public class KotlinControlStructuresTest extends ValidationTestBase { + + public KotlinControlStructuresTest() { + super(KotlinControlStructuresTarget.class); + } + +} diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinControlStructuresTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinControlStructuresTarget.kt new file mode 100644 index 00000000..3c421f3b --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinControlStructuresTarget.kt @@ -0,0 +1,164 @@ +/******************************************************************************* + * 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.* + +/** + * Test target for Kotlin control structures. + */ +object KotlinControlStructuresTarget { + + private fun unconditionalExecution() { + + nop() // assertFullyCovered() + + } + + private fun missedIfBlock() { + + if (f()) { // assertFullyCovered(1, 1) + nop() // assertNotCovered() + } else { + nop() // assertFullyCovered() + } + + } + + private fun executedIfBlock() { + + if (t()) { // assertFullyCovered(1, 1) + nop() // assertFullyCovered() + } else { + nop() // assertNotCovered() + } + + } + + private fun missedWhileBlock() { + + while (f()) { // assertPartlyCovered(1, 1) + nop() // assertNotCovered() + } + + } + + private fun executedWhileBlock() { + + var i = 0 + while (i++ < 3) { // assertFullyCovered(0, 2) + nop() // assertFullyCovered() + } + + } + + private fun executedDoWhileBlock() { + + do { + nop() // assertFullyCovered() + } while (f()) // assertFullyCovered(1, 1) + + } + + private fun missedForBlock() { + + for (j in 0..-1) { // assertPartlyCovered(1, 1) + nop() // assertNotCovered() + } + + } + + private fun executedForBlock() { + + for (j in 0..0) { // assertFullyCovered(0, 2) + nop() // assertFullyCovered() + } + + } + + private fun missedForEachBlock() { + + for (o in emptyList()) { // assertPartlyCovered(1, 1) + nop(o) // assertNotCovered() + } + + } + + private fun executedForEachBlock() { + + for (o in setOf(Any())) { // assertFullyCovered(0,2) + nop(o) // assertFullyCovered() + } + + } + + private fun whenExpression() { + + when (i2()) { // assertFullyCovered(2, 1) + 1 -> nop() // assertNotCovered() + 2 -> nop() // assertFullyCovered() + else -> nop() // assertNotCovered() + } + + } + + private fun breakStatement() { + + while (true) { + if (t()) { + break // assertFullyCovered() + } + nop() // assertNotCovered() + } + + } + + private fun continueStatement() { + + for (j in 0..0) { + if (t()) { + continue // assertFullyCovered() + } + nop() // assertNotCovered() + } + + } + + private fun implicitReturn() { + } // assertFullyCovered() + + private fun explicitReturn() { + + return // assertFullyCovered() + + } // assertEmpty() + + @JvmStatic + fun main(args: Array) { + unconditionalExecution() + missedIfBlock() + executedIfBlock() + missedWhileBlock() + executedWhileBlock() + executedDoWhileBlock() + missedForBlock() + executedForBlock() + missedForEachBlock() + executedForEachBlock() + whenExpression() + breakStatement() + continueStatement() + implicitReturn() + explicitReturn() + } + +} -- cgit v1.2.3