Skip to content

Commit

Permalink
Unified agent filters
Browse files Browse the repository at this point in the history
All filters for both engines now use only `*` and `?` wildcards.
Resolves #21
  • Loading branch information
shanshin committed Dec 8, 2021
1 parent 2fbd52e commit 1475b5d
Show file tree
Hide file tree
Showing 23 changed files with 656 additions and 381 deletions.
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -121,8 +121,8 @@ tasks.test {
extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) {
isEnabled = true
binaryReportFile.set(file("$buildDir/custom/result.bin"))
includes = listOf("com\\.example\\..*")
excludes = listOf("com\\.example\\.subpackage\\..*")
includes = listOf("com.example.*")
excludes = listOf("com.example.subpackage.*")
}
}
```
Expand All @@ -136,8 +136,8 @@ tasks.test {
kover {
enabled = true
binaryReportFile.set(file("$buildDir/custom/result.bin"))
includes = ['com\\.example\\..*']
excludes = ['com\\.example\\.subpackage\\..*']
includes = ['com.example.*']
excludes = ['com.example.subpackage.*']
}
}
```
Expand All @@ -159,8 +159,8 @@ android {
extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) {
isEnabled = true
binaryReportFile.set(file("$buildDir/custom/debug-report.bin"))
includes = listOf("com\\.example\\..*")
excludes = listOf("com\\.example\\.subpackage\\..*")
includes = listOf("com.example.*")
excludes = listOf("com.example.subpackage.*")
}
}
}
Expand All @@ -183,8 +183,8 @@ android {
kover {
enabled = true
binaryReportFile.set(file("$buildDir/custom/debug-report.bin"))
includes = ['com\\.example\\..*']
excludes = ['com\\.example\\.subpackage\\..*']
includes = ['com.example.*']
excludes = ['com.example.subpackage.*']
}
}
}
Expand Down
Expand Up @@ -7,25 +7,27 @@ import kotlin.test.*
internal class DefaultConfigTests : BaseGradleScriptTest() {
@Test
fun testImplicitConfigsJvm() {
runner()
builder()
.case("Test default setting for Kotlin/JVM")
.languages(GradleScriptLanguage.GROOVY, GradleScriptLanguage.KOTLIN)
.types(ProjectType.KOTLIN_JVM)
.sources("simple-single")
.check("build") {
.sources("simple")
.build()
.run("build") {
checkIntellijBinaryReport(DEFAULT_INTELLIJ_KJVM_BINARY, DEFAULT_INTELLIJ_KJVM_SMAP)
checkReports(DEFAULT_XML, DEFAULT_HTML)
}
}

@Test
fun testImplicitConfigsKmp() {
runner()
builder()
.case("Test default setting for Kotlin Multi-Platform")
.languages(GradleScriptLanguage.GROOVY, GradleScriptLanguage.KOTLIN)
.types(ProjectType.KOTLIN_MULTIPLATFORM)
.sources("simple-single")
.check("build") {
.sources("simple")
.build()
.run("build") {
checkIntellijBinaryReport(DEFAULT_INTELLIJ_KMP_BINARY, DEFAULT_INTELLIJ_KMP_SMAP)
checkReports(DEFAULT_XML, DEFAULT_HTML)
}
Expand Down
@@ -0,0 +1,58 @@
package kotlinx.kover.test.functional.cases

import kotlinx.kover.api.*
import kotlinx.kover.test.functional.cases.utils.*
import kotlinx.kover.test.functional.core.*
import kotlinx.kover.test.functional.core.BaseGradleScriptTest
import kotlin.test.*

internal class InstrumentationFilteringTests : BaseGradleScriptTest() {

@Test
fun testExclude() {
builder()
.case("Test exclusion of classes from instrumentation")
.languages(GradleScriptLanguage.KOTLIN, GradleScriptLanguage.GROOVY)
.types(ProjectType.KOTLIN_JVM, ProjectType.KOTLIN_MULTIPLATFORM)
.engines(CoverageEngine.INTELLIJ, CoverageEngine.JACOCO)
.sources("simple")
.configTest(
"""excludes = listOf("org.jetbrains.*Exa?ple*")""",
"""excludes = ['org.jetbrains.*Exa?ple*']"""
)
.build()
.run("build") {
xml(DEFAULT_XML) {
assertCounterExcluded(classCounter("org.jetbrains.ExampleClass"), this@run.engine)
assertCounterCoveredAndIncluded(classCounter("org.jetbrains.SecondClass"))
}
}
}

@Test
fun testExcludeInclude() {
builder()
.case("Test inclusion and exclusion of classes in instrumentation")
.languages(GradleScriptLanguage.KOTLIN, GradleScriptLanguage.GROOVY)
.types(ProjectType.KOTLIN_JVM, ProjectType.KOTLIN_MULTIPLATFORM)
.engines(CoverageEngine.INTELLIJ, CoverageEngine.JACOCO)
.sources("simple")
.configTest(
"""includes = listOf("org.jetbrains.*Cla?s")""",
"""includes = ['org.jetbrains.*Cla?s']"""
)
.configTest(
"""excludes = listOf("org.jetbrains.*Exa?ple*")""",
"""excludes = ['org.jetbrains.*Exa?ple*']"""
)
.build()
.run("build") {
xml(DEFAULT_XML) {
assertCounterExcluded(classCounter("org.jetbrains.ExampleClass"), this@run.engine)
assertCounterExcluded(classCounter("org.jetbrains.Unused"), this@run.engine)
assertCounterCoveredAndIncluded(classCounter("org.jetbrains.SecondClass"))
}
}
}

}
Expand Up @@ -9,48 +9,50 @@ import kotlin.test.*
internal class ReportsCachingTests : BaseGradleScriptTest() {
@Test
fun testCachingForIntellij() {
runner()
builder()
.case("Test caching reports for IntelliJ Coverage Engine")
.engines(CoverageEngine.INTELLIJ)
.sources("simple-single")
.check("build", "--build-cache") {
.sources("simple")
.build()
.run("build", "--build-cache") {
checkIntellijBinaryReport(DEFAULT_INTELLIJ_KJVM_BINARY, DEFAULT_INTELLIJ_KJVM_SMAP)
checkReports(DEFAULT_XML, DEFAULT_HTML)
}
.check("clean", "--build-cache") {
.run("clean", "--build-cache") {
checkIntellijBinaryReport(DEFAULT_INTELLIJ_KJVM_BINARY, DEFAULT_INTELLIJ_KJVM_SMAP, false)
checkReports(DEFAULT_XML, DEFAULT_HTML, false)
}
.check("build", "--build-cache") {
.run("build", "--build-cache") {
checkIntellijBinaryReport(DEFAULT_INTELLIJ_KJVM_BINARY, DEFAULT_INTELLIJ_KJVM_SMAP)
checkReports(DEFAULT_XML, DEFAULT_HTML)
assertEquals(TaskOutcome.FROM_CACHE, outcome(":test"))
assertEquals(TaskOutcome.FROM_CACHE, outcome(":koverXmlReport"))
assertEquals(TaskOutcome.FROM_CACHE, outcome(":koverHtmlReport"))
outcome(":test") { assertEquals(TaskOutcome.FROM_CACHE, this)}
outcome(":koverXmlReport") { assertEquals(TaskOutcome.FROM_CACHE, this)}
outcome(":koverHtmlReport") { assertEquals(TaskOutcome.FROM_CACHE, this)}
}
}

@Test
fun testCachingForJacoco() {
runner()
builder()
.case("Test caching reports for JaCoCo Coverage Engine")
.engines(CoverageEngine.JACOCO)
.sources("simple-single")
.check("build", "--build-cache") {
.sources("simple")
.build()
.run("build", "--build-cache") {
checkJacocoBinaryReport(DEFAULT_JACOCO_KJVM_BINARY)
checkReports(DEFAULT_XML, DEFAULT_HTML)
}
.check("clean", "--build-cache") {
.run("clean", "--build-cache") {
checkJacocoBinaryReport(DEFAULT_JACOCO_KJVM_BINARY, false)
checkReports(DEFAULT_XML, DEFAULT_HTML, false)
}
.check("build", "--build-cache") {
.run("build", "--build-cache") {
checkJacocoBinaryReport(DEFAULT_JACOCO_KJVM_BINARY)
checkReports(DEFAULT_XML, DEFAULT_HTML)

assertEquals(TaskOutcome.FROM_CACHE, outcome(":test"))
assertEquals(TaskOutcome.FROM_CACHE, outcome(":koverXmlReport"))
assertEquals(TaskOutcome.FROM_CACHE, outcome(":koverHtmlReport"))
outcome(":test") { assertEquals(TaskOutcome.FROM_CACHE, this)}
outcome(":koverXmlReport") { assertEquals(TaskOutcome.FROM_CACHE, this)}
outcome(":koverHtmlReport") { assertEquals(TaskOutcome.FROM_CACHE, this)}
}
}

Expand Down
@@ -1,38 +1,73 @@
package kotlinx.kover.test.functional.cases.utils

import kotlinx.kover.api.*
import kotlinx.kover.test.functional.core.*
import kotlinx.kover.test.functional.core.RunResult
import kotlin.test.*

internal fun RunResult.checkIntellijBinaryReport(binary: String, smap: String, mustExists: Boolean = true) {
if (mustExists) {
assertTrue { file(binary).exists() }
assertTrue { file(binary).length() > 0 }
assertTrue { file(smap).exists() }
assertTrue { file(smap).length() > 0 }
file(binary) {
assertTrue { exists() }
assertTrue { length() > 0 }
}
file(smap) {
assertTrue { exists() }
assertTrue { length() > 0 }
}
} else {
assertFalse { file(binary).exists() }
assertFalse { file(smap).exists() }
file(binary) {
assertFalse { exists() }
}
file(smap) {
assertFalse { exists() }
}
}
}

internal fun RunResult.checkJacocoBinaryReport(binary: String, mustExists: Boolean = true) {
if (mustExists) {
assertTrue { file(binary).exists() }
assertTrue { file(binary).length() > 0 }
file(binary) {
assertTrue { exists() }
assertTrue { length() > 0 }
}
} else {
assertFalse { file(binary).exists() }
file(binary) {
assertFalse { exists() }
}
}
}

internal fun RunResult.checkReports(xmlPath: String, htmlPath: String, mustExists: Boolean = true) {
if (mustExists) {
assertTrue { file(xmlPath).exists() }
assertTrue { file(xmlPath).length() > 0 }
assertTrue { file(htmlPath).exists() }
assertTrue { file(htmlPath).isDirectory }
file(xmlPath) {
assertTrue { exists() }
assertTrue { length() > 0 }
}
file(htmlPath) {
assertTrue { exists() }
assertTrue { isDirectory }
}
} else {
assertFalse { file(xmlPath).exists() }
assertFalse { file(htmlPath).exists() }
file(xmlPath) {
assertFalse { exists() }
}
file(htmlPath) {
assertFalse { exists() }
}
}
}

internal fun assertCounterExcluded(counter: Counter?, engine: CoverageEngine) {
if (engine == CoverageEngine.INTELLIJ) {
assertNull(counter)
} else {
assertNotNull(counter)
assertEquals(0, counter.covered)
}
}

internal fun assertCounterCoveredAndIncluded(counter: Counter?) {
assertNotNull(counter)
assertTrue { counter.covered > 0 }
}
Expand Up @@ -9,7 +9,7 @@ internal open class BaseGradleScriptTest {
@JvmField
internal val rootFolder: TemporaryFolder = TemporaryFolder()

fun runner(): ProjectRunner {
return createRunner(rootFolder.root)
fun builder(): ProjectBuilder {
return createBuilder(rootFolder.root)
}
}

0 comments on commit 1475b5d

Please sign in to comment.