This is an automated email from the ASF dual-hosted git repository.

jaikiran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git


The following commit(s) were added to refs/heads/master by this push:
     new fc82dd1  bz-63850 junitlaucher legacy-xml: don't lose exception from 
@BeforeAll
fc82dd1 is described below

commit fc82dd1bf634646d2a0c57a1b19c06c6849b8300
Author: Marc Guillemot <[email protected]>
AuthorDate: Mon Nov 4 12:20:53 2019 +0100

    bz-63850 junitlaucher legacy-xml: don't lose exception from @BeforeAll
---
 CONTRIBUTORS                                       |  1 +
 WHATSNEW                                           |  4 +++
 contributors.xml                                   |  4 +++
 .../junitlauncher/LegacyXmlResultFormatter.java    | 16 ++++++---
 .../junitlauncher/JUnitLauncherTaskTest.java       | 14 ++++++++
 .../jupiter/JupiterSampleTestFailingStatic.java    | 39 ++++++++++++++++++++++
 6 files changed, 74 insertions(+), 4 deletions(-)

diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 80171e7..5a4b73c 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -248,6 +248,7 @@ Ludovic Claude
 Maarten Coene
 Magesh Umasankar
 Maneesh Sahu
+Marc Guillemot
 Marcel Schutte
 Marcus Börger
 Mario Frasca 
diff --git a/WHATSNEW b/WHATSNEW
index 29dedcf..0af7f1d 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -18,6 +18,10 @@ Fixed bugs:
    It specified the SSH configuration file (typically ${user.home}/.ssh/config)
    defining the username and keyfile to be used per host.
 
+ * "legacy-xml" formatter of junitlauncher task wasn't writing out
+   exceptions that happen in @BeforeAll method of a test. This is now fixed.
+   Bugzilla Report 63850
+
 Other changes:
 --------------
 
diff --git a/contributors.xml b/contributors.xml
index 61040c2..55941aa 100644
--- a/contributors.xml
+++ b/contributors.xml
@@ -1033,6 +1033,10 @@
     <last>Sahu</last>
   </name>
   <name>
+    <first>Marc</first>
+    <last>Guillemot</last>
+  </name>
+  <name>
     <first>Marcel</first>
     <last>Schutte</last>
   </name>
diff --git 
a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
 
b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
index 13e552c..dad1cc8 100644
--- 
a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
+++ 
b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
@@ -232,12 +232,20 @@ class LegacyXmlResultFormatter extends 
AbstractJUnitResultFormatter implements T
         void writeTestCase(final XMLStreamWriter writer) throws 
XMLStreamException {
             for (final Map.Entry<TestIdentifier, Stats> entry : 
testIds.entrySet()) {
                 final TestIdentifier testId = entry.getKey();
-                if (!testId.isTest()) {
-                    // only interested in test methods
+                if (!testId.isTest() && !failed.containsKey(testId)) {
+                    // only interested in test methods unless there was a 
failure,
+                    // in which case we want the exception reported
+                    // (https://bz.apache.org/bugzilla/show_bug.cgi?id=63850)
                     continue;
                 }
-                // find the parent class of this test method
-                final Optional<ClassSource> parentClassSource = 
findFirstParentClassSource(testId);
+                // find the associated class of this test
+                final Optional<ClassSource> parentClassSource;
+                if (testId.isTest()) {
+                    parentClassSource = findFirstParentClassSource(testId);
+                }
+                else {
+                    parentClassSource = findFirstClassSource(testId);
+                }
                 if (!parentClassSource.isPresent()) {
                     continue;
                 }
diff --git 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java
 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java
index 1bb53c1..56596c5 100644
--- 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java
@@ -24,6 +24,8 @@ import static org.example.junitlauncher.Tracker.verifySuccess;
 import static org.example.junitlauncher.Tracker.wasTestRun;
 
 import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -174,6 +176,18 @@ public class JUnitLauncherTaskTest {
         Assert.assertTrue("JupiterSampleTest#testSkipped was expected to be 
skipped", verifySkipped(trackerFile,
                 JupiterSampleTest.class.getName(), "testSkipped"));
         Assert.assertFalse("ForkedTest wasn't expected to be run", 
wasTestRun(trackerFile, ForkedTest.class.getName()));
+
+        
verifyLegacyXMLFile("TEST-org.example.junitlauncher.jupiter.JupiterSampleTestFailingBeforeAll.xml",
 "<failure message=\"Intentional failure\" 
type=\"java.lang.RuntimeException\">");
+        
verifyLegacyXMLFile("TEST-org.example.junitlauncher.jupiter.JupiterSampleTestFailingStatic.xml",
 "Caused by: java.lang.RuntimeException: Intentional exception from static init 
block");
+    }
+
+    private void verifyLegacyXMLFile(final String fileName, final String 
expectedContentExtract) throws IOException {
+        final String outputDir = 
buildRule.getProject().getProperty("output.dir");
+        final Path xmlFile = Paths.get(outputDir, fileName);
+
+        Assert.assertTrue("XML file doesn't exist: " + xmlFile, 
Files.exists(xmlFile));
+        final String content = new String(Files.readAllBytes(xmlFile), 
StandardCharsets.UTF_8);
+        Assert.assertTrue(fileName + " doesn't contain " + 
expectedContentExtract, content.contains(expectedContentExtract));
     }
 
     /**
diff --git 
a/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTestFailingStatic.java
 
b/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTestFailingStatic.java
new file mode 100644
index 0000000..2c88d66
--- /dev/null
+++ 
b/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTestFailingStatic.java
@@ -0,0 +1,39 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.example.junitlauncher.jupiter;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ *
+ */
+public class JupiterSampleTestFailingStatic {
+
+    static {
+        if (true) {
+            throw new RuntimeException("Intentional exception from static init 
block");
+        }
+    }
+
+
+    @Test
+    void testSucceeds() {
+        System.out.println("hello");
+    }
+
+}

Reply via email to