Author: bodewig
Date: Mon Aug 11 06:49:18 2008
New Revision: 684745

URL: http://svn.apache.org/viewvc?rev=684745&view=rev
Log:
Make JUnit's output less confusing when a forked VM running more than one test 
is terminated.  PR 45227.

Modified:
    ant/core/trunk/WHATSNEW
    
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
    ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=684745&r1=684744&r2=684745&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Aug 11 06:49:18 2008
@@ -76,6 +76,15 @@
    that can be set to restore the old behavior.
    Bugzilla Report 42122.
 
+ * If a batch containing multiple JUnit tests running inside a forked
+   Java VM caused the VM to crash (or caused a timeout), the
+   formatters would receive an error message for the last test in the
+   batch.
+   Ant will now pass in a test with the name "Batch-With-Multiple-Tests"
+   instead - this is supposed to show more clearly that the last test
+   may not have started at all.
+   Bugzilla Report 45227.
+
 Fixed bugs:
 -----------
 

Modified: 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java?rev=684745&r1=684744&r2=684745&view=diff
==============================================================================
--- 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
 (original)
+++ 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
 Mon Aug 11 06:49:18 2008
@@ -1039,10 +1039,18 @@
                     vmWatcher.delete();
                 }
             }
+
+            boolean crash = (watchdog != null && watchdog.killedProcess())
+                || !Constants.TERMINATED_SUCCESSFULLY.equals(vmCrashString);
+
+            if (casesFile != null && crash) {
+                test = createDummyTestForBatchTest(test);
+            }
+
             if (watchdog != null && watchdog.killedProcess()) {
                 result.timedOut = true;
                 logTimeout(feArray, test, vmCrashString);
-            } else if 
(!Constants.TERMINATED_SUCCESSFULLY.equals(vmCrashString)) {
+            } else if (crash) {
                 result.crashed = true;
                 logVmCrash(feArray, test, vmCrashString);
             }
@@ -1917,4 +1925,28 @@
                   new LogOutputStream(task, errlevel));
         }
     }
+
+    /**
+     * Creates a JUnitTest instance that shares all flags with the
+     * passed in instance but has a more meaningful name.
+     *
+     * <p>If a VM running multiple tests crashes, we don't know which
+     * test failed.  Prior to Ant 1.8.0 Ant would log the error with
+     * the last test of the batch test, which caused some confusion
+     * since the log might look as if a test had been executed last
+     * that was never started.  With Ant 1.8.0 the test's name will
+     * indicate that something went wrong with a test inside the batch
+     * without giving it a real name.</p>
+     *
+     * @see https://issues.apache.org/bugzilla/show_bug.cgi?id=45227
+     */
+    private static JUnitTest createDummyTestForBatchTest(JUnitTest test) {
+        JUnitTest t = (JUnitTest) test.clone();
+        int index = test.getName().indexOf(".");
+        // make sure test looks as if it was in the same "package" as
+        // the last test of the batch
+        String pack = index > 0 ? test.getName().substring(0, index + 1) : "";
+        t.setName(pack + "Batch-With-Multiple-Tests");
+        return t;
+    }
 }

Modified: 
ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml?rev=684745&r1=684744&r2=684745&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml 
(original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml Mon 
Aug 11 06:49:18 2008
@@ -44,7 +44,7 @@
     </sequential>
   </macrodef>
 
-  <target name="XtestTimeoutLogOfBatchTests">
+  <target name="testTimeoutLogOfBatchTests">
     <mkdir dir="${input}"/>
     <mkdir dir="${output}"/>
     <empty-test classname="ATest"/>
@@ -72,6 +72,8 @@
         </fileset>
       </batchtest>
     </junit>
+    <au:assertLogContains text="ATest"/>
+    <au:assertLogContains text="BTest"/>
     <au:assertLogDoesntContain text="CTest"/>
     <au:assertLogDoesntContain text="DTest"/>
   </target>


Reply via email to