Skip to content

Commit b3ca174

Browse files
authored
Fixed applying of the root verification rules
Now, when creating the Android report configuration, on Check is immediately set for verification. According to the rules for Android reports, if onCheck is not specified, it is taken as false. Now, to install onCheck, the reports.verify { block is called. if you look at its implementation, you can see that the default value for verify config is null. When a user writes verify { }, according to the current rules, it automatically resets all filters declared in the hierarchy above. The problem was that the onCheck setting took place through a verify block call, which should be filled in by the user, so the filters seem to be erased. Fixes #459 PR #502
1 parent 59c6718 commit b3ca174

File tree

16 files changed

+252
-5
lines changed

16 files changed

+252
-5
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ class BuildCacheRelocationTests {
1515
fun test() {
1616
val cachePath = Files.createTempDirectory("test-gradle-cache-").toFile().canonicalPath
1717

18+
// escape \ symbol for Windows FS
19+
val escapedPath = cachePath.replace("\\", "\\\\")
1820
val cachePatch = """
1921
buildCache {
2022
local {
21-
directory = "$cachePath"
23+
directory = "$escapedPath"
2224
}
2325
}"""
2426

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

+19
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
package kotlinx.kover.gradle.plugin.test.functional.cases
66

77
import kotlinx.kover.gradle.plugin.dsl.*
8+
import kotlinx.kover.gradle.plugin.test.functional.framework.checker.CheckerContext
9+
import kotlinx.kover.gradle.plugin.test.functional.framework.checker.createCheckerContext
810
import kotlinx.kover.gradle.plugin.test.functional.framework.configurator.*
11+
import kotlinx.kover.gradle.plugin.test.functional.framework.runner.buildFromTemplate
12+
import kotlinx.kover.gradle.plugin.test.functional.framework.runner.runWithParams
913
import kotlinx.kover.gradle.plugin.test.functional.framework.starter.*
14+
import org.junit.jupiter.api.Test
15+
import kotlin.test.assertFalse
16+
import kotlin.test.assertTrue
1017

1118
internal class VerificationTests {
1219
@SlicedGeneratedTest(allLanguages = true, allTools = true)
@@ -194,4 +201,16 @@ Rule violated: lines missed count for package 'org.jetbrains.kover.test.function
194201
run("koverVerify")
195202
}
196203

204+
/**
205+
* In the common verify config, rules are declared that always lead to an error.
206+
* Verification of the Android build variant should use these rules and failed.
207+
*/
208+
@Test
209+
fun testAndroidInverseOrder() {
210+
val buildSource = buildFromTemplate("android-common-verify")
211+
val build = buildSource.generate()
212+
val buildResult = build.runWithParams(":app:koverVerifyRelease")
213+
assertFalse(buildResult.isSuccessful)
214+
}
215+
197216
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
plugins {
2+
id ("org.jetbrains.kotlinx.kover")
3+
id ("com.android.application")
4+
id ("org.jetbrains.kotlin.android")
5+
}
6+
7+
android {
8+
namespace = "kotlinx.kover.test.android"
9+
compileSdk = 32
10+
11+
defaultConfig {
12+
applicationId = "kotlinx.kover.test.android"
13+
minSdk = 21
14+
targetSdk = 31
15+
versionCode = 1
16+
versionName = "1.0"
17+
18+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
19+
}
20+
21+
buildTypes {
22+
release {
23+
isMinifyEnabled = true
24+
}
25+
}
26+
compileOptions {
27+
sourceCompatibility = JavaVersion.VERSION_1_8
28+
targetCompatibility = JavaVersion.VERSION_1_8
29+
}
30+
kotlinOptions {
31+
jvmTarget = "1.8"
32+
}
33+
buildFeatures {
34+
viewBinding = true
35+
}
36+
}
37+
38+
dependencies {
39+
implementation("androidx.core:core-ktx:1.8.0")
40+
implementation("androidx.appcompat:appcompat:1.5.0")
41+
implementation("com.google.android.material:material:1.6.1")
42+
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
43+
testImplementation("junit:junit:4.13.2")
44+
}
45+
46+
47+
/*
48+
* Kover configs
49+
*/
50+
51+
koverReport {
52+
verify {
53+
rule {
54+
// always fails
55+
minBound(100)
56+
maxBound(0)
57+
}
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<application android:label="@string/app_name">
5+
<uses-library android:name="com.google.android.things" android:required="false" />
6+
7+
<activity android:name=".MainActivity"
8+
android:exported="true">
9+
<intent-filter>
10+
<action android:name="android.intent.action.MAIN" />
11+
12+
<category android:name="android.intent.category.LAUNCHER" />
13+
</intent-filter>
14+
<!-- Make this the first activity that is displayed when the device boots. -->
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
18+
<category android:name="android.intent.category.HOME" />
19+
<category android:name="android.intent.category.DEFAULT" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package kotlinx.kover.test.android
2+
3+
object DebugUtil {
4+
fun log(message: String) {
5+
println("DEBUG: $message")
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kotlinx.kover.test.android
2+
3+
import android.os.Bundle
4+
import android.app.Activity
5+
6+
class MainActivity : Activity() {
7+
8+
override fun onCreate(savedInstanceState: Bundle?) {
9+
super.onCreate(savedInstanceState)
10+
setContentView(R.layout.activity_main)
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kotlinx.kover.test.android
2+
3+
object Maths {
4+
fun sum(a: Int, b: Int): Int {
5+
DebugUtil.log("invoked sum")
6+
return a + b
7+
}
8+
9+
fun sub(a: Int, b: Int): Int {
10+
DebugUtil.log("invoked sub")
11+
return a - b
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context=".MainActivity">
8+
9+
<TextView
10+
android:id="@+id/main_label"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:layout_marginStart="104dp"
14+
android:layout_marginTop="28dp"
15+
android:text="SERIALIZATION TEST"
16+
android:textSize="20sp"
17+
android:textStyle="bold"
18+
app:layout_constraintStart_toStartOf="parent"
19+
app:layout_constraintTop_toTopOf="parent" />
20+
21+
<EditText
22+
android:id="@+id/encoded_text"
23+
android:layout_width="373dp"
24+
android:layout_height="411dp"
25+
android:layout_marginStart="16dp"
26+
android:layout_marginTop="16dp"
27+
android:editable="false"
28+
android:ems="10"
29+
android:gravity="start|top"
30+
android:inputType="textMultiLine"
31+
android:textAlignment="viewStart"
32+
android:textSize="12sp"
33+
app:layout_constraintStart_toStartOf="parent"
34+
app:layout_constraintTop_toBottomOf="@+id/main_label" />
35+
36+
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="purple_200">#FFBB86FC</color>
4+
<color name="purple_500">#FF6200EE</color>
5+
<color name="purple_700">#FF3700B3</color>
6+
<color name="teal_200">#FF03DAC5</color>
7+
<color name="teal_700">#FF018786</color>
8+
<color name="black">#FF000000</color>
9+
<color name="white">#FFFFFFFF</color>
10+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">Android Test</string>
3+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<resources>
2+
3+
<style name="Theme.App" parent="android:Theme.Material.Light.DarkActionBar" />
4+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kotlinx.kover.test.android
2+
3+
import org.junit.Test
4+
5+
import org.junit.Assert.*
6+
7+
8+
class LocalTests {
9+
@Test
10+
fun testDebugUtils() {
11+
assertEquals(3, Maths.sum(1, 2))
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
plugins {
2+
id("com.android.application") version "7.4.0" apply false
3+
id("com.android.library") version "7.4.0" apply false
4+
id("org.jetbrains.kotlin.android") version "1.8.20" apply false
5+
id("org.jetbrains.kotlinx.kover") version "0.7.1" apply false
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Project-wide Gradle settings.
2+
# IDE (e.g. Android Studio) users:
3+
# Gradle settings configured through the IDE *will override*
4+
# any settings specified in this file.
5+
# For more details on how to configure your build environment visit
6+
# http://www.gradle.org/docs/current/userguide/build_environment.html
7+
# Specifies the JVM arguments used for the daemon process.
8+
# The setting is particularly useful for tweaking memory settings.
9+
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10+
# When configured, Gradle will run in incubating parallel mode.
11+
# This option should only be used with decoupled projects. More details, visit
12+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13+
# org.gradle.parallel=true
14+
# AndroidX package structure to make it clearer which packages are bundled with the
15+
# Android operating system, and which are packaged with your app's APK
16+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
17+
android.useAndroidX=true
18+
# Kotlin code style for this project: "official" or "obsolete":
19+
kotlin.code.style=official
20+
# Enables namespacing of each library's R class so that its R class includes only the
21+
# resources declared in the library itself and none from the library's dependencies,
22+
# thereby reducing the size of the R class for that library
23+
android.nonTransitiveRClass=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pluginManagement {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
gradlePluginPortal()
6+
}
7+
}
8+
9+
dependencyResolutionManagement {
10+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
11+
repositories {
12+
google()
13+
mavenCentral()
14+
gradlePluginPortal()
15+
}
16+
}
17+
18+
rootProject.name = "android_kts"
19+
include(":app")

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/reports/AndroidVariantApplier.kt

-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ internal fun ObjectFactory.androidReports(variant: String, layout: ProjectLayout
8585
onCheck = false
8686
}
8787

88-
reports.verify {
89-
onCheck = false
90-
}
91-
9288
return reports
9389
}
9490

0 commit comments

Comments
 (0)