Browse Source

Generate some dummy output if <junit> kills a test because of a timeout.

PR: 2499
Submitted by:	Martijn Kruithof <martijn at kruithof.xs4all.nl>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273490 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
837f7ef785
2 changed files with 45 additions and 0 deletions
  1. +2
    -0
      WHATSNEW
  2. +43
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java

+ 2
- 0
WHATSNEW View File

@@ -30,6 +30,8 @@ Fixed bugs:


* <cab> could hang listcab on large <fileset>s. * <cab> could hang listcab on large <fileset>s.


* <junit> will now produce output when a test times out as well.

Other changes: Other changes:
-------------- --------------




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

@@ -77,6 +77,9 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.Environment; import org.apache.tools.ant.types.Environment;
import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestResult;


/** /**
* Runs JUnit tests. * Runs JUnit tests.
@@ -142,6 +145,7 @@ import org.apache.tools.ant.util.FileUtils;
* @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a>
* @author <a href="mailto:Gerrit.Riessen@web.de">Gerrit Riessen</a> * @author <a href="mailto:Gerrit.Riessen@web.de">Gerrit Riessen</a>
* @author <a href="mailto:ehatcher@apache.org">Erik Hatcher</a> * @author <a href="mailto:ehatcher@apache.org">Erik Hatcher</a>
* @author <a href="mailto:martijn@kruithof.xs4all.nl">Martijn Kruithof></a>
* *
* @version $Revision$ * @version $Revision$
* *
@@ -678,6 +682,10 @@ public class JUnitTask extends Task {
} catch (IOException e) { } catch (IOException e) {
throw new BuildException("Process fork failed.", e, getLocation()); throw new BuildException("Process fork failed.", e, getLocation());
} finally { } finally {
if (watchdog.killedProcess()) {
logTimeout(feArray, test);
}

if (!propsFile.delete()) { if (!propsFile.delete()) {
throw new BuildException("Could not delete temporary " throw new BuildException("Could not delete temporary "
+ "properties file."); + "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) {}
}
}
}

} }

Loading…
Cancel
Save