You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by sb...@apache.org on 2002/02/03 14:23:52 UTC
cvs commit: jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/rjunit/formatter BaseFormatter.java BaseStreamFormatter.java Resources.properties SummaryFormatter.java XMLFormatter.java
sbailliez 02/02/03 05:23:52
Modified: proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/rjunit/formatter
BaseFormatter.java BaseStreamFormatter.java
Resources.properties SummaryFormatter.java
XMLFormatter.java
Log:
Fix formatters by cleaning up some logic.
Events will now send a summary for each end of sequence.
Revision Changes Path
1.2 +0 -41 jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/rjunit/formatter/BaseFormatter.java
Index: BaseFormatter.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/rjunit/formatter/BaseFormatter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BaseFormatter.java 1 Feb 2002 23:53:22 -0000 1.1
+++ BaseFormatter.java 3 Feb 2002 13:23:52 -0000 1.2
@@ -65,36 +65,19 @@
*/
public abstract class BaseFormatter implements Formatter {
- /** number of errors */
- private int errorCount;
-
- /** number of failures */
- private int failureCount;
-
- /** number of runs (success + failure + error) */
- private int runCount;
-
public void init(Properties props) throws BuildException {
}
- protected void finalize() throws Throwable {
- super.finalize();
- close();
- }
-
public void onTestStarted(TestRunEvent evt) {
- runCount++;
}
public void onTestEnded(TestRunEvent evt) {
}
public void onTestFailure(TestRunEvent evt) {
- failureCount++;
}
public void onTestError(TestRunEvent evt) {
- errorCount++;
}
public void onSuiteStarted(TestRunEvent evt) {
@@ -107,33 +90,9 @@
}
public void onRunEnded(TestRunEvent evt) {
- finished();
}
public void onRunStopped(TestRunEvent evt) {
- finished();
- }
-
- protected void finished() {
- close();
}
- /** @return the number of errors */
- protected final int getErrorCount() {
- return errorCount;
- }
-
- /** @return the number of failures */
- protected final int getFailureCount() {
- return failureCount;
- }
-
- /** @return the number of runs */
- protected final int getRunCount() {
- return runCount;
- }
-
- /** helper method to flush and close the stream */
- protected void close() {
- }
}
1.2 +11 -1 jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/rjunit/formatter/BaseStreamFormatter.java
Index: BaseStreamFormatter.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/rjunit/formatter/BaseStreamFormatter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BaseStreamFormatter.java 1 Feb 2002 23:53:22 -0000 1.1
+++ BaseStreamFormatter.java 3 Feb 2002 13:23:52 -0000 1.2
@@ -63,6 +63,7 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.optional.rjunit.KeepAliveOutputStream;
+import org.apache.tools.ant.taskdefs.optional.rjunit.remote.TestRunEvent;
/**
* Base formatter providing default implementation to deal with
@@ -85,6 +86,11 @@
/** writer to output the data to */
private PrintWriter writer;
+ protected void finalize() throws Throwable {
+ super.finalize();
+ close();
+ }
+
public void init(Properties props) throws BuildException {
String file = props.getProperty(FILE_KEY);
OutputStream os = null;
@@ -106,13 +112,17 @@
*/
protected void setOutput(OutputStream value) {
try {
- writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(value, "UTF8")), true);
+ // do not buffer but flush each line.
+ writer = new PrintWriter(new OutputStreamWriter(value, "UTF8"), true);
} catch (IOException e) {
// should not happen
throw new BuildException(e);
}
}
+ public void onRunEnded(TestRunEvent evt) {
+ close();
+ }
protected void close() {
if (writer != null) {
1.2 +2 -2 jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/rjunit/formatter/Resources.properties
Index: Resources.properties
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/rjunit/formatter/Resources.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Resources.properties 1 Feb 2002 23:53:22 -0000 1.1
+++ Resources.properties 3 Feb 2002 13:23:52 -0000 1.2
@@ -1,6 +1,6 @@
# Summary formatter
-summary.finished.msg = TestSuite: \nTests run: {0, number, integer}, Failures: {1, number, integer}, Errors: {2, number, integer}, Time elapsed: {3, number, integer} sec\n
-
+suite.summary.msg = TestSuite: {0}\nTests run: {1, number, integer}, Failures: {2, number, integer}, Errors: {3, number, integer}, Time elapsed: {4, number, integer} sec
+run.summary.msg=Tests run: {0, number, integer}, Failures: {1, number, integer}, Errors: {2, number, integer}, Time elapsed: {3, number, integer} sec
# Brief formatter
brief.status-error.msg = TestCase: {0}\tCaused an ERROR\n{1}\n
brief.status-failure.msg = TestCase: {0}\tFAILED\n{1}\n
1.2 +19 -7 jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/rjunit/formatter/SummaryFormatter.java
Index: SummaryFormatter.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/rjunit/formatter/SummaryFormatter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SummaryFormatter.java 1 Feb 2002 23:53:22 -0000 1.1
+++ SummaryFormatter.java 3 Feb 2002 13:23:52 -0000 1.2
@@ -55,6 +55,8 @@
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
+import org.apache.tools.ant.taskdefs.optional.rjunit.remote.TestRunEvent;
+import org.apache.tools.ant.taskdefs.optional.rjunit.remote.TestSummary;
/**
* Display a summary message at the end of a testsuite stating
@@ -67,14 +69,24 @@
private final static Resources RES =
ResourceManager.getPackageResources(SummaryFormatter.class);
- protected void finished(long elapsedtime) {
- String msg = RES.getString("summary.finished.msg",
- new Integer(getRunCount()),
- new Integer(getFailureCount()),
- new Integer(getErrorCount()),
- new Long(elapsedtime / 1000));
+ public void onSuiteEnded(TestRunEvent evt) {
+ TestSummary summary = evt.getSummary();
+ String msg = RES.getString("suite.summary.msg",
+ evt.getName(),
+ new Integer(summary.runCount()),
+ new Integer(summary.failureCount()),
+ new Integer(summary.errorCount()),
+ new Long(summary.elapsedTime()/1000));
getWriter().println(msg);
- close();
}
+ public void onRunEnded(TestRunEvent evt) {
+ TestSummary summary = evt.getSummary();
+ String msg = RES.getString("run.summary.msg",
+ new Integer(summary.runCount()),
+ new Integer(summary.failureCount()),
+ new Integer(summary.errorCount()),
+ new Long(summary.elapsedTime()/1000));
+ getWriter().println(msg);
+ }
}
1.2 +3 -18 jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/rjunit/formatter/XMLFormatter.java
Index: XMLFormatter.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/rjunit/formatter/XMLFormatter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLFormatter.java 1 Feb 2002 23:53:22 -0000 1.1
+++ XMLFormatter.java 3 Feb 2002 13:23:52 -0000 1.2
@@ -148,21 +148,19 @@
currentTest.setAttribute(ATTR_NAME, evt.getName());
rootElement.appendChild(currentTest);
testElements.put(evt.getName(), currentTest);
- super.onTestStarted(evt);
- removeEvent(evt);
+ //removeEvent(evt);
}
public void onTestEnded(TestRunEvent evt) {
- Element currentTest = (Element) testElements.get(evt);
+ Element currentTest = (Element) testElements.get(evt.getName());
// with a TestSetup, startTest and endTest are not called.
if (currentTest == null) {
onTestStarted(evt);
currentTest = (Element) testElements.get(evt.getName());
}
- TestRunEvent start = (TestRunEvent)testStarts.get(evt);
+ TestRunEvent start = (TestRunEvent)testStarts.get(evt.getName());
float time = ((evt.getTimeStamp() - start.getTimeStamp()) / 1000.0f);
currentTest.setAttribute(ATTR_TIME, Float.toString(time));
- super.onTestEnded(evt);
removeEvent(evt);
}
@@ -179,25 +177,12 @@
nested.setAttribute(ATTR_TYPE, args[0]);
Text text = doc.createTextNode(evt.getStackTrace());
nested.appendChild(text);
- super.onTestFailure(evt);
removeEvent(evt);
}
protected void removeEvent(TestRunEvent evt){
testStarts.remove(evt.getName());
testElements.remove(evt.getName());
- }
-
- public void onRunStarted(TestRunEvent evt) {
- super.onRunStarted(evt);
- }
-
- public void onRunEnded(TestRunEvent evt) {
- super.onRunEnded(evt);
- }
-
- public void onRunStopped(TestRunEvent evt) {
- super.onRunStopped(evt);
}
protected void close() {
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>