time, this is not true. PR: 2442 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269834 13f79535-47bb-0310-9956-ffa450edef68master
@@ -20,6 +20,10 @@ Fixed bugs: | |||||
* <ant> will no longer override a subbuilds basedir with inheritall="true". | * <ant> will no longer override a subbuilds basedir with inheritall="true". | ||||
* Fixed problem with the built-in <junit> formatters which assumed | |||||
that only one test could be running at the same time - this is not | |||||
necessarily true, see junit.extensions.ActiveTestSuite. | |||||
Other changes: | Other changes: | ||||
-------------- | -------------- | ||||
@@ -242,7 +242,8 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter { | |||||
/** | /** | ||||
* Format an error and print it. | * Format an error and print it. | ||||
*/ | */ | ||||
protected void formatError(String type, Test test, Throwable error) { | |||||
protected synchronized void formatError(String type, Test test, | |||||
Throwable error) { | |||||
if (test != null) { | if (test != null) { | ||||
endTest(test); | endTest(test); | ||||
} | } | ||||
@@ -61,6 +61,7 @@ import java.io.StringWriter; | |||||
import java.io.PrintWriter; | import java.io.PrintWriter; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.text.NumberFormat; | import java.text.NumberFormat; | ||||
import java.util.Hashtable; | |||||
import junit.framework.AssertionFailedError; | import junit.framework.AssertionFailedError; | ||||
import junit.framework.Test; | import junit.framework.Test; | ||||
@@ -81,7 +82,7 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { | |||||
/** | /** | ||||
* Timing helper. | * Timing helper. | ||||
*/ | */ | ||||
private long lastTestStart = 0; | |||||
private Hashtable testStarts = new Hashtable(); | |||||
/** | /** | ||||
* Where to write the log to. | * Where to write the log to. | ||||
*/ | */ | ||||
@@ -97,7 +98,7 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { | |||||
/** | /** | ||||
* Suppress endTest if testcase failed. | * Suppress endTest if testcase failed. | ||||
*/ | */ | ||||
private boolean failed = true; | |||||
private Hashtable failed = new Hashtable(); | |||||
private String systemOutput = null; | private String systemOutput = null; | ||||
private String systemError = null; | private String systemError = null; | ||||
@@ -187,10 +188,8 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { | |||||
* <p>A new Test is started. | * <p>A new Test is started. | ||||
*/ | */ | ||||
public void startTest(Test t) { | public void startTest(Test t) { | ||||
lastTestStart = System.currentTimeMillis(); | |||||
wri.print("Testcase: " | |||||
+ JUnitVersionHelper.getTestCaseName((TestCase) t)); | |||||
failed = false; | |||||
testStarts.put(t, new Long(System.currentTimeMillis())); | |||||
failed.put(t, Boolean.FALSE); | |||||
} | } | ||||
/** | /** | ||||
@@ -199,11 +198,18 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { | |||||
* <p>A Test is finished. | * <p>A Test is finished. | ||||
*/ | */ | ||||
public void endTest(Test test) { | public void endTest(Test test) { | ||||
if (failed) return; | |||||
wri.println(" took " | |||||
+ nf.format((System.currentTimeMillis()-lastTestStart) | |||||
/ 1000.0) | |||||
+ " sec"); | |||||
synchronized (wri) { | |||||
wri.print("Testcase: " | |||||
+ JUnitVersionHelper.getTestCaseName((TestCase) test)); | |||||
if (Boolean.TRUE.equals(failed.get(test))) { | |||||
return; | |||||
} | |||||
Long l = (Long) testStarts.get(test); | |||||
wri.println(" took " | |||||
+ nf.format((System.currentTimeMillis()-l.longValue()) | |||||
/ 1000.0) | |||||
+ " sec"); | |||||
} | |||||
} | } | ||||
/** | /** | ||||
@@ -234,15 +240,17 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { | |||||
} | } | ||||
private void formatError(String type, Test test, Throwable t) { | private void formatError(String type, Test test, Throwable t) { | ||||
if (test != null) { | |||||
endTest(test); | |||||
} | |||||
failed = true; | |||||
synchronized (wri) { | |||||
if (test != null) { | |||||
endTest(test); | |||||
failed.put(test, Boolean.TRUE); | |||||
} | |||||
wri.println(type); | |||||
wri.println(t.getMessage()); | |||||
t.printStackTrace(wri); | |||||
wri.println(""); | |||||
wri.println(type); | |||||
wri.println(t.getMessage()); | |||||
t.printStackTrace(wri); | |||||
wri.println(""); | |||||
} | |||||
} | } | ||||
} // PlainJUnitResultFormatter | } // PlainJUnitResultFormatter |
@@ -64,6 +64,7 @@ import java.io.PrintWriter; | |||||
import java.util.Properties; | import java.util.Properties; | ||||
import java.util.Enumeration; | import java.util.Enumeration; | ||||
import java.util.Hashtable; | |||||
import javax.xml.parsers.DocumentBuilder; | import javax.xml.parsers.DocumentBuilder; | ||||
import javax.xml.parsers.DocumentBuilderFactory; | import javax.xml.parsers.DocumentBuilderFactory; | ||||
import org.w3c.dom.Document; | import org.w3c.dom.Document; | ||||
@@ -107,11 +108,11 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||||
/** | /** | ||||
* Element for the current test. | * Element for the current test. | ||||
*/ | */ | ||||
private Element currentTest; | |||||
private Hashtable testElements = new Hashtable(); | |||||
/** | /** | ||||
* Timing helper. | * Timing helper. | ||||
*/ | */ | ||||
private long lastTestStart = 0; | |||||
private Hashtable testStarts = new Hashtable(); | |||||
/** | /** | ||||
* Where to write the log to. | * Where to write the log to. | ||||
*/ | */ | ||||
@@ -167,7 +168,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||||
Writer wri = null; | Writer wri = null; | ||||
try { | try { | ||||
wri = new OutputStreamWriter(out, "UTF8"); | wri = new OutputStreamWriter(out, "UTF8"); | ||||
wri.write("<?xml version=\"1.0\"?>\n"); | |||||
wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); | |||||
(new DOMElementWriter()).write(rootElement, wri, 0, " "); | (new DOMElementWriter()).write(rootElement, wri, 0, " "); | ||||
wri.flush(); | wri.flush(); | ||||
} catch(IOException exc) { | } catch(IOException exc) { | ||||
@@ -190,11 +191,13 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||||
* <p>A new Test is started. | * <p>A new Test is started. | ||||
*/ | */ | ||||
public void startTest(Test t) { | public void startTest(Test t) { | ||||
lastTestStart = System.currentTimeMillis(); | |||||
currentTest = doc.createElement(TESTCASE); | |||||
testStarts.put(t, new Long(System.currentTimeMillis())); | |||||
Element currentTest = doc.createElement(TESTCASE); | |||||
currentTest.setAttribute(ATTR_NAME, | currentTest.setAttribute(ATTR_NAME, | ||||
JUnitVersionHelper.getTestCaseName((TestCase) t)); | JUnitVersionHelper.getTestCaseName((TestCase) t)); | ||||
rootElement.appendChild(currentTest); | rootElement.appendChild(currentTest); | ||||
testElements.put(t, currentTest); | |||||
} | } | ||||
/** | /** | ||||
@@ -203,8 +206,10 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||||
* <p>A Test is finished. | * <p>A Test is finished. | ||||
*/ | */ | ||||
public void endTest(Test test) { | public void endTest(Test test) { | ||||
Element currentTest = (Element) testElements.get(test); | |||||
Long l = (Long) testStarts.get(test); | |||||
currentTest.setAttribute(ATTR_TIME, | currentTest.setAttribute(ATTR_TIME, | ||||
""+((System.currentTimeMillis()-lastTestStart) | |||||
""+((System.currentTimeMillis()-l.longValue()) | |||||
/ 1000.0)); | / 1000.0)); | ||||
} | } | ||||
@@ -241,12 +246,15 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan | |||||
} | } | ||||
Element nested = doc.createElement(type); | Element nested = doc.createElement(type); | ||||
Element currentTest = null; | |||||
if (test != null) { | if (test != null) { | ||||
currentTest.appendChild(nested); | |||||
currentTest = (Element) testElements.get(test); | |||||
} else { | } else { | ||||
rootElement.appendChild(nested); | |||||
currentTest = rootElement; | |||||
} | } | ||||
currentTest.appendChild(nested); | |||||
String message = t.getMessage(); | String message = t.getMessage(); | ||||
if (message != null && message.length() > 0) { | if (message != null && message.length() > 0) { | ||||
nested.setAttribute(ATTR_MESSAGE, t.getMessage()); | nested.setAttribute(ATTR_MESSAGE, t.getMessage()); | ||||