Permalink
Browse files

[JENKINS-12417] xUnit problems with CppTest reports generated with

default options

The default CLI options seems not produce the ExecutedTestsDetails
element in the output report where are described test suites. In absense
of ExecutedTestsDetails we try to do our best to generate all testcase
elements from ExecViols. The number of testcase could differs from the
total count of executed test.
  • Loading branch information...
nfalco79 committed May 20, 2018
1 parent cd5367f commit c9cecd58f640ed8dda0c8859c3fcbae5a063c4d5
@@ -38,7 +38,8 @@ THE SOFTWARE.
<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(replace(translate($value,',','.'), '^(\d:.+)', '0$1'), '00:00:00')" />
<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>
@@ -54,6 +55,8 @@ THE SOFTWARE.
<xsl:value-of select="string($value) != ''" />
</xsl:function>

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

<xsl:template match="/">
<xsl:variable name="testCount" select="ResultsSession/Exec/Summary/Projects/Project/@testCases" />
<xsl:variable name="failureCount" select="ResultsSession/Exec/Summary/Projects/Project/@fail" />
@@ -73,7 +76,6 @@ THE SOFTWARE.
</testsuite>
</xsl:when>
<xsl:when test="ResultsSession/ExecutedTestsDetails">
<!-- CppTest 9.x -->
<testsuites name="{$suiteName}"
time="{$totalTime}"
tests="{$testCount}"
@@ -84,7 +86,7 @@ THE SOFTWARE.
</testsuites>
</xsl:when>
<xsl:otherwise>
<!-- CppTest 7.x -->
<!-- CppTest 7.x no CLI options-->
<testsuite name="{$suiteName}"
time="{$totalTime}"
tests="{$testCount}"
@@ -100,12 +102,14 @@ THE SOFTWARE.
<xsl:template name="TestCase_7x">
<xsl:param name="violations" />

<xsl:for-each select="$violations/ExecViol">
<xsl:for-each select="$violations/ExecViol[generate-id() = generate-id(key('testCaseId', @testCaseId)[1])]">
<xsl:variable name="suiteName" select="substring-before(@testName, '::')" />
<xsl:variable name="testName" select="substring-after(@testName, '::')" />

<testcase classname="{$suiteName}" name="{$testName}" time="{xunit:junit-time(0)}">
<xsl:apply-templates select="Thr" />
<xsl:if test="@cat != 6">
<xsl:apply-templates select="Thr" />
</xsl:if>
</testcase>
</xsl:for-each>
</xsl:template>
@@ -121,8 +125,14 @@ THE SOFTWARE.
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="suiteTime">
<xsl:for-each select=".//Test/@time">
<xsl:value-of select="xunit:millis-from-time(.)" />
</xsl:for-each>
</xsl:variable>

<testsuite name="{$suiteName}"
time="{xunit:junit-time(0)}"
time="{xunit:junit-time($suiteTime)}"
tests="{@pass + @fail}"
failures="{@fail}">
<xsl:apply-templates select="Test">
@@ -101,7 +101,7 @@ protected void convertAndValidate(Class<? extends InputMetric> metricClass, Stri

inputMetric.convert(inputXMLFile, outputXMLFile);
XMLUnit.setIgnoreWhitespace(true);
Diff myDiff = new Diff(readXmlAsString(new File(this.getClass().getResource(expectedResultPath).toURI())), readXmlAsString(outputXMLFile));
Diff myDiff = new Diff(readXmlAsString(outputXMLFile), readXmlAsString(new File(this.getClass().getResource(expectedResultPath).toURI())));
Assert.assertTrue("XSL transformation did not work " + myDiff, myDiff.similar());

//The generated output file must be valid
@@ -38,7 +38,11 @@
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] { { "testcase1", 1 }, //
{ "mix execution of pass and fail tests", 2 }, //
{ "testcase3", 3 } //
{ "testcase3", 3 }, //
{ "7.x all test successed", 4 }, //
{ "7.x all test succeed, no CLI options", 5 }, //
{ "7.x one test fails with 2 assertions", 6 }, //
{ "7.x one test fails with 1 assertion", 7 }, //
});
}

@@ -1,7 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="hello" time="8.000" tests="1" failures="0">
<testcase classname="TestSuite_helloworld_c_85db5268" name="TestSuite_helloworld_c_85db5268_test_main_1" time="0.000">
<failure type="Outcome" message="Outcome: int _return=0"><![CDATA[
at /hello/tests/autogenerated/srce/TestSuite_helloworld_c.c:32]]></failure>
</testcase>
<testcase classname="TestSuite_helloworld_c_85db5268" name="TestSuite_helloworld_c_85db5268_test_main_1" time="0.000" />
</testsuite>
Oops, something went wrong.

0 comments on commit c9cecd5

Please sign in to comment.