Skip to content

Commit

Permalink
Merge pull request #38 from etiennebec/master
Browse files Browse the repository at this point in the history
[FIXED JENKINS-24382] Add basic support for CUnit
  • Loading branch information
gboissinot committed Feb 21, 2016
2 parents 237775a + b4424b2 commit 1dca7a0
Show file tree
Hide file tree
Showing 14 changed files with 491 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";
}

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

@Override
public String getXslName() {
return "cunit-2.1-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,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License (MIT)
Copyright (c) 2014 Shawn Liang
Last modification: 02/18/2016 by 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.
https://github.com/shawnliang/cunit-to-junit
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<testsuites>
<xsl:for-each select="//CUNIT_RUN_SUITE_SUCCESS">
<xsl:variable name="suiteName" select="normalize-space(SUITE_NAME/text())"/>
<xsl:variable name="numberOfTests" select="count(CUNIT_RUN_TEST_RECORD/CUNIT_RUN_TEST_SUCCESS)"/>
<xsl:variable name="numberOfFailures" select="count(CUNIT_RUN_TEST_RECORD/CUNIT_RUN_TEST_FAILURE)"/>
<testsuite name="{$suiteName}" tests="{$numberOfTests}" time="0" failures="{$numberOfFailures}" errors="0" skipped="0">
<xsl:for-each select="CUNIT_RUN_TEST_RECORD/CUNIT_RUN_TEST_SUCCESS">
<xsl:variable name="testname" select="normalize-space(TEST_NAME/text())"/>
<testcase classname="{$suiteName}" name="{$testname}" time="0.0"/>
</xsl:for-each>
<xsl:for-each select="CUNIT_RUN_TEST_RECORD/CUNIT_RUN_TEST_FAILURE">
<xsl:variable name="testname" select="normalize-space(TEST_NAME/text())"/>
<testcase classname="{$suiteName}" name="{$testname}" time="0.0">
<failure>
Test failed at line <xsl:value-of select="LINE_NUMBER"/> in file <xsl:value-of select="FILE_NAME"/>:
<xsl:value-of select="CONDITION"/>
</failure>
</testcase>
</xsl:for-each>
</testsuite>
</xsl:for-each>
</testsuites>
</xsl:template>
</xsl:stylesheet>
61 changes: 61 additions & 0 deletions src/test/java/org/jenkinsci/plugins/xunit/types/CUnitTest.java
@@ -0,0 +1,61 @@
/*
* 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.junit.Test;

public class CUnitTest extends AbstractTest{

// Empty CUNIT_RESULT_LISTING
@Test
public void testcase1() throws Exception {
convertAndValidate(CUnit.class, "cunit/testcase1/testresult.xml", "cunit/testcase1/junit-result.xml");
}

// 1 CUNIT_RUN_SUITE / CUNIT_RUN_SUITE_SUCCESS / 1 CUNIT_TEST_RECORD / CUNIT_RUN_TEST_SUCCESS
@Test
public void testcase2() throws Exception {
convertAndValidate(CUnit.class, "cunit/testcase2/testresult.xml", "cunit/testcase2/junit-result.xml");
}

// 1 CUNIT_RUN_SUITE / CUNIT_RUN_SUITE_SUCCESS / 1 CUNIT_TEST_RECORD / CUNIT_RUN_TEST_FAILURE
@Test
public void testcase3() throws Exception {
convertAndValidate(CUnit.class, "cunit/testcase3/testresult.xml", "cunit/testcase3/junit-result.xml");
}

// 1 CUNIT_RUN_SUITE / CUNIT_RUN_SUITE_SUCCESS / * CUNIT_TEST_RECORD / CUNIT_RUN_TEST_SUCCESS | CUNIT_RUN_TEST_FAILURE
@Test
public void testcase4() throws Exception {
convertAndValidate(CUnit.class, "cunit/testcase4/testresult.xml", "cunit/testcase4/junit-result.xml");
}

// * CUNIT_RUN_SUITE / CUNIT_RUN_SUITE_SUCCESS / * CUNIT_TEST_RECORD / CUNIT_RUN_TEST_SUCCESS | CUNIT_RUN_TEST_FAILURE
@Test
public void testcase5() throws Exception {
convertAndValidate(CUnit.class, "cunit/testcase5/testresult.xml", "cunit/testcase5/junit-result.xml");
}
}
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites/>
@@ -0,0 +1,10 @@
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="CUnit-Run.xsl" ?>
<!DOCTYPE CUNIT_TEST_RUN_REPORT SYSTEM "CUnit-Run.dtd">
<CUNIT_TEST_RUN_REPORT>
<CUNIT_HEADER/>
<CUNIT_RESULT_LISTING>

</CUNIT_RESULT_LISTING>
<CUNIT_FOOTER />
</CUNIT_TEST_RUN_REPORT>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="Suite Success 1" tests="1" time="0" failures="0" errors="0" skipped="0">
<testcase classname="Suite Success 1" name="Test 1.1" time="0.0"/>
</testsuite>
</testsuites>
@@ -0,0 +1,23 @@
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="CUnit-Run.xsl" ?>
<!DOCTYPE CUNIT_TEST_RUN_REPORT SYSTEM "CUnit-Run.dtd">
<CUNIT_TEST_RUN_REPORT>
<CUNIT_HEADER/>
<CUNIT_RESULT_LISTING>

<CUNIT_RUN_SUITE>
<CUNIT_RUN_SUITE_SUCCESS>
<SUITE_NAME>Suite Success 1</SUITE_NAME>

<CUNIT_RUN_TEST_RECORD>
<CUNIT_RUN_TEST_SUCCESS>
<TEST_NAME>Test 1.1</TEST_NAME>
</CUNIT_RUN_TEST_SUCCESS>
</CUNIT_RUN_TEST_RECORD>

</CUNIT_RUN_SUITE_SUCCESS>
</CUNIT_RUN_SUITE>

</CUNIT_RESULT_LISTING>
<CUNIT_FOOTER />
</CUNIT_TEST_RUN_REPORT>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="Suite Success 1" tests="0" time="0" failures="1" errors="0" skipped="0">
<testcase classname="Suite Success 1" name="Test 1.1" time="0.0">
<failure>
Test failed at line 100 in file /foo/bar/test_1_1.c :
Error in nominal use 1 - Expected : 0 , Result : -1 </failure>
</testcase>
</testsuite>
</testsuites>
@@ -0,0 +1,26 @@
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="CUnit-Run.xsl" ?>
<!DOCTYPE CUNIT_TEST_RUN_REPORT SYSTEM "CUnit-Run.dtd">
<CUNIT_TEST_RUN_REPORT>
<CUNIT_HEADER/>
<CUNIT_RESULT_LISTING>

<CUNIT_RUN_SUITE>
<CUNIT_RUN_SUITE_SUCCESS>
<SUITE_NAME>Suite Success 1</SUITE_NAME>

<CUNIT_RUN_TEST_RECORD>
<CUNIT_RUN_TEST_FAILURE>
<TEST_NAME> Test 1.1 </TEST_NAME>
<FILE_NAME> /foo/bar/test_1_1.c </FILE_NAME>
<LINE_NUMBER> 100 </LINE_NUMBER>
<CONDITION> Error in nominal use 1 - Expected : 0 , Result : -1 </CONDITION>
</CUNIT_RUN_TEST_FAILURE>
</CUNIT_RUN_TEST_RECORD>

</CUNIT_RUN_SUITE_SUCCESS>
</CUNIT_RUN_SUITE>

</CUNIT_RESULT_LISTING>
<CUNIT_FOOTER />
</CUNIT_TEST_RUN_REPORT>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="Suite Success 1" tests="2" time="0" failures="2" errors="0" skipped="0">
<testcase classname="Suite Success 1" name="Test 1.1" time="0.0"/>
<testcase classname="Suite Success 1" name="Test 1.3" time="0.0"/>
<testcase classname="Suite Success 1" name="Test 1.2" time="0.0">
<failure>
Test failed at line 100 in file /foo/bar/test_1_2.c :
Error in nominal use 1 - Expected : 0 , Result : -1 </failure>
</testcase>
<testcase classname="Suite Success 1" name="Test 1.4" time="0.0">
<failure>
Test failed at line 200 in file /foo/bar/test_1_4.c :
Error in nominal use 1 - Expected : 0 , Result : -1 </failure>
</testcase>
</testsuite>
</testsuites>
@@ -0,0 +1,47 @@
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="CUnit-Run.xsl" ?>
<!DOCTYPE CUNIT_TEST_RUN_REPORT SYSTEM "CUnit-Run.dtd">
<CUNIT_TEST_RUN_REPORT>
<CUNIT_HEADER/>
<CUNIT_RESULT_LISTING>

<CUNIT_RUN_SUITE>
<CUNIT_RUN_SUITE_SUCCESS>
<SUITE_NAME>Suite Success 1</SUITE_NAME>

<CUNIT_RUN_TEST_RECORD>
<CUNIT_RUN_TEST_SUCCESS>
<TEST_NAME>Test 1.1</TEST_NAME>
</CUNIT_RUN_TEST_SUCCESS>
</CUNIT_RUN_TEST_RECORD>

<CUNIT_RUN_TEST_RECORD>
<CUNIT_RUN_TEST_FAILURE>
<TEST_NAME> Test 1.2 </TEST_NAME>
<FILE_NAME> /foo/bar/test_1_2.c </FILE_NAME>
<LINE_NUMBER> 100 </LINE_NUMBER>
<CONDITION> Error in nominal use 1 - Expected : 0 , Result : -1 </CONDITION>
</CUNIT_RUN_TEST_FAILURE>
</CUNIT_RUN_TEST_RECORD>

<CUNIT_RUN_TEST_RECORD>
<CUNIT_RUN_TEST_SUCCESS>
<TEST_NAME>Test 1.3</TEST_NAME>
</CUNIT_RUN_TEST_SUCCESS>
</CUNIT_RUN_TEST_RECORD>

<CUNIT_RUN_TEST_RECORD>
<CUNIT_RUN_TEST_FAILURE>
<TEST_NAME> Test 1.4 </TEST_NAME>
<FILE_NAME> /foo/bar/test_1_4.c </FILE_NAME>
<LINE_NUMBER> 200 </LINE_NUMBER>
<CONDITION> Error in nominal use 1 - Expected : 0 , Result : -1 </CONDITION>
</CUNIT_RUN_TEST_FAILURE>
</CUNIT_RUN_TEST_RECORD>

</CUNIT_RUN_SUITE_SUCCESS>
</CUNIT_RUN_SUITE>

</CUNIT_RESULT_LISTING>
<CUNIT_FOOTER />
</CUNIT_TEST_RUN_REPORT>

0 comments on commit 1dca7a0

Please sign in to comment.