Skip to content

Commit

Permalink
LRCI-3750 Record JUnit XML report when tests fail to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhashimoto authored and brianchandotcom committed Aug 19, 2023
1 parent c23c9db commit 78ffb34
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 72 deletions.
3 changes: 2 additions & 1 deletion build-common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ information.
<attribute name="junit.failure.message.element" />
<attribute name="test.class.name" />
<attribute name="test.command.name" />
<attribute default="." name="test.results.dir" />

<sequential>
<local name="junit.timestamp" />
Expand All @@ -672,7 +673,7 @@ information.
<format pattern="yyyy-MM-dd_kk:mm:ss" property="junit.timestamp" />
</tstamp>

<echo file="TEST-@{test.class.name}.xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<echo file="@{test.results.dir}/TEST-@{test.class.name}.xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<testsuite errors="@{junit.failure.count}" failures="@{junit.failure.count}" hostname="localhost" name="@{test.class.name}" skipped="0" tests="1" time="0.0" timestamp="${junit.timestamp}">
<properties />
Expand Down
164 changes: 93 additions & 71 deletions build-test-batch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2526,40 +2526,11 @@ log.sanitizer.enabled=false</echo>

<for list="${test.class.group}" param="test.class">
<sequential>
<local name="test.timeout" />

<trycatch property="test.failure.message">
<try>
<get-test-project-information test.class="@{test.class}" />

<limit failonerror="true" maxwait="${test.class.timeout.seconds}" property="test.timeout" value="FAILURE: ${test.project.name}:testIntegration --tests ${test.name} failed to complete in ${test.class.timeout.minutes} minutes">
<gradle-execute dir="modules" refreshdependencies="@{refreshdependencies}" task="${test.project.name}:testIntegration" test.name="${test.name}">
<arg value="--continue" />
<arg value="-Dbuild.exclude.ant.plugin=true" />
<arg value="-Dtest.class.group.index=${axis.variable}" />
</gradle-execute>
</limit>

<move
todir="modules/test-results"
>
<fileset
dir="${test.project.results.dir}"
includes="**/TEST-*.xml"
/>
</move>
</try>
<catch>
<if>
<isset property="test.timeout" />
<then>
<echo>${test.timeout}</echo>
</then>
</if>

<echo>${test.failure.message}</echo>
</catch>
</trycatch>
<run-modules-junit-test test.class="@{test.class}" test.task="testIntegration">
<arg value="--continue" />
<arg value="-Dbuild.exclude.ant.plugin=true" />
<arg value="-Dtest.class.group.index=${axis.variable}" />
</run-modules-junit-test>
</sequential>
</for>

Expand Down Expand Up @@ -2735,6 +2706,86 @@ log.sanitizer.enabled=false</echo>
</sequential>
</macrodef>

<macrodef name="run-modules-junit-test">
<attribute name="test.class" />
<attribute name="test.task" />

<element implicit="true" name="args" optional="true" />

<sequential>
<var name="test.timeout" unset="true" />

<trycatch property="test.failure.message">
<try>
<get-test-project-information test.class="@{test.class}" />

<limit failonerror="true" maxwait="${test.class.timeout.seconds}" property="test.timeout" value="FAILURE: ${test.project.name}:@{test.task} --tests ${test.name} failed to complete in ${test.class.timeout.minutes} minutes">
<gradle-execute dir="modules" task="${test.project.name}:@{test.task}" test.name="${test.name}">
<args />
</gradle-execute>
</limit>

<move
flatten="true"
todir="modules/test-results"
>
<fileset
dir="${test.project.results.dir}"
includes="**/TEST-*.xml"
/>
</move>
</try>
<catch>
<var name="junit.failure.message" value="" />

<if>
<isset property="test.timeout" />
<then>
<var name="junit.failure.message" value="${test.timeout}${line.separator}" />
</then>
</if>

<var name="junit.failure.message" value="${junit.failure.message}${test.failure.message}" />

<echo>${junit.failure.message}</echo>

<var name="junit.failure.message.element" unset="true" />

<property name="junit.failure.message" value="${test.failure.message}${test.timeout}" />

<get-junit-failure-message-element />

<local name="test.class.name" />

<propertyregex
input="@{test.class}"
override="true"
property="test.class.name"
regexp="(.*)\.class"
replace="\1"
/>

<propertyregex
global="true"
input="${test.class.name}"
override="true"
property="test.class.name"
regexp="/"
replace="."
/>

<generate-backend-batch-junit-report
junit.failure.count="1"
junit.failure.message.element="${junit.failure.message.element}"
test.class.name="${test.class.name}"
test.command.name="testCompile"
test.results.dir="modules/test-results"
/>
</catch>
</trycatch>
</sequential>
</macrodef>

<macrodef name="run-poshi-validation">
<sequential>
<antcall target="run-poshi-validation" />
Expand Down Expand Up @@ -6992,43 +7043,14 @@ information. Make sure to commit in all format-javadoc results.

<for list="${test.class.group}" param="test.class">
<sequential>
<local name="test.timeout" />

<trycatch property="test.failure.message">
<try>
<get-test-project-information test.class="@{test.class}" />

<limit failonerror="true" maxwait="${test.class.timeout.seconds}" property="test.timeout" value="FAILURE: ${test.project.name}:test --tests ${test.name} failed to complete in ${test.class.timeout.minutes} minutes">
<gradle-execute dir="modules" task="${test.project.name}:test" test.name="${test.name}">
<arg value="--continue" />
<arg value="-Dbuild.exclude.ant.plugin=true" />
<arg if:true="${run.solr.unit.tests}" value="-Dcom.liferay.portal.search.solr8.test.unit.started=true" />
<arg value="-Djunit.code.coverage=${test.batch.code.coverage}" />
<arg if:set="project.templates.test.builds" value="-Dproject.templates.test.builds=${project.templates.test.builds}" />
<arg value="-Dtest.class.group.index=${axis.variable}" />
</gradle-execute>
</limit>

<move
todir="modules/test-results"
>
<fileset
dir="${test.project.results.dir}"
includes="**/TEST-*.xml"
/>
</move>
</try>
<catch>
<if>
<isset property="test.timeout" />
<then>
<echo>${test.timeout}</echo>
</then>
</if>

<echo>${test.failure.message}</echo>
</catch>
</trycatch>
<run-modules-junit-test test.class="@{test.class}" test.task="test">
<arg value="--continue" />
<arg value="-Dbuild.exclude.ant.plugin=true" />
<arg if:true="${run.solr.unit.tests}" value="-Dcom.liferay.portal.search.solr8.test.unit.started=true" />
<arg value="-Djunit.code.coverage=${test.batch.code.coverage}" />
<arg if:set="project.templates.test.builds" value="-Dproject.templates.test.builds=${project.templates.test.builds}" />
<arg value="-Dtest.class.group.index=${axis.variable}" />
</run-modules-junit-test>
</sequential>
</for>

Expand Down

0 comments on commit 78ffb34

Please sign in to comment.