Browse Source

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
master
Stefan Bodewig 17 years ago
parent
commit
d8b918468e
3 changed files with 45 additions and 2 deletions
  1. +9
    -0
      WHATSNEW
  2. +33
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  3. +3
    -1
      src/tests/antunit/taskdefs/optional/junit/junit-test.xml

+ 9
- 0
WHATSNEW View File

@@ -76,6 +76,15 @@ Changes that could break older environments:
that can be set to restore the old behavior. that can be set to restore the old behavior.
Bugzilla Report 42122. 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: Fixed bugs:
----------- -----------




+ 33
- 1
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -1039,10 +1039,18 @@ public class JUnitTask extends Task {
vmWatcher.delete(); 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()) { if (watchdog != null && watchdog.killedProcess()) {
result.timedOut = true; result.timedOut = true;
logTimeout(feArray, test, vmCrashString); logTimeout(feArray, test, vmCrashString);
} else if (!Constants.TERMINATED_SUCCESSFULLY.equals(vmCrashString)) {
} else if (crash) {
result.crashed = true; result.crashed = true;
logVmCrash(feArray, test, vmCrashString); logVmCrash(feArray, test, vmCrashString);
} }
@@ -1917,4 +1925,28 @@ public class JUnitTask extends Task {
new LogOutputStream(task, errlevel)); 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;
}
} }

+ 3
- 1
src/tests/antunit/taskdefs/optional/junit/junit-test.xml View File

@@ -44,7 +44,7 @@ public class @{classname} extends TestCase {
</sequential> </sequential>
</macrodef> </macrodef>


<target name="XtestTimeoutLogOfBatchTests">
<target name="testTimeoutLogOfBatchTests">
<mkdir dir="${input}"/> <mkdir dir="${input}"/>
<mkdir dir="${output}"/> <mkdir dir="${output}"/>
<empty-test classname="ATest"/> <empty-test classname="ATest"/>
@@ -72,6 +72,8 @@ public class BTest extends TestCase {
</fileset> </fileset>
</batchtest> </batchtest>
</junit> </junit>
<au:assertLogContains text="ATest"/>
<au:assertLogContains text="BTest"/>
<au:assertLogDoesntContain text="CTest"/> <au:assertLogDoesntContain text="CTest"/>
<au:assertLogDoesntContain text="DTest"/> <au:assertLogDoesntContain text="DTest"/>
</target> </target>


Loading…
Cancel
Save