ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit BriefJUnitResultFormatter.java PlainJUnitResultFormatter.java XMLJUnitResultFormatter.java
Date Mon, 29 Oct 2001 14:25:07 GMT
bodewig     01/10/29 06:25:07

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/taskdefs/optional/junit
                        BriefJUnitResultFormatter.java
                        PlainJUnitResultFormatter.java
                        XMLJUnitResultFormatter.java
  Log:
  formatters assumed that only one test could be running at the same
  time, this is not true.
  
  PR: 2442
  
  Revision  Changes    Path
  1.162     +4 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.161
  retrieving revision 1.162
  diff -u -r1.161 -r1.162
  --- WHATSNEW	2001/10/26 09:36:40	1.161
  +++ WHATSNEW	2001/10/29 14:25:07	1.162
  @@ -20,6 +20,10 @@
   
   * <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:
   --------------
   
  
  
  
  1.5       +2 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java
  
  Index: BriefJUnitResultFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BriefJUnitResultFormatter.java	2001/10/28 21:30:22	1.4
  +++ BriefJUnitResultFormatter.java	2001/10/29 14:25:07	1.5
  @@ -242,7 +242,8 @@
       /**
        * 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) {
               endTest(test);
           }
  
  
  
  1.9       +27 -19    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java
  
  Index: PlainJUnitResultFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- PlainJUnitResultFormatter.java	2001/10/28 21:30:22	1.8
  +++ PlainJUnitResultFormatter.java	2001/10/29 14:25:07	1.9
  @@ -61,6 +61,7 @@
   import java.io.PrintWriter;
   import java.io.IOException;
   import java.text.NumberFormat;
  +import java.util.Hashtable;
   
   import junit.framework.AssertionFailedError;
   import junit.framework.Test;
  @@ -81,7 +82,7 @@
       /**
        * Timing helper.
        */
  -    private long lastTestStart = 0;
  +    private Hashtable testStarts = new Hashtable();
       /**
        * Where to write the log to.
        */
  @@ -97,7 +98,7 @@
       /**
        * Suppress endTest if testcase failed.
        */
  -    private boolean failed = true;
  +    private Hashtable failed = new Hashtable();
   
       private String systemOutput = null;
       private String systemError = null;
  @@ -187,10 +188,8 @@
        * <p>A new Test is started.
        */
       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 @@
        * <p>A Test is finished.
        */
       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 @@
       }
   
       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
  
  
  
  1.14      +16 -8     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java
  
  Index: XMLJUnitResultFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- XMLJUnitResultFormatter.java	2001/10/28 21:30:22	1.13
  +++ XMLJUnitResultFormatter.java	2001/10/29 14:25:07	1.14
  @@ -64,6 +64,7 @@
   
   import java.util.Properties;
   import java.util.Enumeration;
  +import java.util.Hashtable;
   import javax.xml.parsers.DocumentBuilder;
   import javax.xml.parsers.DocumentBuilderFactory;
   import org.w3c.dom.Document;
  @@ -107,11 +108,11 @@
       /**
        * Element for the current test.
        */
  -    private Element currentTest;
  +    private Hashtable testElements = new Hashtable();
       /**
        * Timing helper.
        */
  -    private long lastTestStart = 0;
  +    private Hashtable testStarts = new Hashtable();
       /**
        * Where to write the log to.
        */
  @@ -167,7 +168,7 @@
               Writer wri = null;
               try {
                   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, "  ");
                   wri.flush();
               } catch(IOException exc) {
  @@ -190,11 +191,13 @@
        * <p>A new Test is started.
        */
       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, 
                                    JUnitVersionHelper.getTestCaseName((TestCase) t));
           rootElement.appendChild(currentTest);
  +        testElements.put(t, currentTest);
       }
   
       /**
  @@ -203,8 +206,10 @@
        * <p>A Test is finished.
        */
       public void endTest(Test test) {
  +        Element currentTest = (Element) testElements.get(test);
  +        Long l = (Long) testStarts.get(test);
           currentTest.setAttribute(ATTR_TIME,
  -                                 ""+((System.currentTimeMillis()-lastTestStart)
  +                                 ""+((System.currentTimeMillis()-l.longValue())
                                              / 1000.0));
       }
   
  @@ -241,11 +246,14 @@
           }
   
           Element nested = doc.createElement(type);
  +        Element currentTest = null;
           if (test != null) {
  -            currentTest.appendChild(nested);
  +            currentTest = (Element) testElements.get(test);
           } else {
  -            rootElement.appendChild(nested);
  +            currentTest = rootElement;
           }
  +
  +        currentTest.appendChild(nested);
   
           String message = t.getMessage();
           if (message != null && message.length() > 0) {
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message