Skip to content

Commit

Permalink
Inverted the flags for disabling instrumentation of test tasks
Browse files Browse the repository at this point in the history
The name `IsEnabled` is misleading in that it seems that if you wrote `IsEnabled = true` instrumentation should work anyway.
`isDisabled` guarantees that if you assigned it `true`, then the task instrumentation will definitely not happen. However, this does not guarantee instrumentation if the value is `false`.
  • Loading branch information
shanshin committed Dec 22, 2021
1 parent c6e8c5f commit 06932b4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ For example, to configure a standard test task for Kotlin/JVM named `test`, you
```kotlin
tasks.test {
extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) {
isEnabled = true
isDisabled = false
binaryReportFile.set(file("$buildDir/custom/result.bin"))
includes = listOf("com.example.*")
excludes = listOf("com.example.subpackage.*")
Expand All @@ -131,7 +131,7 @@ tasks.test {
```groovy
tasks.test {
kover {
enabled = true
disabled = false
binaryReportFile.set(file("$buildDir/custom/result.bin"))
includes = ['com.example.*']
excludes = ['com.example.subpackage.*']
Expand All @@ -154,7 +154,7 @@ android {
unitTests.all {
if (it.name == "testDebugUnitTest") {
extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) {
isEnabled = true
isDisabled = false
binaryReportFile.set(file("$buildDir/custom/debug-report.bin"))
includes = listOf("com.example.*")
excludes = listOf("com.example.subpackage.*")
Expand All @@ -178,7 +178,7 @@ android {
unitTests.all {
if (name == "testDebugUnitTest") {
kover {
enabled = true
disabled = false
binaryReportFile.set(file("$buildDir/custom/debug-report.bin"))
includes = ['com.example.*']
excludes = ['com.example.subpackage.*']
Expand Down Expand Up @@ -298,7 +298,7 @@ In the module in which the plugin is applied, you need to add code:

```kotlin
kover {
isEnabled = true // false to disable instrumentation of all test tasks in all modules
isDisabled = false // true to disable instrumentation of all test tasks in all modules
coverageEngine.set(kotlinx.kover.api.CoverageEngine.INTELLIJ) // change instrumentation agent and reporter
intellijEngineVersion.set("1.0.640") // change version of IntelliJ agent and reporter
jacocoEngineVersion.set("0.8.7") // change version of JaCoCo agent and reporter
Expand All @@ -313,7 +313,7 @@ kover {

```groovy
kover {
enabled = true // false to disable instrumentation of all test tasks in all modules
disabled = false // true to disable instrumentation of all test tasks in all modules
coverageEngine.set(kotlinx.kover.api.CoverageEngine.INTELLIJ) // change instrumentation agent and reporter
intellijEngineVersion.set('1.0.640') // change version of IntelliJ agent and reporter
jacocoEngineVersion.set('0.8.7') // change version of JaCoCo agent and reporter
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/kotlinx/kover/KoverPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class KoverPlugin : Plugin<Project> {

private fun Project.createKoverExtension(): KoverExtension {
val extension = extensions.create(ROOT_EXTENSION_NAME, KoverExtension::class.java, objects)
extension.isEnabled = true
extension.isDisabled = false
extension.coverageEngine.set(CoverageEngine.INTELLIJ)
extension.intellijEngineVersion.set(defaultIntellijVersion.toString())
extension.jacocoEngineVersion.set(defaultJacocoVersion)
Expand All @@ -251,7 +251,7 @@ class KoverPlugin : Plugin<Project> {
) {
val taskExtension = extensions.create(TASK_EXTENSION_NAME, KoverTaskExtension::class.java, project.objects)

taskExtension.isEnabled = true
taskExtension.isDisabled = false
taskExtension.binaryReportFile.set(this.project.provider {
val koverExtension = providers.koverExtension.get()
val suffix = if (koverExtension.coverageEngine.get() == CoverageEngine.INTELLIJ) ".ic" else ".exec"
Expand Down Expand Up @@ -311,8 +311,8 @@ private class CoverageArgumentProvider(
val koverExtensionValue = koverExtension.get()
val taskExtensionValue = taskExtension.get()

if (!taskExtensionValue.isEnabled
|| !koverExtensionValue.isEnabled
if (taskExtensionValue.isDisabled
|| koverExtensionValue.isDisabled
|| koverExtensionValue.disabledModules.contains(task.project.name)
) {
return mutableListOf()
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/kotlinx/kover/Providers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal fun Project.testTasks(rootProject: Project): List<Test> {
}

return tasks.withType(Test::class.java)
.filter { t -> t.extensions.getByType(KoverTaskExtension::class.java).isEnabled }
.filterNot { t -> t.extensions.getByType(KoverTaskExtension::class.java).isDisabled }
}

internal fun Project.binaryReports(root: Project): List<File> {
Expand All @@ -84,7 +84,7 @@ internal fun Project.binaryReports(root: Project): List<File> {
return tasks.withType(Test::class.java).asSequence()
.map { t -> t.extensions.getByType(KoverTaskExtension::class.java) }
// process binary report only from tasks with enabled cover
.filter { e -> e.isEnabled }
.filterNot { e -> e.isDisabled }
.map { e -> e.binaryReportFile.get() }
// process binary report only from tasks with sources
.filter { f -> f.exists() }
Expand All @@ -98,7 +98,7 @@ internal fun Project.smapFiles(root: Project): List<File> {

return tasks.withType(Test::class.java).asSequence()
.map { t -> t.extensions.getByType(KoverTaskExtension::class.java) }
.filter { e -> e.isEnabled }
.filterNot { e -> e.isDisabled }
.mapNotNull { e -> e.smapFile.orNull }
/*
Binary reports and SMAP files have same ordering for IntelliJ engine:
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/kotlinx/kover/api/KoverExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import org.gradle.api.tasks.*
open class KoverExtension(objects: ObjectFactory) {

/**
* Specifies whether the plugin is applied to the test task and configures it to collect and generate coverage data.
* Specifies whether instrumentation is disabled for all test tasks of all modules.
*/
@get:Input
public var isEnabled: Boolean = true
public var isDisabled: Boolean = false

/**
* Specifies the coverage engine to be used to collect execution data.
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/kotlinx/kover/api/KoverTaskExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import java.io.*
*/
open class KoverTaskExtension(objects: ObjectFactory) {
/**
* Specifies whether the plugin is applied to the test task and configures it to collect and generate coverage data.
* Specifies whether instrumentation is disabled for an extended test task.
*/
@get:Input
public var isEnabled: Boolean = true
public var isDisabled: Boolean = false

/**
* Specifies file path of generated binary file with coverage data.
Expand Down

0 comments on commit 06932b4

Please sign in to comment.