Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose reportDir property in KoverHtmlReport interface #591

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kover-gradle-plugin/api/kover-gradle-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public abstract interface class kotlinx/kover/gradle/plugin/dsl/tasks/KoverBinar
}

public abstract interface class kotlinx/kover/gradle/plugin/dsl/tasks/KoverHtmlReport : kotlinx/kover/gradle/plugin/dsl/tasks/KoverReport {
public abstract fun getReportDir ()Lorg/gradle/api/provider/Provider;
}

public abstract interface class kotlinx/kover/gradle/plugin/dsl/tasks/KoverLogReport : kotlinx/kover/gradle/plugin/dsl/tasks/KoverReport {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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.runner.generateBuild
import kotlinx.kover.gradle.plugin.test.functional.framework.runner.runWithParams
import org.junit.jupiter.api.Test
import kotlin.test.assertTrue

internal class TaskInterfacesTests {

@Test
fun testDefaultHtmlDir() {
val build = generateBuild { dir ->
dir.resolve("settings.gradle.kts").createNewFile()

dir.resolve("build.gradle.kts").writeText(
"""
import kotlinx.kover.gradle.plugin.dsl.tasks.KoverHtmlReport

plugins {
kotlin("jvm") version "1.9.22"
id("org.jetbrains.kotlinx.kover")
}

tasks.register("checkDir") {
doFirst {
val task = tasks.withType<KoverHtmlReport>().matching { it.name == "koverHtmlReport" }.first()
if (task.reportDir.get().asFile != layout.buildDirectory.dir("reports/kover/html").get().asFile) {
throw Exception("Default directory differ, expect ${'$'}{layout.buildDirectory.dir("reports/kover/html").get().asFile} actual ${'$'}{task.reportDir.get().asFile}")
}
}
}
""".trimIndent()
)
}.generate()

val result = build.runWithParams("checkDir")
assertTrue(result.isSuccessful)
}

@Test
fun testCustomHtmlDir() {
val build = generateBuild { dir ->
dir.resolve("settings.gradle.kts").createNewFile()

dir.resolve("build.gradle.kts").writeText(
"""
import kotlinx.kover.gradle.plugin.dsl.tasks.KoverHtmlReport

plugins {
kotlin("jvm") version "1.9.22"
id("org.jetbrains.kotlinx.kover")
}

kover {
reports {
total {
html {
htmlDir.set(layout.buildDirectory.dir("customHtmlReport"))
}
}
}
}

tasks.register("checkDir") {
doFirst {
val task = tasks.withType<KoverHtmlReport>().matching { it.name == "koverHtmlReport" }.first()
if (task.reportDir.get().asFile != layout.buildDirectory.dir("customHtmlReport").get().asFile) {
throw Exception("Custom directory differ, expect ${'$'}{layout.buildDirectory.dir("customHtmlReport").get().asFile} actual ${'$'}{task.reportDir.get().asFile}")
}
}
}
""".trimIndent()
)
}.generate()

val result = build.runWithParams("checkDir")
assertTrue(result.isSuccessful)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
package kotlinx.kover.gradle.plugin.dsl.tasks

import org.gradle.api.Task
import org.gradle.api.file.Directory
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.OutputDirectory

/**
* Common interface for all Kover report tasks.
Expand All @@ -19,7 +22,13 @@ interface KoverXmlReport: KoverReport
/**
* Interface for Kover HTML report generation tasks.
*/
interface KoverHtmlReport: KoverReport
interface KoverHtmlReport: KoverReport {
/**
* The directory where the HTML report will be saved.
*/
@get:OutputDirectory
val reportDir: Provider<Directory>
}

/**
* Interface for Kover tasks that print coverage to the build log.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.net.URI
@CacheableTask
internal abstract class KoverHtmlTask : AbstractKoverReportTask(), KoverHtmlReport {
@get:OutputDirectory
abstract val reportDir: DirectoryProperty
abstract override val reportDir: DirectoryProperty

@get:Input
abstract val title: Property<String>
Expand Down