-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relates #608
- Loading branch information
Showing
39 changed files
with
1,375 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Kover Aggregated Plugin | ||
|
||
## Quickstart | ||
This plugin is a prototype for testing ideas related to an alternative configuration method. | ||
|
||
The main difference from the existing Kover Gradle Plugin is the reactive content of the report: only those classes and tests that were compiled and executed within the same build get into the report. | ||
|
||
To use the plugin, just add into a `settings.gradle.kts` file | ||
```kotlin | ||
plugins { | ||
id("org.jetbrains.kotlinx.kover.settings") version "0.8.1" | ||
} | ||
``` | ||
**There is no need to apply Kover plugin in other places, the `org.jetbrains.kotlinx.kover` plug-in should not be applied anywhere.** | ||
|
||
To measure coverage you should pass special `-Pkover` argument to Gradle CLI command and call the command to generate the corresponding report `koverHtmlReport` or `koverXmlReport`. | ||
Example, if you want to measure the coverage of the `test` task: | ||
```shell | ||
./gradlew test -Pkover koverHtmlReport | ||
``` | ||
|
||
Only those classes that were compiled as part of the current Gradle build are included in the report. | ||
If no compilation tasks were called in the build, the report will be empty. | ||
|
||
The report covers only those tests that were run as part of the current build. | ||
If no tests were called in the assembly, then the coverage for all classes will be 0. | ||
|
||
## Configuring | ||
At the moment, Kover Settings Plugin allows to configure reports minimally. | ||
|
||
There are two ways to configure, using a build script in `settings.gradle.kts` and CLI | ||
|
||
Acceptable settings in `settings.gradle.kts` and their equivalent in CLI | ||
```kotlin | ||
kover { | ||
// -Pkover | ||
enableCoverage() | ||
|
||
reports { | ||
// -Pkover.classes.from=:a | ||
includedProjects.add(":a") | ||
|
||
// -Pkover.classes.from.excludes=:b | ||
excludedProjects.add(":b") | ||
|
||
// -Pkover.classes.includes=classes.to.exclude.* | ||
includedClasses.add("classes.to.include.*") | ||
|
||
// -Pkover.classes.excludes=classes.to.include.* | ||
excludedClasses.add("classes.to.exclude.*") | ||
} | ||
} | ||
``` | ||
|
||
For example, the following setting is in `settings.gradle.kts` | ||
```kotlin | ||
kover { | ||
enableCoverage() | ||
|
||
reports { | ||
excludedClasses.add("org.test.MyClass*") | ||
} | ||
} | ||
``` | ||
fully equivalent to Gradle CLI arguments `-Pkover -Pkover.classes.excludes=org.test.MyClass*` | ||
|
||
**Any of the specified settings or DSL is preliminary and can be deleted or changed without maintaining backward compatibility** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...ionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/SettingsPluginTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.kover.gradle.plugin.test.functional.cases | ||
|
||
import kotlinx.kover.gradle.plugin.test.functional.framework.checker.CheckerContext | ||
import kotlinx.kover.gradle.plugin.test.functional.framework.starter.TemplateTest | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertTrue | ||
|
||
internal class SettingsPluginTests { | ||
@TemplateTest("settings-plugin", [":tasks"]) | ||
fun CheckerContext.testNoReportTasks() { | ||
taskOutput(":tasks") { | ||
assertFalse("koverXmlReport" in this) | ||
assertFalse("koverHtmlReport" in this) | ||
} | ||
} | ||
|
||
@TemplateTest("settings-plugin", ["test"]) | ||
fun CheckerContext.testNoInstrumentation() { | ||
checkDefaultBinReport(false) | ||
subproject("subproject") { | ||
checkDefaultBinReport(false) | ||
} | ||
} | ||
|
||
@TemplateTest("settings-plugin", ["-Pkover", ":tasks", "-Dorg.gradle.unsafe.isolated-projects=true", "--configuration-cache", "--build-cache"]) | ||
fun CheckerContext.testHasReportTasks() { | ||
taskOutput(":tasks") { | ||
assertTrue("koverXmlReport" in this) | ||
assertTrue("koverHtmlReport" in this) | ||
} | ||
} | ||
|
||
@TemplateTest("settings-plugin", ["-Pkover", "koverXmlReport", "-Dorg.gradle.unsafe.isolated-projects=true", "--configuration-cache", "--build-cache"]) | ||
fun CheckerContext.testNoCompilations() { | ||
xmlReport { | ||
classCounter("tests.settings.root.RootClass").assertAbsent() | ||
classCounter("tests.settings.subproject.SubprojectClass").assertAbsent() | ||
} | ||
} | ||
|
||
@TemplateTest("settings-plugin", ["-Pkover", ":compileKotlin", "koverXmlReport", "-Dorg.gradle.unsafe.isolated-projects=true", "--configuration-cache", "--build-cache"]) | ||
fun CheckerContext.testCompilationOnlyForRoot() { | ||
xmlReport { | ||
classCounter("tests.settings.root.RootClass").assertFullyMissed() | ||
classCounter("tests.settings.subproject.SubprojectClass").assertAbsent() | ||
} | ||
} | ||
|
||
@TemplateTest("settings-plugin", ["-Pkover", ":subproject:compileKotlin", ":test", "koverXmlReport", "-Dorg.gradle.unsafe.isolated-projects=true", "--configuration-cache", "--build-cache"]) | ||
fun CheckerContext.testRootAndOnlyCompileSubproject() { | ||
xmlReport { | ||
classCounter("tests.settings.root.RootClass").assertFullyCovered() | ||
classCounter("tests.settings.subproject.SubprojectClass").assertFullyMissed() | ||
} | ||
} | ||
|
||
|
||
@TemplateTest("settings-plugin", ["-Pkover", "test", "koverXmlReport", "-Dorg.gradle.unsafe.isolated-projects=true", "--configuration-cache", "--build-cache"]) | ||
fun CheckerContext.testAll() { | ||
xmlReport { | ||
classCounter("tests.settings.root.RootClass").assertFullyCovered() | ||
classCounter("tests.settings.subproject.SubprojectClass").assertFullyCovered() | ||
} | ||
} | ||
|
||
@TemplateTest("settings-plugin", ["-Pkover", "test", "koverXmlReport", "-Pkover.classes.from.excludes=:subproject", "-Dorg.gradle.unsafe.isolated-projects=true", "--configuration-cache", "--build-cache"]) | ||
fun CheckerContext.testExcludeSubproject() { | ||
xmlReport { | ||
classCounter("tests.settings.root.RootClass").assertFullyCovered() | ||
classCounter("tests.settings.subproject.SubprojectClass").assertAbsent() | ||
} | ||
} | ||
|
||
@TemplateTest("settings-plugin", ["-Pkover", "test", "koverXmlReport", "-Pkover.classes.excludes=tests.settings.subproject.*", "-Dorg.gradle.unsafe.isolated-projects=true", "--configuration-cache", "--build-cache"]) | ||
fun CheckerContext.testExcludeClasses() { | ||
xmlReport { | ||
classCounter("tests.settings.root.RootClass").assertFullyCovered() | ||
classCounter("tests.settings.subproject.SubprojectClass").assertAbsent() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
kover-gradle-plugin/src/functionalTest/templates/builds/settings-plugin/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
kotlin("jvm") version ("2.0.0") | ||
} | ||
|
||
dependencies { | ||
testImplementation(kotlin("test")) | ||
} | ||
|
20 changes: 20 additions & 0 deletions
20
kover-gradle-plugin/src/functionalTest/templates/builds/settings-plugin/settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
pluginManagement { | ||
repositories { | ||
gradlePluginPortal() | ||
mavenCentral() | ||
} | ||
} | ||
|
||
plugins { | ||
id("org.jetbrains.kotlinx.kover.settings") version "SNAPSHOT" | ||
} | ||
|
||
buildCache { | ||
local { | ||
directory = "$settingsDir/build-cache" | ||
} | ||
} | ||
|
||
rootProject.name = "settings-plugin" | ||
|
||
include(":subproject") |
11 changes: 11 additions & 0 deletions
11
...e-plugin/src/functionalTest/templates/builds/settings-plugin/src/main/kotlin/RootClass.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package tests.settings.root | ||
|
||
class RootClass { | ||
fun action() { | ||
println("It's root class") | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...le-plugin/src/functionalTest/templates/builds/settings-plugin/src/test/kotlin/RootTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package tests.settings.root | ||
|
||
import kotlin.test.Test | ||
|
||
class RootTest { | ||
@Test | ||
fun test() { | ||
RootClass().action() | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...le-plugin/src/functionalTest/templates/builds/settings-plugin/subproject/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plugins { | ||
kotlin("jvm") | ||
} | ||
|
||
dependencies { | ||
testImplementation(kotlin("test")) | ||
} |
11 changes: 11 additions & 0 deletions
11
...tionalTest/templates/builds/settings-plugin/subproject/src/main/kotlin/SubprojectClass.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package tests.settings.subproject | ||
|
||
class SubprojectClass { | ||
fun action() { | ||
println("It's class from the subproject") | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...n/src/functionalTest/templates/builds/settings-plugin/subproject/src/test/kotlin/ATest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package tests.settings.subproject | ||
|
||
import kotlin.test.Test | ||
|
||
class SubprojectTest { | ||
@Test | ||
fun test() { | ||
SubprojectClass().action() | ||
} | ||
} |
Oops, something went wrong.