You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2002/11/06 11:44:19 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit JUnitTask.java
bodewig 2002/11/06 02:44:19
Modified: . WHATSNEW
src/main/org/apache/tools/ant/taskdefs/optional/junit
JUnitTask.java
Log:
Generate some dummy output if <junit> kills a test because of a timeout.
PR: 2499
Submitted by: Martijn Kruithof <martijn at kruithof.xs4all.nl>
Revision Changes Path
1.306 +2 -0 jakarta-ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
retrieving revision 1.305
retrieving revision 1.306
diff -u -r1.305 -r1.306
--- WHATSNEW 5 Nov 2002 16:33:27 -0000 1.305
+++ WHATSNEW 6 Nov 2002 10:44:18 -0000 1.306
@@ -30,6 +30,8 @@
* <cab> could hang listcab on large <fileset>s.
+* <junit> will now produce output when a test times out as well.
+
Other changes:
--------------
1.49 +44 -1 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
Index: JUnitTask.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- JUnitTask.java 25 Jul 2002 15:21:16 -0000 1.48
+++ JUnitTask.java 6 Nov 2002 10:44:19 -0000 1.49
@@ -77,6 +77,9 @@
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 @@
* @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:ehatcher@apache.org">Erik Hatcher</a>
+ * @author <a href="mailto:martijn@kruithof.xs4all.nl">Martijn Kruithof></a>
*
* @version $Revision$
*
@@ -678,6 +682,10 @@
} 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.");
@@ -917,6 +925,41 @@
}
} else {
log("Couldn\'t find " + resource, Project.MSG_DEBUG);
+ }
+ }
+
+ /**
+ * 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) {}
+ }
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>