Skip to content

Commit

Permalink
[FIXED JENKINS-24382] Add basic support for CUnit
Browse files Browse the repository at this point in the history
I included Oliver van Porten XSL available here: https://bitbucket.org/mcdeck/cunit-to-junit (MIT license)

Change-Id: Idb23d13b9e656c0d6e7da6a7cf7af5ffdb8ef8e6
  • Loading branch information
etiennebec committed Feb 16, 2016
1 parent a86de8b commit 0655050
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/main/java/org/jenkinsci/plugins/xunit/types/CUnit.java
@@ -0,0 +1,68 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016, Etienne Bec
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.xunit.types;

import org.jenkinsci.lib.dtkit.model.InputMetricXSL;
import org.jenkinsci.lib.dtkit.model.InputType;
import org.jenkinsci.lib.dtkit.model.OutputMetric;
import org.jenkinsci.plugins.xunit.types.model.JUnitModel;

public class CUnit extends InputMetricXSL {

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

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

@Override
public String getToolVersion() {
return "2.1-2";
}

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

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

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

@Override
public OutputMetric getOutputFormatType() {
return JUnitModel.LATEST;
}
}
@@ -0,0 +1,53 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016, Etienne Bec
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (t&he "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.xunit.types;

import hudson.Extension;
import org.jenkinsci.lib.dtkit.descriptor.TestTypeDescriptor;
import org.jenkinsci.lib.dtkit.type.TestType;
import org.kohsuke.stapler.DataBoundConstructor;

public class CUnitJunitHudsonTestType extends TestType {

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

@Extension
public static class DescriptorImpl extends TestTypeDescriptor<CUnitJunitHudsonTestType> {

public DescriptorImpl() {
super(CUnitJunitHudsonTestType.class, CUnit.class);
}

}

@Override
public Object readResolve() {
return super.readResolve();
}

}
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License (MIT)
Copyright (c) 2011 Oliver van Porten
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />

<xsl:param name="suitename" />

<xsl:variable name="cunitCount" select="count(//CUNIT_RUN_TEST_RECORD)"/>
<xsl:variable name="cunitFailureCount" select="count(//CUNIT_RUN_TEST_FAILURE)"/>

<xsl:template match="/">
<testsuites>
<xsl:attribute name="errors">0</xsl:attribute>
<xsl:attribute name="failures">
<xsl:value-of select="$cunitFailureCount"/>
</xsl:attribute>
<xsl:attribute name="tests">
<xsl:value-of select="$cunitCount"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="$suitename" />
</xsl:attribute>
<xsl:apply-templates />
</testsuites>
</xsl:template>

<xsl:template match="/CUNIT_TEST_RUN_REPORT/CUNIT_RESULT_LISTING">
<xsl:for-each select="CUNIT_RUN_SUITE/CUNIT_RUN_SUITE_SUCCESS">
<xsl:variable name="localCunitFailureCount" select="count(CUNIT_RUN_TEST_RECORD/CUNIT_RUN_TEST_FAILURE)"/>
<xsl:variable name="localCunitCount" select="count(CUNIT_RUN_TEST_RECORD)"/>
<xsl:variable name="sn" select="normalize-space(SUITE_NAME/text())"/>
<testsuite>
<xsl:attribute name="errors">0</xsl:attribute>
<xsl:attribute name="failures">
<xsl:value-of select="$localCunitFailureCount"/>
</xsl:attribute>
<xsl:attribute name="tests">
<xsl:value-of select="$localCunitCount"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="$sn"/>
</xsl:attribute>
<xsl:apply-templates select="CUNIT_RUN_TEST_RECORD" />
</testsuite>
</xsl:for-each>
</xsl:template>

<xsl:template match="CUNIT_RUN_TEST_RECORD">
<xsl:apply-templates select="CUNIT_RUN_TEST_SUCCESS" />
<xsl:apply-templates select="CUNIT_RUN_TEST_FAILURE" />
</xsl:template>

<xsl:template match="CUNIT_RUN_TEST_SUCCESS">
<testcase>
<xsl:attribute name="classname">
<xsl:value-of select="substring-before(substring-after(TEST_NAME,'test_'),'_')" />
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="normalize-space(TEST_NAME)" />
</xsl:attribute>
<xsl:attribute name="time">0</xsl:attribute>
</testcase>
</xsl:template>
<xsl:template match="CUNIT_RUN_TEST_FAILURE">
<testcase>
<xsl:attribute name="classname">
<xsl:value-of select="substring-before(substring-after(TEST_NAME,'test_'),'_')" />
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="normalize-space(TEST_NAME)" />
</xsl:attribute>
<xsl:attribute name="time">0</xsl:attribute>
<failure>
<xsl:attribute name="message">
<xsl:value-of select=" normalize-space(CONDITION)" />
</xsl:attribute>
<xsl:attribute name="type">Failure</xsl:attribute>
<xsl:value-of select="normalize-space(CONDITION)" />
File: <xsl:value-of select="normalize-space(FILE_NAME)" />
Line: <xsl:value-of select="normalize-space(LINE_NUMBER)" />
</failure>
</testcase>
</xsl:template>

<xsl:template match="text()|@*" />

</xsl:stylesheet>

0 comments on commit 0655050

Please sign in to comment.