Skip to content

Commit

Permalink
[JENKINS-51798] GoogleTest 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 2c18ed7 commit 44589f4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
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="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,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 All @@ -61,16 +67,16 @@ THE SOFTWARE.
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:attribute name="tests">
<xsl:value-of select="@tests"/>
<xsl:value-of select="xunit:if-empty(@tests, 0)"/>
</xsl:attribute>
<xsl:attribute name="failures">
<xsl:value-of select="@failures"/>
<xsl:value-of select="xunit:if-empty(@failures, 0)"/>
</xsl:attribute>
<xsl:attribute name="errors">
<xsl:value-of select="@errors"/>
<xsl:value-of select="xunit:if-empty(@errors, 0)"/>
</xsl:attribute>
<xsl:attribute name="skipped">
<xsl:value-of select="@disabled"/>
<xsl:value-of select="xunit:if-empty(@disabled, 0)"/>
</xsl:attribute>
<xsl:attribute name="time">
<xsl:value-of select="xunit:junit-time(@time)"/>
Expand Down
Expand Up @@ -32,16 +32,17 @@
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class GoogleTestTypeTest extends AbstractTest {
public class GoogleTestTest extends AbstractTest {

@Parameters(name = "testcase{1}: {0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] { { "testTestCase1", 1 }, //
{ "testTestCase2", 2 } //
{ "testTestCase2", 2 }, //
{ "JENKINS-51798 ", 3 }, //
});
}

public GoogleTestTypeTest(String testName, int testNumber) {
public GoogleTestTest(String testName, int testNumber) {
super(GoogleTestInputMetric.class, resolveInput("googletest", testNumber), resolveOutput("googletest", testNumber));
}

Expand Down
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?><testsuite name="nosetests" tests="3" errors="0" failures="0" skip="0"><testcase classname="test.test_xxx.TestAlternative" name="test_alternative" time="0.011"><system-out><![CDATA[Test data stripped out.
]]></system-out></testcase><testcase classname="test.test_xxx.TestAlternative" name="test_low" time="0.009"><system-out><![CDATA[Test data stripped out.
]]></system-out></testcase><testcase classname="test.test_xxx.TestAlternative" name="test_high" time="0.010"><system-out><![CDATA[Test data stripped out.
]]></system-out></testcase><testcase classname="test.test_book_gripper_alternative.TestAlternative" name="test_box_length_known_book" time="0.004"><system-out><![CDATA[Test data stripped out.
]]></system-out></testcase></testsuite>
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="nosetests" tests="3" failures="0" errors="0" skipped="0" time="0.000">
<testcase name="test_alternative" time="0.011" classname="test.test_xxx.TestAlternative" />
<testcase name="test_low" time="0.009" classname="test.test_xxx.TestAlternative" />
<testcase name="test_high" time="0.010" classname="test.test_xxx.TestAlternative" />
<testcase name="test_box_length_known_book" time="0.004" classname="test.test_book_gripper_alternative.TestAlternative" />
</testsuite>

0 comments on commit 44589f4

Please sign in to comment.