Skip to content

Commit

Permalink
[JENKINS-51797] xUnit.Net v2 parse error when time attribute is missing
Browse files Browse the repository at this point in the history
Fix junit time function when is time attribute is empty
  • Loading branch information
Nikolas Falco committed Jun 8, 2018
1 parent 354a598 commit 2c18ed7
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 92 deletions.
Expand Up @@ -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;
}
Expand Down
Expand Up @@ -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>

Expand All @@ -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="/">
Expand Down
Expand Up @@ -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">
Expand All @@ -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>
Expand Down
Expand Up @@ -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>

Expand Down
Expand Up @@ -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">
Expand All @@ -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) != ''" />
Expand Down
Expand Up @@ -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">
Expand All @@ -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)"/>
Expand Down
Expand Up @@ -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">
Expand All @@ -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>
Expand All @@ -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">
Expand Down
Expand Up @@ -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">
Expand All @@ -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>
Expand Down
Expand Up @@ -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?" />

Expand All @@ -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">
Expand Down
Expand Up @@ -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">
Expand All @@ -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)"/>
Expand Down
Expand Up @@ -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">
Expand All @@ -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">
Expand Down

0 comments on commit 2c18ed7

Please sign in to comment.