http://issues.apache.org/bugzilla/show_bug.cgi?id=31962

Easiest fix for this is to change the code so that the initial line "Testsuite: " is printed as soon as the tests start. As there were a couple of places where this occured I made a new private method that handled the logging to log file jsu to reduce teh amount of duplicated code (I assume that the user would still want the output recorded to the log file).

So now endTestSuite only writes result information, and startTestSuite writes out the name of the Testsuite thats about to run.

*Not tested as I don't have time to write a jUnit test, this could blow up completely*

Kev
Index: BriefJUnitResultFormatter.java
===================================================================
RCS file: 
/home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java,v
retrieving revision 1.15
diff -u -r1.15 BriefJUnitResultFormatter.java
--- BriefJUnitResultFormatter.java      9 Mar 2004 16:48:31 -0000       1.15
+++ BriefJUnitResultFormatter.java      11 Nov 2004 06:53:37 -0000
@@ -91,11 +91,55 @@
         systemError = err;
     }
 
+    private StringBuffer appendToLog(StringBuffer sb, String newLine) {
+        //append the err and output streams to the log
+        if (systemOutput != null && systemOutput.length() > 0) {
+            sb.append("------------- Standard Output ---------------")
+                .append(newLine)
+                .append(systemOutput)
+                .append("------------- ---------------- ---------------")
+                .append(newLine);
+        }
+
+        if (systemError != null && systemError.length() > 0) {
+            sb.append("------------- Standard Error -----------------")
+                .append(newLine)
+                .append(systemError)
+                .append("------------- ---------------- ---------------")
+                .append(newLine);
+        }
 
+        return sb.append(newLine);
+    }
+    
+    
     /**
      * The whole testsuite started.
      */
     public void startTestSuite(JUnitTest suite) throws BuildException {
+        String newLine = System.getProperty("line.separator");
+        StringBuffer sb = new StringBuffer("Testsuite: ");
+        sb.append(suite.getName());
+        sb.append(newLine);
+        
+        appendToLog(sb, newLine);
+        
+        if (output != null) {
+            try {
+                output.write(sb.toString());
+                resultWriter.close();
+                output.write(results.toString());
+                output.flush();
+            } finally {
+                if (out != System.out && out != System.err) {
+                    try {
+                        out.close();
+                    } catch (IOException e) {
+                        // ignore
+                    }
+                }
+            }
+        }
     }
 
     /**
@@ -103,10 +147,7 @@
      */
     public void endTestSuite(JUnitTest suite) throws BuildException {
         String newLine = System.getProperty("line.separator");
-        StringBuffer sb = new StringBuffer("Testsuite: ");
-        sb.append(suite.getName());
-        sb.append(newLine);
-        sb.append("Tests run: ");
+        StringBuffer sb = new StringBuffer("Tests run:");
         sb.append(suite.runCount());
         sb.append(", Failures: ");
         sb.append(suite.failureCount());
@@ -118,22 +159,7 @@
         sb.append(newLine);
         sb.append(newLine);
 
-        // append the err and output streams to the log
-        if (systemOutput != null && systemOutput.length() > 0) {
-            sb.append("------------- Standard Output ---------------")
-                    .append(newLine)
-                    .append(systemOutput)
-                    .append("------------- ---------------- ---------------")
-                    .append(newLine);
-        }
-
-        if (systemError != null && systemError.length() > 0) {
-            sb.append("------------- Standard Error -----------------")
-                    .append(newLine)
-                    .append(systemError)
-                    .append("------------- ---------------- ---------------")
-                    .append(newLine);
-        }
+        appendToLog(sb, newLine);
 
         if (output != null) {
             try {
Index: PlainJUnitResultFormatter.java
===================================================================
RCS file: 
/home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java,v
retrieving revision 1.25
diff -u -r1.25 PlainJUnitResultFormatter.java
--- PlainJUnitResultFormatter.java      9 Mar 2004 16:48:31 -0000       1.25
+++ PlainJUnitResultFormatter.java      11 Nov 2004 06:53:37 -0000
@@ -80,10 +80,56 @@
         systemError = err;
     }
 
+    private StringBuffer appendToLog(StringBuffer sb, String newLine) {
+        //append the err and output streams to the log
+        if (systemOutput != null && systemOutput.length() > 0) {
+            sb.append("------------- Standard Output ---------------")
+                .append(newLine)
+                .append(systemOutput)
+                .append("------------- ---------------- ---------------")
+                .append(newLine);
+        }
+
+        if (systemError != null && systemError.length() > 0) {
+            sb.append("------------- Standard Error -----------------")
+                .append(newLine)
+                .append(systemError)
+                .append("------------- ---------------- ---------------")
+                .append(newLine);
+        }
+
+        return sb.append(newLine);
+    }
+    
     /**
-     * Empty.
+     * Testsuite started, write out testsuite name
      */
     public void startTestSuite(JUnitTest suite) {
+        String newLine = System.getProperty("line.separator");
+        StringBuffer sb = new StringBuffer("Testsuite: ");
+        sb.append(suite.getName());
+        sb.append(newLine);
+        
+        appendToLog(sb, newLine);
+        
+        if (out != null) {
+            try {
+                out.write(sb.toString().getBytes());
+                wri.close();
+                out.write(inner.toString().getBytes());
+                out.flush();
+            } catch (IOException ioex) {
+                throw new BuildException("Unable to write output", ioex);
+            } finally {
+                if (out != System.out && out != System.err) {
+                    try {
+                        out.close();
+                    } catch (IOException e) {
+                        // ignore
+                    }
+                }
+            }
+        }
     }
 
     /**
@@ -91,10 +137,7 @@
      */
     public void endTestSuite(JUnitTest suite) throws BuildException {
         String newLine = System.getProperty("line.separator");
-        StringBuffer sb = new StringBuffer("Testsuite: ");
-        sb.append(suite.getName());
-        sb.append(newLine);
-        sb.append("Tests run: ");
+        StringBuffer sb = new StringBuffer("Tests run: ");
         sb.append(suite.runCount());
         sb.append(", Failures: ");
         sb.append(suite.failureCount());
@@ -105,24 +148,7 @@
         sb.append(" sec");
         sb.append(newLine);
 
-        // append the err and output streams to the log
-        if (systemOutput != null && systemOutput.length() > 0) {
-            sb.append("------------- Standard Output ---------------")
-                .append(newLine)
-                .append(systemOutput)
-                .append("------------- ---------------- ---------------")
-                .append(newLine);
-        }
-
-        if (systemError != null && systemError.length() > 0) {
-            sb.append("------------- Standard Error -----------------")
-                .append(newLine)
-                .append(systemError)
-                .append("------------- ---------------- ---------------")
-                .append(newLine);
-        }
-
-        sb.append(newLine);
+        appendToLog(sb, newLine);
 
         if (out != null) {
             try {

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to