From ff61b8e19361e8229947961660a3ff07fc5f711f Mon Sep 17 00:00:00 2001 From: Nikolas Falco Date: Sun, 20 May 2018 14:40:47 +0200 Subject: [PATCH] [JENKINS-28871] CppTest 9.5 report file seems not valid for xUnit when no tests was executed Improve CppTest XSL to better handle 7.x and 9.x reports. Cover also the case no test was run. --- .../types/{CppTestUnit.java => CppTest.java} | 2 +- .../types/CppTestJunitHudsonTestType.java | 2 +- .../types/cpptestunit-2.0-to-junit-1.0.xsl | 218 +++++---- .../xunit/types/model/xsd/junit-10.xsd | 10 - .../plugins/xunit/types/AbstractTest.java | 2 +- .../plugins/xunit/types/CppTestTest.java | 55 +++ .../plugins/xunit/types/CppTestUnitTest.java | 39 -- .../xunit/types/ValidInputMetricXSLTest.java | 2 +- .../testcase1/input.xml} | 71 +-- .../xunit/types/cpptest/testcase1/result.xml | 7 + .../testcase2/input.xml} | 7 +- .../xunit/types/cpptest/testcase2/result.xml | 202 ++++++++ .../xunit/types/cpptest/testcase3/input.xml | 258 +++++++++++ .../xunit/types/cpptest/testcase3/result.xml | 4 + .../cpptestunit/testcase1/junit-result.xml | 7 - .../cpptestunit/testcase2/result-junit.xml | 435 ------------------ 16 files changed, 695 insertions(+), 626 deletions(-) rename src/main/java/org/jenkinsci/plugins/xunit/types/{CppTestUnit.java => CppTest.java} (98%) create mode 100644 src/test/java/org/jenkinsci/plugins/xunit/types/CppTestTest.java delete mode 100644 src/test/java/org/jenkinsci/plugins/xunit/types/CppTestUnitTest.java rename src/test/resources/org/jenkinsci/plugins/xunit/types/{cpptestunit/testcase1/inputcpptest.xml => cpptest/testcase1/input.xml} (57%) create mode 100644 src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase1/result.xml rename src/test/resources/org/jenkinsci/plugins/xunit/types/{cpptestunit/testcase2/report-cpptest-tests.xml => cpptest/testcase2/input.xml} (99%) create mode 100644 src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase2/result.xml create mode 100644 src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase3/input.xml create mode 100644 src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase3/result.xml delete mode 100644 src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase1/junit-result.xml delete mode 100644 src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase2/result-junit.xml diff --git a/src/main/java/org/jenkinsci/plugins/xunit/types/CppTestUnit.java b/src/main/java/org/jenkinsci/plugins/xunit/types/CppTest.java similarity index 98% rename from src/main/java/org/jenkinsci/plugins/xunit/types/CppTestUnit.java rename to src/main/java/org/jenkinsci/plugins/xunit/types/CppTest.java index 45f28e71..4e61275d 100644 --- a/src/main/java/org/jenkinsci/plugins/xunit/types/CppTestUnit.java +++ b/src/main/java/org/jenkinsci/plugins/xunit/types/CppTest.java @@ -28,7 +28,7 @@ import org.jenkinsci.lib.dtkit.model.OutputMetric; import org.jenkinsci.plugins.xunit.types.model.JUnitModel; -public class CppTestUnit extends InputMetricXSL { +public class CppTest extends InputMetricXSL { @Override public InputType getToolType() { diff --git a/src/main/java/org/jenkinsci/plugins/xunit/types/CppTestJunitHudsonTestType.java b/src/main/java/org/jenkinsci/plugins/xunit/types/CppTestJunitHudsonTestType.java index c4608a53..543707f5 100644 --- a/src/main/java/org/jenkinsci/plugins/xunit/types/CppTestJunitHudsonTestType.java +++ b/src/main/java/org/jenkinsci/plugins/xunit/types/CppTestJunitHudsonTestType.java @@ -48,7 +48,7 @@ public CppTestJunitHudsonTestType(String pattern, boolean skipNoTestFiles, boole public static class DescriptorImpl extends TestTypeDescriptor { public DescriptorImpl() { - super(CppTestJunitHudsonTestType.class, CppTestUnit.class); + super(CppTestJunitHudsonTestType.class, CppTest.class); } } diff --git a/src/main/resources/org/jenkinsci/plugins/xunit/types/cpptestunit-2.0-to-junit-1.0.xsl b/src/main/resources/org/jenkinsci/plugins/xunit/types/cpptestunit-2.0-to-junit-1.0.xsl index d8eeed50..0a23133c 100644 --- a/src/main/resources/org/jenkinsci/plugins/xunit/types/cpptestunit-2.0-to-junit-1.0.xsl +++ b/src/main/resources/org/jenkinsci/plugins/xunit/types/cpptestunit-2.0-to-junit-1.0.xsl @@ -1,65 +1,156 @@ - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + - - - - + + + + + + + + - - + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + - - - - - + @@ -67,42 +158,13 @@ - - - Trace + - + - Line : - - File : - - - - - - - - - - - - - - - - - - - - - JUnitTestSuite - - - - + at : \ No newline at end of file diff --git a/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd b/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd index 9bcea697..442ab6bd 100644 --- a/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd +++ b/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd @@ -104,14 +104,8 @@ THE SOFTWARE. - - - - - - @@ -129,15 +123,12 @@ THE SOFTWARE. - - - @@ -152,7 +143,6 @@ THE SOFTWARE. - diff --git a/src/test/java/org/jenkinsci/plugins/xunit/types/AbstractTest.java b/src/test/java/org/jenkinsci/plugins/xunit/types/AbstractTest.java index 318f51f6..4cd96fa1 100644 --- a/src/test/java/org/jenkinsci/plugins/xunit/types/AbstractTest.java +++ b/src/test/java/org/jenkinsci/plugins/xunit/types/AbstractTest.java @@ -101,7 +101,7 @@ protected void convertAndValidate(Class metricClass, Stri inputMetric.convert(inputXMLFile, outputXMLFile); XMLUnit.setIgnoreWhitespace(true); - Diff myDiff = new Diff(readXmlAsString(outputXMLFile), readXmlAsString(new File(this.getClass().getResource(expectedResultPath).toURI()))); + Diff myDiff = new Diff(readXmlAsString(new File(this.getClass().getResource(expectedResultPath).toURI())), readXmlAsString(outputXMLFile)); Assert.assertTrue("XSL transformation did not work " + myDiff, myDiff.similar()); //The generated output file must be valid diff --git a/src/test/java/org/jenkinsci/plugins/xunit/types/CppTestTest.java b/src/test/java/org/jenkinsci/plugins/xunit/types/CppTestTest.java new file mode 100644 index 00000000..fa33a229 --- /dev/null +++ b/src/test/java/org/jenkinsci/plugins/xunit/types/CppTestTest.java @@ -0,0 +1,55 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2017, Gregory Boissinot, Falco Nikolas + * + * 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 java.util.Arrays; +import java.util.Collection; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class CppTestTest extends AbstractTest { + + @Parameters(name = "testcase{1}: {0}") + public static Collection data() { + return Arrays.asList(new Object[][] { { "testcase1", 1 }, // + { "mix execution of pass and fail tests", 2 }, // + { "testcase3", 3 } // + }); + } + + public CppTestTest(String testName, int testNumber) { + super(CppTest.class, resolveInput("cpptest", testNumber), resolveOutput("cpptest", testNumber)); + } + + @Override + @Test + public void verifyXSLT() throws Exception { + super.verifyXSLT(); + } + +} \ No newline at end of file diff --git a/src/test/java/org/jenkinsci/plugins/xunit/types/CppTestUnitTest.java b/src/test/java/org/jenkinsci/plugins/xunit/types/CppTestUnitTest.java deleted file mode 100644 index 56b04285..00000000 --- a/src/test/java/org/jenkinsci/plugins/xunit/types/CppTestUnitTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Thales Corporate Services SAS * - * Author : Gregory Boissinot * - * * - * 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 CppTestUnitTest extends AbstractTest { - - @Test - public void cpptestTestcase1() throws Exception { - convertAndValidate(CppTestUnit.class, "cpptestunit/testcase1/inputcpptest.xml", "cpptestunit/testcase1/junit-result.xml"); - } - - @Test - public void cpptestTestcase2() throws Exception { - convertAndValidate(CppTestUnit.class, "cpptestunit/testcase2/report-cpptest-tests.xml", "cpptestunit/testcase2/result-junit.xml"); - } -} diff --git a/src/test/java/org/jenkinsci/plugins/xunit/types/ValidInputMetricXSLTest.java b/src/test/java/org/jenkinsci/plugins/xunit/types/ValidInputMetricXSLTest.java index 9b59e8e0..4454ce49 100644 --- a/src/test/java/org/jenkinsci/plugins/xunit/types/ValidInputMetricXSLTest.java +++ b/src/test/java/org/jenkinsci/plugins/xunit/types/ValidInputMetricXSLTest.java @@ -42,7 +42,7 @@ public class ValidInputMetricXSLTest { public static void loadList() { listInputMetric.add(AUnit.class); listInputMetric.add(BoostTest.class); - listInputMetric.add(CppTestUnit.class); + listInputMetric.add(CppTest.class); listInputMetric.add(CppUnit.class); listInputMetric.add(FPCUnit.class); listInputMetric.add(MSTest.class); diff --git a/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase1/inputcpptest.xml b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase1/input.xml similarity index 57% rename from src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase1/inputcpptest.xml rename to src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase1/input.xml index 26ddfc35..e1dd890a 100644 --- a/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase1/inputcpptest.xml +++ b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase1/input.xml @@ -4,26 +4,16 @@ - - - - - - - - - - + + + + + + + + + + @@ -37,16 +27,12 @@ - + - + @@ -68,33 +54,22 @@ - - - - - - + + + + + + - - - + + + - - diff --git a/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase1/result.xml b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase1/result.xml new file mode 100644 index 00000000..3760ee37 --- /dev/null +++ b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase1/result.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase2/report-cpptest-tests.xml b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase2/input.xml similarity index 99% rename from src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase2/report-cpptest-tests.xml rename to src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase2/input.xml index ce5985f3..c80c78ec 100644 --- a/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase2/report-cpptest-tests.xml +++ b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase2/input.xml @@ -6,8 +6,7 @@ - + @@ -6425,10 +6424,8 @@ - - + diff --git a/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase2/result.xml b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase2/result.xml new file mode 100644 index 00000000..42a8d330 --- /dev/null +++ b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase2/result.xml @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase3/input.xml b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase3/input.xml new file mode 100644 index 00000000..c211ba25 --- /dev/null +++ b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase3/input.xml @@ -0,0 +1,258 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 06-09-15, + 0,0,0, + 0,0,0, + + + + + + + + + + 06-09-15, + 0,0,0, + 0,0,0, + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 06-09-15, + 2583,0,0, + 2583,0,0, + + + + + + + + + + + + + + + + diff --git a/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase3/result.xml b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase3/result.xml new file mode 100644 index 00000000..2d315e2d --- /dev/null +++ b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptest/testcase3/result.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase1/junit-result.xml b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase1/junit-result.xml deleted file mode 100644 index bdbbb829..00000000 --- a/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase1/junit-result.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase2/result-junit.xml b/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase2/result-junit.xml deleted file mode 100644 index 9d0fbbe7..00000000 --- a/src/test/resources/org/jenkinsci/plugins/xunit/types/cpptestunit/testcase2/result-junit.xml +++ /dev/null @@ -1,435 +0,0 @@ - - - - - - - - - - Trace Line :14 File :/ATM/ATM.cxxLine :476 File :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine - :26 File :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine :9 File - :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cpp - - - - - Trace Line :14 File :/ATM/ATM.cxxLine :501 File :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine - :27 File :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine :9 File - :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cpp - - - - - Trace Line :14 File :/ATM/ATM.cxxLine :526 File :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine - :28 File :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine :9 File - :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cpp - - - - - Trace Line :14 File :/ATM/ATM.cxxLine :626 File :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine - :32 File :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine :9 File - :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cpp - - - - - Trace Line :18 File :/ATM/Bank.cxxLine :12 File :/ATM/ATM.cxxLine :425 File - :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine :24 File - :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine :9 File :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cpp - - - - - Trace Line :18 File :/ATM/Bank.cxxLine :12 File :/ATM/ATM.cxxLine :551 File - :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine :29 File - :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine :9 File :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cpp - - - - - Trace Line :18 File :/ATM/Bank.cxxLine :12 File :/ATM/ATM.cxxLine :601 File - :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine :31 File - :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine :9 File :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cpp - - - - - Trace Line :18 File :/ATM/Bank.cxxLine :12 File :/ATM/ATM.cxxLine :651 File - :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine :33 File - :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cppLine :9 File :/ATM/tests/autogenerated/TestSuite_ATM_cxx.cpp - - - - - Trace Line :37 File :/ATM/include/Account.hxxLine :939 File - :/ATM/tests/autogenerated/include/TestSuite_Account_hxx.cppLine :53 File - :/ATM/tests/autogenerated/include/TestSuite_Account_hxx.cppLine :9 File - :/ATM/tests/autogenerated/include/TestSuite_Account_hxx.cpp - - - - - Trace Line :37 File :/ATM/include/Account.hxxLine :1097 File - :/ATM/tests/autogenerated/include/TestSuite_Account_hxx.cppLine :61 File - :/ATM/tests/autogenerated/include/TestSuite_Account_hxx.cppLine :9 File - :/ATM/tests/autogenerated/include/TestSuite_Account_hxx.cpp - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -