Skip to content

Commit

Permalink
Fail the build when tests fail
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderpann committed Mar 18, 2024
1 parent 1595ede commit 00253bc
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
}

import de.itemis.mps.gradle.*
import groovy.xml.XmlSlurper

import java.time.LocalDateTime

Expand Down Expand Up @@ -228,12 +229,42 @@ task build_tests(type: BuildLanguages, dependsOn: build_languages) {
script scriptFile('tests/build.xml')
}

task failOnTestError() {
description 'evaluate junit result and fail on error'
doLast {

def juniXml = file('TESTS-TestSuites.xml')
if(juniXml.exists()){
def junitResult = new XmlSlurper().parse(juniXml)
def failures = junitResult.'**'.findAll { it.name() == 'failure' }
def errors = junitResult.'**'.findAll { it.name() == 'error' }

if (failures || errors) {
def amount = failures.size() + errors.size()
throw new GradleException(amount + " JUnit tests failed. Check the test report for details.")
}
}
}
}

task run_tests(type: TestLanguages, dependsOn: build_tests) {
description "Will execute all tests from command line"
script scriptFile('tests/build.xml')
targets 'check'
doLast {
ant.taskdef(name: 'junitreport',
classname: 'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator',
classpath: configurations.junitAnt.asPath)
ant.junitreport {
fileset(dir: "$buildDir", includes: '**/TEST*.xml')
report(format: 'frames', todir: "$buildDir/junitreport")
}
ant.echo("JUnit report placed into $buildDir/junitreport/index.html")
}
}

run_tests.configure { finalizedBy failOnTestError }

task install_nativelibs(type: Copy, dependsOn: build_languages) {
from "$rootDir/artifacts/de.itemis.mps.extensions/"
include "de.itemis.mps.nativelibs.loader/"
Expand Down

0 comments on commit 00253bc

Please sign in to comment.