Permalink
Browse files

[JENKINS-51797] xUnit.Net v2 parse error when time attribute is missing

Fix junit time function when is time attribute is empty
  • Loading branch information...
Nikolas Falco
Nikolas Falco committed Jun 8, 2018
1 parent 354a598 commit 2c18ed76cc2fc5aa06bbf919ad59627b1f0b6396
Showing with 150 additions and 92 deletions.
  1. +2 −1 src/main/java/org/jenkinsci/plugins/xunit/types/XUnitDotNet.java
  2. +12 −12 src/main/resources/org/jenkinsci/plugins/xunit/types/cpptestunit-2.0-to-junit.xsl
  3. +3 −3 src/main/resources/org/jenkinsci/plugins/xunit/types/ctest-to-junit.xsl
  4. +2 −2 src/main/resources/org/jenkinsci/plugins/xunit/types/fpcunit-1.0-to-junit.xsl
  5. +8 −2 src/main/resources/org/jenkinsci/plugins/xunit/types/mbunit-to-junit-4.xsl
  6. +9 −2 src/main/resources/org/jenkinsci/plugins/xunit/types/mstest-1.0-to-junit-1.0.xsl
  7. +5 −4 src/main/resources/org/jenkinsci/plugins/xunit/types/nunit-2.x-to-junit.xsl
  8. +9 −2 src/main/resources/org/jenkinsci/plugins/xunit/types/nunit-3.0-to-junit.xsl
  9. +14 −9 src/main/resources/org/jenkinsci/plugins/xunit/types/phpunit-1.0-to-junit-4.0.xsl
  10. +14 −2 src/main/resources/org/jenkinsci/plugins/xunit/types/qtestlib-5.0-to-junit-1.0.xsl
  11. +8 −3 src/main/resources/org/jenkinsci/plugins/xunit/types/unittest-1.1-to-junit.xsl
  12. +16 −11 ...org/jenkinsci/plugins/xunit/types/{xunitdotnet-2.0-to-junit-2.xsl → xunitdotnet-2.0-to-junit.xsl}
  13. +2 −1 src/test/java/org/jenkinsci/plugins/xunit/types/XUnitDotNetTest.java
  14. +14 −19 src/test/resources/org/jenkinsci/plugins/xunit/types/xunitdotnet/testcase1/result.xml
  15. +14 −19 src/test/resources/org/jenkinsci/plugins/xunit/types/xunitdotnet/testcase3/result.xml
  16. +8 −0 src/test/resources/org/jenkinsci/plugins/xunit/types/xunitdotnet/testcase4/input.xml
  17. +10 −0 src/test/resources/org/jenkinsci/plugins/xunit/types/xunitdotnet/testcase4/result.xml
@@ -53,14 +53,15 @@ public boolean isDefault() {

@Override
public String getXslName() {
return "xunitdotnet-2.0-to-junit-2.xsl";
return "xunitdotnet-2.0-to-junit.xsl";
}

@Override
public String[] getInputXsdNameList() {
return null;
}

@Override
public OutputMetric getOutputFormatType() {
return JUnitModel.LATEST;
}
@@ -35,25 +35,16 @@ THE SOFTWARE.
<xsl:value-of select="$value" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(string($value), ',', '.')" />
<xsl:value-of select="translate(string(xunit:if-empty($value, 0)), ',', '.')" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="format-number($time, '0.000')" />
</xsl:function>

<xsl:function name="xunit:millis-from-time" as="xs:double">
<xsl:param name="value" as="xs:string?" />

<xsl:variable name="formattedTime" select="xunit:if-empty(string($value), '00:00:00')" />
<xsl:variable name="formattedTime" select="replace(translate($formattedTime,',','.'), '^(\d:.+)', '0$1')" />
<xsl:variable name="time" select="xs:time($formattedTime)" />
<xsl:value-of select="hours-from-time($time)*3600 + minutes-from-time($time)*60 + seconds-from-time($time)" />
</xsl:function>

<xsl:function name="xunit:if-empty" as="xs:string">
<xsl:param name="value" as="xs:string?" />
<xsl:param name="default" as="xs:anyAtomicType?" />
<xsl:param name="value" as="xs:anyAtomicType?" />
<xsl:param name="default" as="xs:anyAtomicType" />
<xsl:value-of select="if (string($value) != '') then string($value) else $default" />
</xsl:function>

@@ -62,6 +53,15 @@ THE SOFTWARE.
<xsl:value-of select="string($value) != ''" />
</xsl:function>

<xsl:function name="xunit:millis-from-time" as="xs:double">
<xsl:param name="value" as="xs:string?" />

<xsl:variable name="formattedTime" select="xunit:if-empty(string($value), '00:00:00')" />
<xsl:variable name="formattedTime" select="replace(translate($formattedTime,',','.'), '^(\d:.+)', '0$1')" />
<xsl:variable name="time" select="xs:time($formattedTime)" />
<xsl:value-of select="hours-from-time($time)*3600 + minutes-from-time($time)*60 + seconds-from-time($time)" />
</xsl:function>

<xsl:key name="testCaseId" match="/ResultsSession/Exec/ExecViols/ExecViol" use="@testCaseId" />

<xsl:template match="/">
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xunit="http://www.xunit.org">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:output method="xml" indent="yes" encoding="UTF-8" cdata-section-elements="system-out system-err failure"/>
<xsl:decimal-format decimal-separator="." grouping-separator=","/>

<xsl:function name="xunit:junit-time" as="xs:string">
@@ -35,15 +35,15 @@ THE SOFTWARE.
<xsl:value-of select="$value" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(string($value), ',', '.')" />
<xsl:value-of select="translate(string(xunit:if-empty($value, 0)), ',', '.')" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="format-number($time, '0.000')" />
</xsl:function>

<xsl:function name="xunit:if-empty" as="xs:string">
<xsl:param name="value" as="xs:string?" />
<xsl:param name="value" as="xs:anyAtomicType?" />
<xsl:param name="default" as="xs:anyAtomicType" />
<xsl:value-of select="if (string($value) != '') then string($value) else $default" />
</xsl:function>
@@ -43,8 +43,8 @@ THE SOFTWARE.
</xsl:function>

<xsl:function name="xunit:if-empty" as="xs:string">
<xsl:param name="value" as="xs:string?" />
<xsl:param name="default" as="xs:anyAtomicType?" />
<xsl:param name="value" as="xs:anyAtomicType?" />
<xsl:param name="default" as="xs:anyAtomicType" />
<xsl:value-of select="if (string($value) != '') then string($value) else $default" />
</xsl:function>

@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xunit="http://www.xunit.org">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:output method="xml" indent="yes" encoding="UTF-8" cdata-section-elements="system-out system-err failure"/>
<xsl:decimal-format decimal-separator="." grouping-separator=","/>

<xsl:function name="xunit:junit-time" as="xs:string">
@@ -35,13 +35,19 @@ THE SOFTWARE.
<xsl:value-of select="$value" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(string($value), ',', '.')" />
<xsl:value-of select="translate(string(xunit:if-empty($value, 0)), ',', '.')" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="format-number($time, '0.000')" />
</xsl:function>

<xsl:function name="xunit:if-empty" as="xs:string">
<xsl:param name="value" as="xs:anyAtomicType?" />
<xsl:param name="default" as="xs:anyAtomicType" />
<xsl:value-of select="if (string($value) != '') then string($value) else $default" />
</xsl:function>

<xsl:function name="xunit:is-empty" as="xs:boolean">
<xsl:param name="value" as="xs:string?" />
<xsl:value-of select="string($value) != ''" />
@@ -25,7 +25,7 @@ THE SOFTWARE.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xunit="http://www.xunit.org"
xmlns:a="http://microsoft.com/schemas/VisualStudio/TeamTest/2006" xmlns:b="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">

<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:output method="xml" indent="yes" encoding="UTF-8" cdata-section-elements="system-out system-err failure"/>
<xsl:decimal-format decimal-separator="." grouping-separator=","/>

<xsl:function name="xunit:junit-time" as="xs:string">
@@ -37,18 +37,25 @@ THE SOFTWARE.
<xsl:value-of select="$value" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(string($value), ',', '.')" />
<xsl:value-of select="translate(string(xunit:if-empty($value, 0)), ',', '.')" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="format-number($time, '0.000')" />
</xsl:function>

<xsl:function name="xunit:if-empty" as="xs:string">
<xsl:param name="value" as="xs:anyAtomicType?" />
<xsl:param name="default" as="xs:anyAtomicType" />
<xsl:value-of select="if (string($value) != '') then string($value) else $default" />
</xsl:function>

<xsl:function name="xunit:is-empty" as="xs:boolean">
<xsl:param name="value" as="xs:string?" />
<xsl:value-of select="string($value) != ''" />
</xsl:function>


<xsl:template match="/">
<testsuites>
<xsl:variable name="numberOfTests" select="sum(/a:TestRun/a:ResultSummary/a:Counters/@total | /b:TestRun/b:ResultSummary/b:Counters/@total)"/>
@@ -23,10 +23,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xunit="http://www.xunit.org">
<xsl:output method="xml" indent="yes" encoding="UTF-8" cdata-section-elements="failure error system-out system-err"/>
<xsl:output method="xml" indent="yes" encoding="UTF-8" cdata-section-elements="system-out system-err failure"/>
<xsl:decimal-format decimal-separator="." grouping-separator=","/>

<xsl:function name="xunit:junit-time" as="xs:string">
<xsl:function name="xunit:junit-time" as="xs:string">
<xsl:param name="value" as="xs:anyAtomicType?" />

<xsl:variable name="time" as="xs:double">
@@ -35,15 +35,15 @@ THE SOFTWARE.
<xsl:value-of select="$value" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(string($value), ',', '.')" />
<xsl:value-of select="translate(string(xunit:if-empty($value, 0)), ',', '.')" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="format-number($time, '0.000')" />
</xsl:function>

<xsl:function name="xunit:if-empty" as="xs:string">
<xsl:param name="value" as="xs:string?" />
<xsl:param name="value" as="xs:anyAtomicType?" />
<xsl:param name="default" as="xs:anyAtomicType" />
<xsl:value-of select="if (string($value) != '') then string($value) else $default" />
</xsl:function>
@@ -53,6 +53,7 @@ THE SOFTWARE.
<xsl:value-of select="string($value) != ''" />
</xsl:function>


<xsl:template match="/test-results">
<testsuites>
<xsl:for-each select="//test-suite">
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xunit="http://www.xunit.org">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:output method="xml" indent="yes" encoding="UTF-8" cdata-section-elements="system-out system-err failure"/>
<xsl:decimal-format decimal-separator="." grouping-separator=","/>

<xsl:function name="xunit:junit-time" as="xs:string">
@@ -35,18 +35,25 @@ THE SOFTWARE.
<xsl:value-of select="$value" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(string($value), ',', '.')" />
<xsl:value-of select="translate(string(xunit:if-empty($value, 0)), ',', '.')" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="format-number($time, '0.000')" />
</xsl:function>

<xsl:function name="xunit:if-empty" as="xs:string">
<xsl:param name="value" as="xs:anyAtomicType?" />
<xsl:param name="default" as="xs:anyAtomicType" />
<xsl:value-of select="if (string($value) != '') then string($value) else $default" />
</xsl:function>

<xsl:function name="xunit:is-empty" as="xs:boolean">
<xsl:param name="value" as="xs:string?" />
<xsl:value-of select="string($value) != ''" />
</xsl:function>


<xsl:template match="/test-run">
<!--<xsl:variable name="hostname" select="./environment/@machine-name"/>-->
<testsuites>
@@ -23,16 +23,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xunit="http://www.xunit.org">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:output method="xml" indent="yes" encoding="UTF-8" cdata-section-elements="system-out system-err failure"/>
<xsl:decimal-format decimal-separator="." grouping-separator=","/>

<xsl:function name="xunit:if-empty" as="xs:string">
<xsl:param name="value" as="xs:string?" />
<xsl:param name="default" as="xs:anyAtomicType" />
<xsl:value-of select="if (string($value) != '') then string($value) else $default" />
</xsl:function>

<xsl:function name="xunit:junit-time" as="xs:string">
<xsl:param name="value" as="xs:anyAtomicType?" />

@@ -42,13 +35,25 @@ THE SOFTWARE.
<xsl:value-of select="$value" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(string($value), ',', '.')" />
<xsl:value-of select="translate(string(xunit:if-empty($value, 0)), ',', '.')" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="format-number($time, '0.000')" />
</xsl:function>

<xsl:function name="xunit:if-empty" as="xs:string">
<xsl:param name="value" as="xs:anyAtomicType?" />
<xsl:param name="default" as="xs:anyAtomicType" />
<xsl:value-of select="if (string($value) != '') then string($value) else $default" />
</xsl:function>

<xsl:function name="xunit:is-empty" as="xs:boolean">
<xsl:param name="value" as="xs:string?" />
<xsl:value-of select="string($value) != ''" />
</xsl:function>


<xsl:template match="testsuite">

<xsl:if test="testcase">
@@ -24,7 +24,7 @@ THE SOFTWARE.
-->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xunit="http://www.xunit.org">
<!-- for details interpreting unit test results http://qt-project.org/wiki/Writing_Unit_Tests -->
<xsl:output method="xml" indent="yes"/>
<xsl:output method="xml" indent="yes" encoding="UTF-8" cdata-section-elements="system-out system-err failure"/>
<xsl:decimal-format decimal-separator="." grouping-separator=","/>

<xsl:function name="xunit:junit-time" as="xs:string">
@@ -36,13 +36,25 @@ THE SOFTWARE.
<xsl:value-of select="$value" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(string($value), ',', '.')" />
<xsl:value-of select="translate(string(xunit:if-empty($value, 0)), ',', '.')" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="format-number($time, '0.000')" />
</xsl:function>

<xsl:function name="xunit:if-empty" as="xs:string">
<xsl:param name="value" as="xs:anyAtomicType?" />
<xsl:param name="default" as="xs:anyAtomicType" />
<xsl:value-of select="if (string($value) != '') then string($value) else $default" />
</xsl:function>

<xsl:function name="xunit:is-empty" as="xs:boolean">
<xsl:param name="value" as="xs:string?" />
<xsl:value-of select="string($value) != ''" />
</xsl:function>


<!-- misc variables -->
<xsl:variable name="classname" select="/TestCase/@name"/>
<xsl:variable name="total-tests" select="count(/TestCase/TestFunction)"/>
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xunit="http://www.xunit.org">
<xsl:output method="xml" indent="yes" encoding="UTF-8" cdata-section-elements="failure error system-out system-err"/>
<xsl:output method="xml" indent="yes" encoding="UTF-8" cdata-section-elements="system-out system-err failure"/>
<xsl:decimal-format decimal-separator="." grouping-separator=","/>

<xsl:function name="xunit:junit-time" as="xs:string">
@@ -35,19 +35,24 @@ THE SOFTWARE.
<xsl:value-of select="$value" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(string($value), ',', '.')" />
<xsl:value-of select="translate(string(xunit:if-empty($value, 0)), ',', '.')" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="format-number($time, '0.000')" />
</xsl:function>

<xsl:function name="xunit:if-empty" as="xs:string">
<xsl:param name="value" as="xs:string?" />
<xsl:param name="value" as="xs:anyAtomicType?" />
<xsl:param name="default" as="xs:anyAtomicType" />
<xsl:value-of select="if (string($value) != '') then string($value) else $default" />
</xsl:function>

<xsl:function name="xunit:is-empty" as="xs:boolean">
<xsl:param name="value" as="xs:string?" />
<xsl:value-of select="string($value) != ''" />
</xsl:function>

<xsl:template match="/">
<testsuite>
<xsl:attribute name="errors">
Oops, something went wrong.

0 comments on commit 2c18ed7

Please sign in to comment.