Skip to content

Commit

Permalink
Fix JENKINS-17884
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed May 13, 2013
1 parent 9151adf commit c991264
Show file tree
Hide file tree
Showing 6 changed files with 517 additions and 0 deletions.
@@ -0,0 +1,47 @@
package org.jenkinsci.plugins.xunit.types;

import com.thalesgroup.dtkit.junit.model.JUnitModel;
import com.thalesgroup.dtkit.metrics.model.InputMetricXSL;
import com.thalesgroup.dtkit.metrics.model.InputType;
import com.thalesgroup.dtkit.metrics.model.OutputMetric;

/**
* @author Gregory Boissinot
*/
public class CTestInputMetric extends InputMetricXSL {

@Override
public InputType getToolType() {
return InputType.TEST;
}

@Override
public String getToolVersion() {
return "Version N/A";
}

@Override
public String getToolName() {
return "CTest";
}

@Override
public boolean isDefault() {
return true;
}

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

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

@Override
public OutputMetric getOutputFormatType() {
return JUnitModel.OUTPUT_JUNIT_5;
}
}
43 changes: 43 additions & 0 deletions src/main/java/org/jenkinsci/plugins/xunit/types/CTestType.java
@@ -0,0 +1,43 @@
package org.jenkinsci.plugins.xunit.types;

import com.thalesgroup.dtkit.metrics.hudson.api.descriptor.TestTypeDescriptor;
import com.thalesgroup.dtkit.metrics.hudson.api.type.TestType;
import com.thalesgroup.dtkit.metrics.model.InputMetric;
import com.thalesgroup.dtkit.metrics.model.InputMetricException;
import com.thalesgroup.dtkit.metrics.model.InputMetricFactory;
import hudson.Extension;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* @author Gregory Boissinot
*/
public class CTestType extends TestType {

@DataBoundConstructor
public CTestType(String pattern, boolean ignoreNoResultFiles, boolean failIfNotNew, boolean deleteOutputFiles, boolean stopProcessingIfError) {
super(pattern, failIfNotNew, ignoreNoResultFiles, deleteOutputFiles, stopProcessingIfError);
}

@Extension
public static class CTestTypeDescriptor extends TestTypeDescriptor<CTestType> {

public CTestTypeDescriptor() {
super(CTestType.class, null);
}

@Override
public String getId() {
return this.getClass().getName();
}

@Override
public InputMetric getInputMetric() {
try {
return InputMetricFactory.getInstance(CTestInputMetric.class);
} catch (InputMetricException e) {
throw new RuntimeException("Can't create the inputMetric object for the class " + CTestInputMetric.class);
}
}
}
}

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<testsuites>
<xsl:variable name="buildName" select="//Site/@BuildName"/>
<xsl:variable name="numberOfTests" select="count(//Site/Testing/Test)"/>
<xsl:variable name="numberOfFailures" select="count(//Site/Testing/Test[@Status!='passed'])"/>
<testsuite name="CTest"
tests="{$numberOfTests}" time="0"
failures="{$numberOfFailures}" errors="0"
skipped="0">
<xsl:for-each select="//Site/Testing/Test">
<xsl:variable name="testName" select="translate(Name, '-', '_')"/>
<xsl:variable name="duration" select="Results/NamedMeasurement[@name='Execution Time']/Value"/>
<xsl:variable name="status" select="@Status"/>
<xsl:variable name="output" select="Results/Measurement/Value"/>
<xsl:variable name="className" select="translate(Path, '/.', '.')"/>
<testcase classname="projectroot{$className}"
name="{$testName}"
time="{$duration}">
<xsl:if test="@Status!='passed'">
<failure>
<xsl:value-of select="$output"/>
</failure>
</xsl:if>
<system-out>
<xsl:value-of select="$output"/>
</system-out>
</testcase>
</xsl:for-each>
</testsuite>
</testsuites>
</xsl:template>
</xsl:stylesheet>
15 changes: 15 additions & 0 deletions src/test/java/org/jenkinsci/plugins/xunit/types/CTestTest.java
@@ -0,0 +1,15 @@
package org.jenkinsci.plugins.xunit.types;

import org.junit.Test;

/**
* @author Gregory Boissinot
*/
public class CTestTest extends AbstractTest {

@Test
public void testTestCase1() throws Exception {
convertAndValidate(CTestInputMetric.class, "ctest/testcase1/input.xml", "ctest/testcase1/result.xml");
}

}

0 comments on commit c991264

Please sign in to comment.