ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit FormatterElement.java JUnitTask.java
Date Thu, 14 Sep 2000 08:13:06 GMT
bodewig     00/09/14 01:13:06

  Modified:    .        build.xml
               docs     junit.html
               src/main/org/apache/tools/ant/taskdefs/optional/junit
                        FormatterElement.java JUnitTask.java
  Log:
  Added usefile attribute to <formatter> to allow testoutput to be sent
  to stdout instead of a file.
  
  Revision  Changes    Path
  1.71      +3 -1      jakarta-ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/build.xml,v
  retrieving revision 1.70
  retrieving revision 1.71
  diff -u -r1.70 -r1.71
  --- build.xml	2000/09/14 07:19:50	1.70
  +++ build.xml	2000/09/14 08:13:04	1.71
  @@ -315,7 +315,9 @@
           <pathelement path="${java.class.path}" />
         </classpath>
   
  -      <batchtest>
  +      <formatter type="plain" usefile="false" />
  +
  +      <batchtest fork="yes">
           <fileset dir="${src.tests.dir}">
             <include name="**/*Test*" />
             <exclude name="**/All*" />
  
  
  
  1.8       +10 -3     jakarta-ant/docs/junit.html
  
  Index: junit.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/junit.html,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- junit.html	2000/09/07 09:50:52	1.7
  +++ junit.html	2000/09/14 08:13:05	1.8
  @@ -91,9 +91,10 @@
   <h4>formatter</h4>
   
   <p>The results of the tests can be printed in different
  -formats. Output will always be sent to a file, the name of the file is
  -determined by the name of the test and can be set by the
  -<code>outfile</code> attribute of <code>&lt;test&gt;</code>.
  +formats. Output will always be sent to a file unless you set the
  +usefile attribute to false, the name of the file is determined by the
  +name of the test and can be set by the <code>outfile</code> attribute
  +of <code>&lt;test&gt;</code>.
   
   <p>There are two predefined formatters, one prints the test results in
   XML format, the other emits plain text. Custom formatters that need to
  @@ -120,6 +121,12 @@
       <td valign="top">extension</td> 
       <td valign="top">Extension to append to the output filename.</td>
       <td align="center">Yes, if classname has been used.</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">usefile</td> 
  +    <td valign="top">Boolean that determines whether output should be
  +      sent to a file.</td>
  +    <td align="center">No, default true.</td>
     </tr>
   </table>
   
  
  
  
  1.2       +10 -1     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
  
  Index: FormatterElement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FormatterElement.java	2000/08/09 13:12:12	1.1
  +++ FormatterElement.java	2000/09/14 08:13:05	1.2
  @@ -73,6 +73,7 @@
       private String extension;
       private OutputStream out = System.out;
       private File outFile;
  +    private boolean useFile = true;
   
       public void setType(TypeAttribute type) {
           if ("xml".equals(type.getValue())) {
  @@ -108,6 +109,14 @@
           this.out = out;
       }
   
  +    public void setUseFile(boolean useFile) {
  +        this.useFile = useFile;
  +    }
  +
  +    boolean getUseFile() {
  +        return useFile;
  +    }
  +
       JUnitResultFormatter createFormatter() throws BuildException {
           if (classname == null) {
               throw new BuildException("you must specify type or classname");
  @@ -135,7 +144,7 @@
   
           JUnitResultFormatter r = (JUnitResultFormatter) o;
   
  -        if (outFile != null) {
  +        if (useFile && outFile != null) {
               try {
                   out = new FileOutputStream(outFile);
               } catch (java.io.IOException e) {
  
  
  
  1.8       +37 -12    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JUnitTask.java	2000/09/06 14:05:00	1.7
  +++ JUnitTask.java	2000/09/14 08:13:06	1.8
  @@ -193,6 +193,9 @@
               }
   
               int exitValue = JUnitTestRunner.ERRORS;
  +            
  +            System.err.println(test.getFork());
  +
               if (!test.getFork()) {
                   JUnitTestRunner runner = 
                       new JUnitTestRunner(test, test.getHaltonerror(),
  @@ -208,14 +211,22 @@
   
                   for (int i=0; i<formatters.size(); i++) {
                       FormatterElement fe = (FormatterElement) formatters.elementAt(i);
  -                    fe.setOutfile(project.resolveFile(test.getOutfile()
  -                                                      +fe.getExtension()));
  +                    if (fe.getUseFile()) {
  +                        fe.setOutfile(project.resolveFile(test.getOutfile()
  +                                                          +fe.getExtension()));
  +                    } else {
  +                        fe.setOutput(new LogOutputStream(this, Project.MSG_INFO));
  +                    }
                       runner.addFormatter(fe.createFormatter());
                   }
                   FormatterElement[] add = test.getFormatters();
                   for (int i=0; i<add.length; i++) {
  -                    add[i].setOutfile(project.resolveFile(test.getOutfile()
  -                                                          +add[i].getExtension()));
  +                    if (add[i].getUseFile()) {
  +                        add[i].setOutfile(project.resolveFile(test.getOutfile()
  +                                                              +add[i].getExtension()));
  +                    } else {
  +                        add[i].setOutput(new LogOutputStream(this, Project.MSG_INFO));
  +                    }
                       runner.addFormatter(add[i].createFormatter());
                   }
   
  @@ -237,24 +248,38 @@
                       cmd.createArgument().setValue("formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter");
                   }
   
  +                StringBuffer formatterArg = new StringBuffer();
                   for (int i=0; i<formatters.size(); i++) {
                       FormatterElement fe = (FormatterElement) formatters.elementAt(i);
  -                    cmd.createArgument().setValue("formatter=" +
  -                                                  fe.getClassname() + ","
  -                                                  + project.resolveFile(test.getOutfile()
  -                                                                               +fe.getExtension()).getAbsolutePath());
  +                    formatterArg.append("formatter=");
  +                    formatterArg.append(fe.getClassname());
  +                    if (fe.getUseFile()) {
  +                        formatterArg.append(",");
  +                        formatterArg.append(project.resolveFile(test.getOutfile()
  +                                                                +fe.getExtension())
  +                                            .getAbsolutePath());
  +                    }
  +                    cmd.createArgument().setValue(formatterArg.toString());
  +                    formatterArg.setLength(0);
                   }
                   
                   FormatterElement[] add = test.getFormatters();
                   for (int i=0; i<add.length; i++) {
  -                    cmd.createArgument().setValue("formatter=" +
  -                                                  add[i].getClassname() + ","
  -                                                  + project.resolveFile(test.getOutfile()
  -                                                                               +add[i].getExtension()).getAbsolutePath());
  +                    formatterArg.append("formatter=");
  +                    formatterArg.append(add[i].getClassname());
  +                    if (add[i].getUseFile()) {
  +                        formatterArg.append(",");
  +                        formatterArg.append(project.resolveFile(test.getOutfile()
  +                                                                +add[i].getExtension())
  +                                            .getAbsolutePath());
  +                    }
  +                    cmd.createArgument().setValue(formatterArg.toString());
  +                    formatterArg.setLength(0);
                   }
   
                   Execute execute = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
Project.MSG_WARN), createWatchdog());
                   execute.setCommandline(cmd.getCommandline());
  +                log("Executing: "+cmd.toString(), Project.MSG_VERBOSE);
                   try {
                       exitValue = execute.execute();
                   } catch (IOException e) {
  
  
  

Mime
View raw message