Skip to content

Commit 2ccffb7

Browse files
committed
Add GoogleTest support from David Hallas
1 parent 534c6f3 commit 2ccffb7

File tree

8 files changed

+205
-0
lines changed

8 files changed

+205
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.jenkinsci.plugins.xunit.types;
2+
3+
import com.thalesgroup.dtkit.junit.model.JUnitModel;
4+
import com.thalesgroup.dtkit.metrics.model.InputMetricXSL;
5+
import com.thalesgroup.dtkit.metrics.model.InputType;
6+
import com.thalesgroup.dtkit.metrics.model.OutputMetric;
7+
8+
/**
9+
* @author David Hallas
10+
*/
11+
public class GoogleTestInputMetric extends InputMetricXSL {
12+
13+
@Override
14+
public InputType getToolType() {
15+
return InputType.TEST;
16+
}
17+
18+
@Override
19+
public String getToolVersion() {
20+
return "1.6";
21+
}
22+
23+
@Override
24+
public String getToolName() {
25+
return "GoogleTest";
26+
}
27+
28+
@Override
29+
public boolean isDefault() {
30+
return false;
31+
}
32+
33+
@Override
34+
public String getXslName() {
35+
return "googletest-to-junit-4.xsl";
36+
}
37+
38+
@Override
39+
public String[] getInputXsdNameList() {
40+
return null;
41+
}
42+
43+
@Override
44+
public OutputMetric getOutputFormatType() {
45+
return JUnitModel.OUTPUT_JUNIT_4;
46+
}
47+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.jenkinsci.plugins.xunit.types;
2+
3+
import com.thalesgroup.dtkit.metrics.hudson.api.descriptor.TestTypeDescriptor;
4+
import com.thalesgroup.dtkit.metrics.hudson.api.type.TestType;
5+
import com.thalesgroup.dtkit.metrics.model.InputMetric;
6+
import com.thalesgroup.dtkit.metrics.model.InputMetricException;
7+
import com.thalesgroup.dtkit.metrics.model.InputMetricFactory;
8+
import hudson.Extension;
9+
import org.kohsuke.stapler.DataBoundConstructor;
10+
11+
/**
12+
* @author David Hallas
13+
*/
14+
public class GoogleTestType extends TestType {
15+
16+
@DataBoundConstructor
17+
public GoogleTestType(String pattern, boolean ignoreNoResultFiles, boolean failIfNotNew, boolean deleteOutputFiles, boolean stopProcessingIfError) {
18+
super(pattern, ignoreNoResultFiles, failIfNotNew, deleteOutputFiles, stopProcessingIfError);
19+
}
20+
21+
@Extension
22+
public static class GoogleTestTypeDescriptor extends TestTypeDescriptor<GoogleTestType> {
23+
24+
public GoogleTestTypeDescriptor() {
25+
super(GoogleTestType.class, null);
26+
}
27+
28+
@Override
29+
public String getId() {
30+
return this.getClass().getName();
31+
}
32+
33+
@Override
34+
public InputMetric getInputMetric() {
35+
try {
36+
return InputMetricFactory.getInstance(GoogleTestInputMetric.class);
37+
} catch (InputMetricException e) {
38+
throw new RuntimeException("Can't create the inputMetric object for the class " + GoogleTestInputMetric.class);
39+
}
40+
}
41+
}
42+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!-- from src/main/resources/org/jenkinsci/plugins/xunit/types/googletest-to-junit-4.xsl -->
2+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3+
<xsl:output method="xml" indent="yes" cdata-section-elements="system-out"/>
4+
<xsl:template match="/">
5+
<xsl:apply-templates/>
6+
</xsl:template>
7+
<xsl:template match="//testsuites">
8+
<testsuites>
9+
<xsl:apply-templates/>
10+
</testsuites>
11+
</xsl:template>
12+
<xsl:template match="//testsuite">
13+
<testsuite>
14+
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
15+
<xsl:attribute name="tests"><xsl:value-of select="@tests"/></xsl:attribute>
16+
<xsl:apply-templates select="testcase"/>
17+
</testsuite>
18+
</xsl:template>
19+
<xsl:template match="//testcase">
20+
<testcase>
21+
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
22+
<xsl:attribute name="time"><xsl:value-of select="@time"/></xsl:attribute>
23+
<xsl:attribute name="classname"><xsl:value-of select="@classname"/></xsl:attribute>
24+
<xsl:if test="@status = 'notrun'">
25+
<skipped/>
26+
</xsl:if>
27+
<xsl:apply-templates select="failure"/>
28+
</testcase>
29+
</xsl:template>
30+
<xsl:template match="//failure">
31+
<failure>
32+
<xsl:value-of select="@message"/>
33+
</failure>
34+
<system-out>
35+
<xsl:value-of select="."/>
36+
</system-out>
37+
</xsl:template>
38+
<!-- this swallows all unmatched text -->
39+
<!-- <xsl:template match="text()|@*"/>-->
40+
</xsl:stylesheet>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.jenkinsci.plugins.xunit.types;
2+
3+
import org.junit.Test;
4+
5+
/**
6+
* @author David Hallas
7+
*/
8+
public class GoogleTestTypeTest extends AbstractTest {
9+
10+
@Test
11+
public void testTestCase1() throws Exception {
12+
convertAndValidate(GoogleTestInputMetric.class, "googletest/testcase1/input.xml", "googletest/testcase1/result.xml");
13+
}
14+
@Test
15+
public void testTestCase2() throws Exception {
16+
convertAndValidate(GoogleTestInputMetric.class, "googletest/testcase2/input.xml", "googletest/testcase2/result.xml");
17+
}
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites tests="3" failures="0" disabled="0" errors="0" time="0.042" name="AllTests">
3+
<testsuite name="TestAbsTimer" tests="2" failures="0" disabled="0" errors="0" time="0.001">
4+
<testcase name="Basic" status="run" time="0.001" classname="TestAbsTimer" />
5+
<testcase name="InvalidTime" status="run" time="0.3" classname="TestAbsTimer" />
6+
</testsuite>
7+
<testsuite name="AppCreator" tests="1" failures="0" disabled="0" errors="0" time="0">
8+
<testcase name="Basic" status="run" time="1.42" classname="AppCreator" />
9+
</testsuite>
10+
</testsuites>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="TestAbsTimer" tests="2">
4+
<testcase name="Basic" time="0.001" classname="TestAbsTimer"/>
5+
<testcase name="InvalidTime" time="0.3" classname="TestAbsTimer"/>
6+
</testsuite>
7+
<testsuite name="AppCreator" tests="1">
8+
<testcase name="Basic" time="1.42" classname="AppCreator"/>
9+
</testsuite>
10+
</testsuites>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites tests="4" failures="2" disabled="1" errors="0" time="0" name="AllTests">
3+
<testsuite name="TestSuite" tests="4" failures="2" disabled="1" errors="0" time="0">
4+
<testcase name="Ok_Testcase" status="run" time="0" classname="TestSuite" />
5+
<testcase name="Failing_Testcase" status="run" time="0" classname="TestSuite">
6+
<failure message="Value of: false&#x0A; Actual: false&#x0A;Expected: true" type=""><![CDATA[Test_moca_bl.cpp:271
7+
Value of: false
8+
Actual: false
9+
Expected: true]]></failure>
10+
</testcase>
11+
<testcase name="Error_Testcase" status="run" time="0" classname="TestSuite">
12+
<failure message="Unknown C++ exception thrown in the test body." type=""><![CDATA[unknown file
13+
Unknown C++ exception thrown in the test body.]]></failure>
14+
</testcase>
15+
<testcase name="DISABLED_Testcase" status="notrun" time="0" classname="TestSuite" />
16+
</testsuite>
17+
</testsuites>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="TestSuite" tests="4">
4+
<testcase name="Ok_Testcase" time="0" classname="TestSuite"/>
5+
<testcase name="Failing_Testcase" time="0" classname="TestSuite">
6+
<failure>Value of: false&#x0A; Actual: false&#x0A;Expected: true</failure>
7+
<system-out><![CDATA[Test_moca_bl.cpp:271
8+
Value of: false
9+
Actual: false
10+
Expected: true]]></system-out>
11+
</testcase>
12+
<testcase name="Error_Testcase" time="0" classname="TestSuite">
13+
<failure>Unknown C++ exception thrown in the test body.</failure>
14+
<system-out><![CDATA[unknown file
15+
Unknown C++ exception thrown in the test body.]]></system-out>
16+
</testcase>
17+
<testcase name="DISABLED_Testcase" time="0" classname="TestSuite">
18+
<skipped/>
19+
</testcase>
20+
</testsuite>
21+
</testsuites>

0 commit comments

Comments
 (0)