-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoverage.gradle.kts
34 lines (26 loc) · 1.18 KB
/
coverage.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import javax.xml.parsers.DocumentBuilderFactory
tasks.register("printLineCoverage") {
group = "verification" // Put into the same group as the `kover` tasks
doLast {
val report = file("$buildDir/reports/kover/report.xml")
val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(report)
val rootNode = doc.firstChild
var childNode = rootNode.firstChild
var coveragePercent = 0.0
while (childNode != null) {
if (childNode.nodeName == "counter") {
val typeAttr = childNode.attributes.getNamedItem("type")
if (typeAttr.textContent == "LINE") {
val missedAttr = childNode.attributes.getNamedItem("missed")
val coveredAttr = childNode.attributes.getNamedItem("covered")
val missed = missedAttr.textContent.toLong()
val covered = coveredAttr.textContent.toLong()
coveragePercent = (covered * 100.0) / (missed + covered)
break
}
}
childNode = childNode.nextSibling
}
println("%.1f".format(coveragePercent))
}
}