From 00253bc9b2fa64ccb40a85f99dd08050c104118c Mon Sep 17 00:00:00 2001 From: Alexander Pann Date: Mon, 18 Mar 2024 09:19:25 +0100 Subject: [PATCH] Fail the build when tests fail --- build.gradle | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/build.gradle b/build.gradle index 909d8af4e..2f5ef842b 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,7 @@ plugins { } import de.itemis.mps.gradle.* +import groovy.xml.XmlSlurper import java.time.LocalDateTime @@ -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/"