Skip to content

Commit

Permalink
Ordered report tasks before verification
Browse files Browse the repository at this point in the history
Resolves #209
  • Loading branch information
shanshin committed Aug 23, 2022
1 parent f7f0d1c commit cb8280d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
@@ -0,0 +1,54 @@
package kotlinx.kover.test.functional.cases

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 TasksOrderingTests : BaseGradleScriptTest() {
@Test
fun testProjectTasks() {
val build = diverseBuild()
build.addKoverRootProject {
sourcesFrom("simple")
kover {
verify {
rule {
bound {
minValue = 100
}
}
}
}
}
val runner = build.prepare()
runner.runWithError("koverVerify", "koverReport") {
// reports should be generated even if verification failed with an error
checkDefaultReports()
}
}

@Test
fun testMergedTasks() {
val build = diverseBuild()
build.addKoverRootProject {
sourcesFrom("simple")
koverMerged {
enable()
verify {
rule {
bound {
minValue = 100
}
}
}
}
}
val runner = build.prepare()
runner.runWithError("koverMergedVerify", "koverMergedReport") {
// reports should be generated even if verification failed with an error
checkDefaultMergedReports()
}
}

}
Expand Up @@ -211,13 +211,19 @@ internal class RepositoriesState : Repositories {
internal class TestKoverMergedConfigState : TestKoverMergedConfig {
var enabled: Boolean = false
val filters: TestKoverMergedFiltersState = TestKoverMergedFiltersState()
val verify: TestKoverVerifyConfigState = TestKoverVerifyConfigState()

override fun enable() {
enabled = true
}

override fun filters(config: TestKoverMergedFilters.() -> Unit) {
filters.also(config)
}

override fun verify(config: TestKoverVerifyConfig.() -> Unit) {
verify.also(config)
}
}

internal class TestKoverMergedFiltersState : TestKoverMergedFilters {
Expand Down
Expand Up @@ -98,6 +98,8 @@ internal interface TestKoverMergedConfig {
public fun enable()

public fun filters(config: TestKoverMergedFilters.() -> Unit)

public fun verify(config: TestKoverVerifyConfig.() -> Unit)
}

public interface TestKoverMergedFilters {
Expand Down
Expand Up @@ -14,6 +14,7 @@ internal fun PrintWriter.printKoverMerged(merged: TestKoverMergedConfigState?, s
indented(indents, "koverMerged {")
printEnabled(merged.enabled, indents + 1)
printFilters(merged.filters, slice, indents + 1)
printVerify(merged.verify, slice, indents + 1)
indented(indents, "}")
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/kotlinx/kover/appliers/KoverMergedApplier.kt
Expand Up @@ -92,6 +92,8 @@ private class ProcessMergeExtensionAction(private val extension: KoverMergedConf
// TODO `onlyIf` block moved out from config lambda because of bug in Kotlin compiler - it implicitly adds closure on `Project` inside onlyIf's lambda
verifyTask.onlyIf { extension.verify.hasActiveRules() }

// ordering of task calls, so that if a verification error occurs, reports are generated and the values can be viewed in them
verifyTask.shouldRunAfter(xmlTask, htmlTask)

container.tasks.create(MERGED_REPORT_TASK_NAME) {
it.group = VERIFICATION_GROUP
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/kotlinx/kover/appliers/KoverProjectApplier.kt
Expand Up @@ -68,6 +68,8 @@ internal fun Project.applyToProject() {
// TODO `onlyIf` block moved out from config lambda because of bug in Kotlin compiler - it implicitly adds closure on `Project` inside onlyIf's lambda
verifyTask.onlyIf { extension.verify.hasActiveRules() }

// ordering of task calls, so that if a verification error occurs, reports are generated and the values can be viewed in them
verifyTask.shouldRunAfter(xmlTask, htmlTask)

tasks.create(KoverNames.REPORT_TASK_NAME) {
it.group = KoverNames.VERIFICATION_GROUP
Expand Down

0 comments on commit cb8280d

Please sign in to comment.