Skip to content

Commit 325bd50

Browse files
authored
Added tests on try-finally and try-with-resources
Resolves #628 PR #639
1 parent 06f4de4 commit 325bd50

File tree

9 files changed

+54
-9
lines changed

9 files changed

+54
-9
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22

3-
intellij-coverage = "1.0.755"
3+
intellij-coverage = "1.0.760"
44
junit = "5.9.0"
55
kotlinx-bcv = "0.13.2"
66
kotlinx-dokka = "1.8.10"

kover-gradle-plugin/api/kover-gradle-plugin.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ public abstract interface class kotlinx/kover/gradle/plugin/dsl/KoverVerifyTaskC
297297
public final class kotlinx/kover/gradle/plugin/dsl/KoverVersions {
298298
public static final field INSTANCE Lkotlinx/kover/gradle/plugin/dsl/KoverVersions;
299299
public static final field JACOCO_TOOL_DEFAULT_VERSION Ljava/lang/String;
300-
public static final field KOVER_TOOL_VERSION Ljava/lang/String;
301300
public static final field MINIMUM_GRADLE_VERSION Ljava/lang/String;
302301
public final fun getVersion ()Ljava/lang/String;
303302
}

kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/CountersValueTests.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ internal class CountersValueTests {
3434

3535
// Instruction counters - value may depend on Kotlin compiler version
3636
methodCounter("org.jetbrains.Different", "helloWorld").assertTotal(4)
37+
38+
// Test on try with resources in Java
39+
methodCounter("org.jetbrains.TryWithResources", "test", "LINE").assertFullyCovered()
40+
methodCounter("org.jetbrains.TryWithResources", "test", "BRANCH").assertFullyCovered()
41+
42+
methodCounter("org.jetbrains.TryFinally", "testWithCatch", "LINE").assertCovered(2, 1)
3743
}
3844
}
3945

kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/checker/Checker.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ private class CounterImpl(
512512

513513
override fun assertFullyCovered() {
514514
assertNotNull(values, "Counter '$symbol' with type '$type' is absent so fully covered can't be checked")
515+
516+
// skip empty branches
517+
if (values.covered == 0 && values.missed == 0) return
518+
515519
assertTrue(values.covered > 0, "Counter '$symbol' with type '$type' isn't fully covered")
516520
assertEquals(0, values.missed, "Counter '$symbol' with type '$type' isn't fully covered")
517521
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.jetbrains;
2+
3+
public final class TryFinally {
4+
5+
private TryFinally() {}
6+
7+
public static void testWithCatch(Runnable runnable) {
8+
try {
9+
runnable.run(); // covered
10+
} catch (RuntimeException e) {
11+
System.out.println("Error"); // missed
12+
} finally {
13+
System.out.println("Finally"); // covered
14+
}
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.jetbrains;
2+
3+
public final class TryWithResources {
4+
5+
private TryWithResources() {}
6+
7+
public static void test() throws Exception {
8+
try (AutoCloseable ignored = generate()) {
9+
System.out.println("action");
10+
}
11+
}
12+
13+
private static AutoCloseable generate() {
14+
return () -> System.out.println("closed");
15+
}
16+
}

kover-gradle-plugin/src/functionalTest/templates/builds/counters/src/test/kotlin/TestClass.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@ class TestClass {
2424
UsedObjectWithFun.toString()
2525
UsedObjectFun.hello()
2626
}
27+
28+
@Test
29+
fun testTryWithResources() {
30+
TryWithResources.test()
31+
}
32+
@Test
33+
fun testTryFinally() {
34+
TryFinally.testWithCatch {}
35+
}
2736
}

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/KoverVersions.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ public object KoverVersions {
1414
*/
1515
public const val MINIMUM_GRADLE_VERSION = "6.8"
1616

17-
/**
18-
* Kover coverage tool version.
19-
*/
20-
public const val KOVER_TOOL_VERSION = "1.0.755"
21-
2217
/**
2318
* JaCoCo coverage tool version used by default.
2419
*/

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tools/CoverageTool.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
package kotlinx.kover.gradle.plugin.tools
66

7+
import kotlinx.kover.features.jvm.KoverFeatures
78
import kotlinx.kover.features.jvm.RuleViolations
89
import kotlinx.kover.gradle.plugin.commons.*
910
import kotlinx.kover.gradle.plugin.commons.VerificationRule
1011
import kotlinx.kover.gradle.plugin.dsl.*
11-
import kotlinx.kover.gradle.plugin.dsl.KoverVersions.KOVER_TOOL_VERSION
1212
import kotlinx.kover.gradle.plugin.dsl.internal.KoverProjectExtensionImpl
1313
import kotlinx.kover.gradle.plugin.tools.jacoco.JacocoTool
1414
import kotlinx.kover.gradle.plugin.tools.kover.KoverTool
@@ -48,7 +48,7 @@ internal sealed class CoverageToolVariant(
4848
}
4949

5050
internal class KoverToolVariant(version: String): CoverageToolVariant(CoverageToolVendor.KOVER, version)
51-
internal object KoverToolBuiltin: CoverageToolVariant(CoverageToolVendor.KOVER, KOVER_TOOL_VERSION)
51+
internal object KoverToolBuiltin: CoverageToolVariant(CoverageToolVendor.KOVER, KoverFeatures.version)
5252

5353
internal class JacocoToolVariant(version: String): CoverageToolVariant(CoverageToolVendor.JACOCO, version)
5454

0 commit comments

Comments
 (0)