Skip to content

Commit

Permalink
Added ability to supplement coverage values from external binary reports
Browse files Browse the repository at this point in the history
This will allow to build reports on tests run on various machines.

Relates #585
Relates #645
  • Loading branch information
shanshin committed Aug 2, 2024
1 parent 980f472 commit 87b8de1
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2017-2023 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.configurator.BuildConfigurator
import kotlinx.kover.gradle.plugin.test.functional.framework.starter.GeneratedTest
import java.io.File

internal class ReportsAdditionalIcTests {

@GeneratedTest
fun BuildConfigurator.test() {
copy(File("src/functionalTest/templates/report.bin"), "additional.ic")
addProjectWithKover {
sourcesFrom("simple")
kover {
reports {
verify {
rule {
minBound(100)
}
}

total {
additionalBinaryReports.add(File("additional.ic"))
}
}
}
}
run("koverBinaryReport", "koverVerify", "koverXmlReport") {
xmlReport {
classCounter("org.jetbrains.ExampleClass").assertFullyCovered()
classCounter("org.jetbrains.SecondClass").assertFullyCovered()
classCounter("org.jetbrains.Unused").assertFullyCovered()
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.kover.gradle.plugin.test.functional.framework.checker.*
import kotlinx.kover.gradle.plugin.test.functional.framework.common.*
import kotlinx.kover.gradle.plugin.test.functional.framework.common.kotlinVersionCurrent
import kotlinx.kover.gradle.plugin.test.functional.framework.mirroring.printGradleDsl
import java.io.File

internal fun createConfigurator(): BuildConfigurator {
return TestBuildConfigurator()
Expand Down Expand Up @@ -50,6 +51,13 @@ internal data class TestFileAddStep(
override val name: String = "Add file: $filePath"
}

internal data class TestFileCopyStep(
val origin: File,
val filePath: String,
): TestExecutionStep() {
override val name: String = "Copy file $origin to $filePath"
}

internal data class TestFileDeleteStep(val filePath: String): TestExecutionStep() {
override val name: String = "Delete file: $filePath"
}
Expand Down Expand Up @@ -92,6 +100,10 @@ private open class TestBuildConfigurator : BuildConfigurator {
steps += TestFileAddStep(filePath, editor)
}

override fun copy(from: File, filePath: String) {
steps += TestFileCopyStep(from, filePath)
}

override fun delete(filePath: String) {
steps += TestFileDeleteStep(filePath)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ internal interface BuildConfigurator {

fun add(filePath: String, editor: () -> String)

fun copy(from: File, filePath: String)

fun delete(filePath: String)

fun useLocalCache(use: Boolean = true)
Expand Down Expand Up @@ -85,6 +87,10 @@ internal abstract class BuilderConfiguratorWrapper(private val origin: BuildConf
origin.add(filePath, editor)
}

override fun copy(from: File, filePath: String) {
origin.copy(from, filePath)
}

override fun delete(filePath: String) {
origin.delete(filePath)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package kotlinx.kover.gradle.plugin.test.functional.framework.mirroring

import kotlinx.kover.gradle.plugin.test.functional.framework.common.ScriptLanguage
import kotlinx.kover.gradle.plugin.util.SemVer
import java.io.File


internal fun printCode(name: String?, language: ScriptLanguage, gradleVersion: String, block: CodeBlock): String {
Expand Down Expand Up @@ -132,6 +133,7 @@ private fun handleValueLiteral(context: PrintingContext, expression: ValueLitera
is String -> context.print("\"${expression.value}\"")
is Int -> context.print(expression.value.toString())
is Boolean -> context.print(expression.value.toString())
is File -> context.print("file(\"${expression.value}\")")
else -> throw IllegalStateException("Value '${expression.value}' with type ${expression.value.javaClass} unsupported as argument")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ ${this.targetDir.buildScript()}
file.writeText(step.editor())
}

is TestFileCopyStep -> {
val file = projectFile(step.filePath, description)
step.origin.copyTo(file, overwrite = true)
}

is TestFileDeleteStep -> {
val file = projectFile(step.filePath, description)
file.delete()
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ internal class VariantReportsSet(
htmlTask.configure {
onlyIf { printPath(); true }

additionalBinaryReports.convention(config.additionalBinaryReports)
reportDir.convention(config.html.htmlDir)
title.convention(config.html.title.orElse(project.name))
charset.convention(config.html.charset)
Expand All @@ -79,6 +80,8 @@ internal class VariantReportsSet(
}

xmlTask.configure {
additionalBinaryReports.convention(config.additionalBinaryReports)

reportFile.convention(config.xml.xmlFile)
title.convention(config.xml.title)
filters.set((config.filters).convert())
Expand All @@ -88,6 +91,8 @@ internal class VariantReportsSet(
}

binTask.configure {
additionalBinaryReports.convention(config.additionalBinaryReports)

file.convention(config.binary.file)
filters.set((config.filters).convert())
}
Expand All @@ -97,6 +102,8 @@ internal class VariantReportsSet(


doVerifyTask.configure {
additionalBinaryReports.convention(config.additionalBinaryReports)

val resultRules = config.verify.rules
val converted = resultRules.map { rules -> rules.map { it.convert() } }

Expand Down Expand Up @@ -142,6 +149,8 @@ internal class VariantReportsSet(
}

logTask.configure {
additionalBinaryReports.convention(config.additionalBinaryReports)

header.convention(config.log.header)
lineFormat.convention(config.log.format)
groupBy.convention(config.log.groupBy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.SetProperty
import java.io.File

/**
* Configuration of Kover reports.
Expand Down Expand Up @@ -428,6 +429,9 @@ public interface KoverReportSetConfig {
*/
public val log: KoverLogTaskConfig


public val additionalBinaryReports: SetProperty<File>

@Deprecated(
message = "Block mergeWith was removed, create custom reports variant and merge with specified variant. Please refer to migration guide in order to migrate: ${KoverMigrations.MIGRATION_0_7_TO_0_8}",
level = DeprecationLevel.ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ internal abstract class AbstractKoverReportTask : DefaultTask() {
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val reportClasspath: ConfigurableFileCollection

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val additionalBinaryReports: SetProperty<File>

/**
* This will cause the task to be considered out-of-date when source files of dependencies have changed.
*/
Expand Down Expand Up @@ -73,7 +77,7 @@ internal abstract class AbstractKoverReportTask : DefaultTask() {
}

private fun collectAllFiles(): ArtifactContent {
val local = ArtifactContent(projectPath, emptySet(), emptySet(), emptySet())
val local = ArtifactContent(projectPath, emptySet(), emptySet(), additionalBinaryReports.get())
return local.joinWith(artifacts.files.map { it.parseArtifactFile(rootDir).filterProjectSources() }).existing()
}

Expand Down

0 comments on commit 87b8de1

Please sign in to comment.