From d8b918468e8937816e3ba42719cea8f0327a7948 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 11 Aug 2008 13:49:18 +0000 Subject: [PATCH] Make JUnit's output less confusing when a forked VM running more than one test is terminated. PR 45227. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@684745 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 9 +++++ .../taskdefs/optional/junit/JUnitTask.java | 34 ++++++++++++++++++- .../taskdefs/optional/junit/junit-test.xml | 4 ++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index cad4140ab..17c7173b5 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -76,6 +76,15 @@ Changes that could break older environments: 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: ----------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java index 507e87afa..3404eb1a7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java @@ -1039,10 +1039,18 @@ public class JUnitTask extends Task { 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 @@ public class JUnitTask extends Task { new LogOutputStream(task, errlevel)); } } + + /** + * Creates a JUnitTest instance that shares all flags with the + * passed in instance but has a more meaningful name. + * + *

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.

+ * + * @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; + } } diff --git a/src/tests/antunit/taskdefs/optional/junit/junit-test.xml b/src/tests/antunit/taskdefs/optional/junit/junit-test.xml index 31b2367e9..2a28c72ac 100644 --- a/src/tests/antunit/taskdefs/optional/junit/junit-test.xml +++ b/src/tests/antunit/taskdefs/optional/junit/junit-test.xml @@ -44,7 +44,7 @@ public class @{classname} extends TestCase { - + @@ -72,6 +72,8 @@ public class BTest extends TestCase { + +