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 JUnitTask.java
Date Wed, 06 Nov 2002 10:47:50 GMT
bodewig     2002/11/06 02:47:50

  Modified:    .        Tag: ANT_15_BRANCH WHATSNEW
               src/main/org/apache/tools/ant/taskdefs/optional/junit Tag:
                        ANT_15_BRANCH JUnitTask.java
  Log:
  Merge from HEAD
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.263.2.90 +2 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.263.2.89
  retrieving revision 1.263.2.90
  diff -u -r1.263.2.89 -r1.263.2.90
  --- WHATSNEW	31 Oct 2002 13:55:08 -0000	1.263.2.89
  +++ WHATSNEW	6 Nov 2002 10:47:49 -0000	1.263.2.90
  @@ -13,6 +13,8 @@
   * The "plain" <junit> <formatter> could throw a NullPointerException
     if an error occured in setUp.
   
  +* <junit> will now produce output when a test times out as well.
  +
   Changes from Ant 1.5.1Beta1 to 1.5.1
   ====================================
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.44.2.2  +60 -16    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.44.2.1
  retrieving revision 1.44.2.2
  diff -u -r1.44.2.1 -r1.44.2.2
  --- JUnitTask.java	22 Jun 2002 23:40:23 -0000	1.44.2.1
  +++ JUnitTask.java	6 Nov 2002 10:47:49 -0000	1.44.2.2
  @@ -81,6 +81,10 @@
   
   import java.net.URL;
   
  +import junit.framework.AssertionFailedError;
  +import junit.framework.Test;
  +import junit.framework.TestResult;
  +
   /**
    * Runs JUnit tests.
    *
  @@ -145,6 +149,7 @@
    * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a>
    * @author <a href="mailto:Gerrit.Riessen@web.de">Gerrit Riessen</a>
    * @author <a href="mailto:ehatcher@apache.org">Erik Hatcher</a>
  + * @author <a href="mailto:martijn@kruithof.xs4all.nl">Martijn Kruithof></a>
    *
    * @version $Revision$
    *
  @@ -406,7 +411,7 @@
        * @since Ant 1.2
        */
       public Path createClasspath() {
  -        return commandline.createClasspath(project).createPath();
  +        return commandline.createClasspath(getProject()).createPath();
       }
   
       /**
  @@ -451,7 +456,7 @@
        * @since Ant 1.2
        */
       public BatchTest createBatchTest() {
  -        BatchTest test = new BatchTest(project);
  +        BatchTest test = new BatchTest(getProject());
           batchTests.addElement(test);
           return test;
       }
  @@ -523,7 +528,7 @@
           Enumeration list = getIndividualTests();
           while (list.hasMoreElements()) {
               JUnitTest test = (JUnitTest) list.nextElement();
  -            if (test.shouldRun(project)) {
  +            if (test.shouldRun(getProject())) {
                   execute(test);
               }
           }
  @@ -537,7 +542,7 @@
           // set the default values if not specified
           //@todo should be moved to the test class instead.
           if (test.getTodir() == null) {
  -            test.setTodir(project.resolveFile("."));
  +            test.setTodir(getProject().resolveFile("."));
           }
   
           if (test.getOutfile() == null) {
  @@ -566,15 +571,15 @@
               if ((errorOccurredHere && test.getHaltonerror())
                   || (failureOccurredHere && test.getHaltonfailure())) {
                   throw new BuildException("Test " + test.getName() + " failed"
  -                    + (wasKilled ? " (timeout)" : ""), location);
  +                    + (wasKilled ? " (timeout)" : ""), getLocation());
               } else {
                   log("TEST " + test.getName() + " FAILED"
                       + (wasKilled ? " (timeout)" : ""), Project.MSG_ERR);
                   if (errorOccurredHere && test.getErrorProperty() != null) {
  -                    project.setNewProperty(test.getErrorProperty(), "true");
  +                    getProject().setNewProperty(test.getErrorProperty(), "true");
                   }
                   if (failureOccurredHere && test.getFailureProperty() != null) {
  -                    project.setNewProperty(test.getFailureProperty(), "true");
  +                    getProject().setNewProperty(test.getFailureProperty(), "true");
                   }
               }
           }
  @@ -635,10 +640,10 @@
           // forked test
           File propsFile = 
               FileUtils.newFileUtils().createTempFile("junit", ".properties",
  -                                                    project.getBaseDir());
  +                                                    getProject().getBaseDir());
           cmd.createArgument().setValue("propsfile=" 
                                         + propsFile.getAbsolutePath());
  -        Hashtable p = project.getProperties();
  +        Hashtable p = getProject().getProperties();
           Properties props = new Properties();
           for (Enumeration enum = p.keys(); enum.hasMoreElements();) {
               Object key = enum.nextElement();
  @@ -651,7 +656,7 @@
           } catch (java.io.IOException e) {
               propsFile.delete();
               throw new BuildException("Error creating temporary properties "
  -                                     + "file.", e, location);
  +                                     + "file.", e, getLocation());
           }
   
           Execute execute = new Execute(new LogStreamHandler(this, 
  @@ -659,7 +664,7 @@
                                                              Project.MSG_WARN),
                                         watchdog);
           execute.setCommandline(cmd.getCommandline());
  -        execute.setAntRun(project);
  +        execute.setAntRun(getProject());
           if (dir != null) {
               execute.setWorkingDirectory(dir);
           }
  @@ -679,8 +684,12 @@
           try {
               retVal = execute.execute();
           } catch (IOException e) {
  -            throw new BuildException("Process fork failed.", e, location);
  +            throw new BuildException("Process fork failed.", e, getLocation());
           } finally {
  +            if (watchdog.killedProcess()) {
  +                logTimeout(feArray, test);
  +            }
  +
               if (!propsFile.delete()) {
                   throw new BuildException("Could not delete temporary "
                                            + "properties file.");
  @@ -734,7 +743,7 @@
        */
       private int executeInVM(JUnitTest arg) throws BuildException {
           JUnitTest test = (JUnitTest) arg.clone();
  -        test.setProperties(project.getProperties());
  +        test.setProperties(getProject().getProperties());
           if (dir != null) {
               log("dir attribute ignored if running in the same VM", 
                   Project.MSG_WARN);
  @@ -765,7 +774,7 @@
                       classpath.append(antRuntimeClasses);
                   }
   
  -                cl = new AntClassLoader(null, project, classpath, false);
  +                cl = new AntClassLoader(null, getProject(), classpath, false);
                   log("Using CLASSPATH " + cl.getClasspath(),
                       Project.MSG_VERBOSE);
   
  @@ -882,7 +891,7 @@
               String filename = test.getOutfile() + fe.getExtension();
               File destFile = new File(test.getTodir(), filename);
               String absFilename = destFile.getAbsolutePath();
  -            return project.resolveFile(absFilename);
  +            return getProject().resolveFile(absFilename);
           }
           return null;
       }
  @@ -920,6 +929,41 @@
               }
           } else {
               log("Couldn\'t find " + resource, Project.MSG_DEBUG);
  +        }
  +    }
  +
  +    /**
  +     * Take care that some output is produced in report files if the 
  +     * watchdog kills the test.
  +     *
  +     * @since Ant 1.5.2
  +     */
  +
  +    private void logTimeout(FormatterElement[] feArray, JUnitTest test) {
  +        for (int i = 0; i < feArray.length; i++) {
  +            FormatterElement fe = feArray[i];
  +            File outFile = getOutput(fe, test);
  +            JUnitResultFormatter formatter = fe.createFormatter();
  +            if (outFile != null && formatter != null) {
  +                try {
  +                    OutputStream out = new FileOutputStream(outFile);
  +                    formatter.setOutput(out);
  +                    formatter.startTestSuite(test);
  +                    test.setCounts(0,0,1);
  +                    Test t = new Test() {
  +                        public int countTestCases() { return 0; }
  +                        public void run(TestResult r) { 
  +                            throw new AssertionFailedError("Timeout occured");
  +                        }
  +                    };
  +                    formatter.startTest(t);
  +                    formatter
  +                        .addError(t, 
  +                                  new AssertionFailedError("Timeout occured"));
  +
  +                    formatter.endTestSuite(test);
  +                } catch (IOException e) {}
  +            }
           }
       }
   
  
  
  

--
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