Skip to content

Commit

Permalink
Print the coverage numbers of the Jacoco tasks to the console
Browse files Browse the repository at this point in the history
  • Loading branch information
floscher committed Jun 20, 2018
1 parent ed9ac1f commit 04efc1b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ publishPlugin:

pages:
stage: deploy
environment:
name: documentation
url: https://gitlab.com/floscher/gradle-josm-plugin/tree/pages
script:
- |
mkdir -p ~/.ssh/
Expand Down
37 changes: 36 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.openstreetmap.josm.gradle.plugin.GitDescriber
import java.time.Duration
import java.time.Instant
import java.net.URL
import java.util.Locale

buildscript {
repositories {
Expand Down Expand Up @@ -96,11 +97,45 @@ dependencies {
jacoco {
toolVersion = "0.8.1"
}
tasks.withType(JacocoReport::class.java) {
reports {
csv.isEnabled = true
}
val task = this
doLast {
val allLines = task.reports.csv.destination.readLines()
val headerLine = allLines[0].split(',')
var instructionsCovered = 0
var instructionsMissed = 0
var branchesCovered = 0
var branchesMissed = 0
var linesCovered = 0
var linesMissed = 0
allLines.subList(1, allLines.size)
.map{ it.split(',') }
.forEach {
require(it.size == headerLine.size)
instructionsCovered += it[headerLine.indexOf("INSTRUCTION_COVERED")].toInt()
instructionsMissed += it[headerLine.indexOf("INSTRUCTION_MISSED")].toInt()
branchesCovered += it[headerLine.indexOf("BRANCH_COVERED")].toInt()
branchesMissed += it[headerLine.indexOf("BRANCH_MISSED")].toInt()
linesCovered += it[headerLine.indexOf("LINE_COVERED")].toInt()
linesMissed += it[headerLine.indexOf("LINE_MISSED")].toInt()
}

fun coverageLogMessage(coveredCount: Int, missedCount: Int) = "${String.format(Locale.UK, "%.4f", 100 * coveredCount.toDouble() / (coveredCount + missedCount))} % ($coveredCount of ${coveredCount + missedCount})"

logger.lifecycle("Instruction coverage: ${coverageLogMessage(instructionsCovered, instructionsMissed)}")
logger.lifecycle(" Branch coverage: ${coverageLogMessage(branchesCovered, branchesMissed)}")
logger.lifecycle(" Line coverage: ${coverageLogMessage(linesCovered, linesMissed)}")
}
}


tasks.withType(Test::class.java) {
useJUnitPlatform()
finalizedBy(tasks.getByName("jacocoTestReport"))
}
tasks.findByName("jacocoTestReport")?.dependsOn(tasks.findByName("test"))

tasks {
"dokka"(DokkaTask::class) {
Expand Down

0 comments on commit 04efc1b

Please sign in to comment.