Skip to content

Commit

Permalink
Add code coverage report generation
Browse files Browse the repository at this point in the history
  • Loading branch information
DimuthuMadushan committed Nov 8, 2023
1 parent 1d32ea6 commit da70e44
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
25 changes: 24 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ allprojects {
version = project.version
apply plugin: 'checkstyle'
apply plugin: 'maven-publish'
apply plugin: 'java'
apply plugin: 'jacoco'

repositories {
mavenLocal()
Expand Down Expand Up @@ -59,8 +61,29 @@ def stripBallerinaExtensionVersion(String extVersion) {
}
}

tasks.register('codeCoverageReport', JacocoReport) {
dependsOn = subprojects.test

executionData fileTree(project.rootDir.absolutePath).include("**/build/coverage-reports/*.exec")

subprojects.each {
sourceSets it.sourceSets.main
}
reports {
xml.required = true
html.required = true
csv.required = true
xml.destination(new File("${buildDir}/reports/jacoco/report.xml"))
html.destination(new File("${buildDir}/reports/jacoco/report.html"))
csv.destination(new File("${buildDir}/reports/jacoco/report.csv"))
}

onlyIf = {
true
}
}

subprojects {
apply plugin: 'java'
configurations {
ballerinaStdLibs
}
Expand Down
11 changes: 11 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ignore:
- "copybook-tool"

coverage:
precision: 2
round: down
range: "60...80"
status:
project:
default:
target: auto
28 changes: 28 additions & 0 deletions copybook-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,41 @@ tasks.register('copyJar', Copy) {
into "$rootDir/copybook-tool/build/libs"
}

jacoco {
toolVersion = "${jacocoVersion}"
}

jacocoTestReport {
dependsOn test
def classFiles = new File("${rootDir}/copybook-cli/build/classes/java/main/io/ballerina/tools/copybook")
additionalClassDirs(classFiles)
reports {
xml.required = true
html.required = true
}
}

checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles")
checkstyleTest.dependsOn(":checkstyle:downloadCheckstyleRuleFiles")

test {
useTestNG() {
suites "src/test/resources/testng.xml"
}

testLogging.showStandardStreams = true
testLogging {
events "PASSED", "FAILED", "SKIPPED"
afterSuite { desc, result ->
if (!desc.parent) {
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
}
}
}
finalizedBy jacocoTestReport
}

spotbugsMain {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ copybookParserVersion=0.1.0-SNAPSHOT
testngVersion=7.7.0
slf4jVersion=2.0.9
antlrVersion=4.13.1
jacocoVersion=0.8.10

0 comments on commit da70e44

Please sign in to comment.