diff --git a/WHATSNEW b/WHATSNEW index c797b3fbb..61944c2de 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -30,6 +30,8 @@ Fixed bugs: * could hang listcab on large s. +* will now produce output when a test times out as well. + Other changes: -------------- 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 695e63ef7..e6595775f 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 @@ -77,6 +77,9 @@ import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.Environment; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.util.FileUtils; +import junit.framework.AssertionFailedError; +import junit.framework.Test; +import junit.framework.TestResult; /** * Runs JUnit tests. @@ -142,6 +145,7 @@ import org.apache.tools.ant.util.FileUtils; * @author Stephane Bailliez * @author Gerrit Riessen * @author Erik Hatcher + * @author Martijn Kruithof> * * @version $Revision$ * @@ -678,6 +682,10 @@ public class JUnitTask extends Task { } catch (IOException e) { throw new BuildException("Process fork failed.", e, getLocation()); } finally { + if (watchdog.killedProcess()) { + logTimeout(feArray, test); + } + if (!propsFile.delete()) { throw new BuildException("Could not delete temporary " + "properties file."); @@ -920,4 +928,39 @@ public class JUnitTask extends Task { } } + /** + * Take care that some output is produced in report files if the + * watchdog kills the test. + * + * @since Ant 1.5.2 + */ + + private void logTimeout(FormatterElement[] feArray, JUnitTest test) { + for (int i = 0; i < feArray.length; i++) { + FormatterElement fe = feArray[i]; + File outFile = getOutput(fe, test); + JUnitResultFormatter formatter = fe.createFormatter(); + if (outFile != null && formatter != null) { + try { + OutputStream out = new FileOutputStream(outFile); + formatter.setOutput(out); + formatter.startTestSuite(test); + test.setCounts(0,0,1); + Test t = new Test() { + public int countTestCases() { return 0; } + public void run(TestResult r) { + throw new AssertionFailedError("Timeout occured"); + } + }; + formatter.startTest(t); + formatter + .addError(t, + new AssertionFailedError("Timeout occured")); + + formatter.endTestSuite(test); + } catch (IOException e) {} + } + } + } + }