aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core.test.validation.kotlin/src
diff options
context:
space:
mode:
authorEvgeny Mandrikov <138671+Godin@users.noreply.github.com>2019-07-26 14:18:30 +0200
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2019-07-26 14:18:30 +0200
commit7a32ae362997d20141f59ceb119563287c2485e9 (patch)
tree3adddeab0dd62c54f945ffa47b5549a1c77d7542 /org.jacoco.core.test.validation.kotlin/src
parent86b27dc25f3be9acca365da49af49e340f04efbf (diff)
downloadjacoco-7a32ae362997d20141f59ceb119563287c2485e9.tar.gz
Add validation test for Kotlin control structures (#911)
Diffstat (limited to 'org.jacoco.core.test.validation.kotlin/src')
-rw-r--r--org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinControlStructuresTest.java26
-rw-r--r--org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinControlStructuresTarget.kt164
2 files changed, 190 insertions, 0 deletions
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<Any>()) { // 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<String>) {
+ unconditionalExecution()
+ missedIfBlock()
+ executedIfBlock()
+ missedWhileBlock()
+ executedWhileBlock()
+ executedDoWhileBlock()
+ missedForBlock()
+ executedForBlock()
+ missedForEachBlock()
+ executedForEachBlock()
+ whenExpression()
+ breakStatement()
+ continueStatement()
+ implicitReturn()
+ explicitReturn()
+ }
+
+}