configured at runtime. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267990 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -317,7 +317,7 @@ | |||||
| <formatter type="plain" usefile="false" /> | <formatter type="plain" usefile="false" /> | ||||
| <batchtest fork="yes"> | |||||
| <batchtest> | |||||
| <fileset dir="${src.tests.dir}"> | <fileset dir="${src.tests.dir}"> | ||||
| <include name="**/*Test*" /> | <include name="**/*Test*" /> | ||||
| <exclude name="**/All*" /> | <exclude name="**/All*" /> | ||||
| @@ -0,0 +1,107 @@ | |||||
| /* | |||||
| * The Apache Software License, Version 1.1 | |||||
| * | |||||
| * Copyright (c) 2000 The Apache Software Foundation. All rights | |||||
| * reserved. | |||||
| * | |||||
| * Redistribution and use in source and binary forms, with or without | |||||
| * modification, are permitted provided that the following conditions | |||||
| * are met: | |||||
| * | |||||
| * 1. Redistributions of source code must retain the above copyright | |||||
| * notice, this list of conditions and the following disclaimer. | |||||
| * | |||||
| * 2. Redistributions in binary form must reproduce the above copyright | |||||
| * notice, this list of conditions and the following disclaimer in | |||||
| * the documentation and/or other materials provided with the | |||||
| * distribution. | |||||
| * | |||||
| * 3. The end-user documentation included with the redistribution, if | |||||
| * any, must include the following acknowlegement: | |||||
| * "This product includes software developed by the | |||||
| * Apache Software Foundation (http://www.apache.org/)." | |||||
| * Alternately, this acknowlegement may appear in the software itself, | |||||
| * if and wherever such third-party acknowlegements normally appear. | |||||
| * | |||||
| * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software | |||||
| * Foundation" must not be used to endorse or promote products derived | |||||
| * from this software without prior written permission. For written | |||||
| * permission, please contact apache@apache.org. | |||||
| * | |||||
| * 5. Products derived from this software may not be called "Apache" | |||||
| * nor may "Apache" appear in their names without prior written | |||||
| * permission of the Apache Group. | |||||
| * | |||||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
| * SUCH DAMAGE. | |||||
| * ==================================================================== | |||||
| * | |||||
| * This software consists of voluntary contributions made by many | |||||
| * individuals on behalf of the Apache Software Foundation. For more | |||||
| * information on the Apache Software Foundation, please see | |||||
| * <http://www.apache.org/>. | |||||
| */ | |||||
| package org.apache.tools.ant.taskdefs.optional.junit; | |||||
| import java.util.Vector; | |||||
| /** | |||||
| * Baseclass for BatchTest and JUnitTest. | |||||
| * | |||||
| * @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a> | |||||
| */ | |||||
| public abstract class BaseTest { | |||||
| protected boolean haltOnError = false; | |||||
| protected boolean haltOnFail = false; | |||||
| protected boolean fork = false; | |||||
| protected String ifProperty = null; | |||||
| protected String unlessProperty = null; | |||||
| protected Vector formatters = new Vector(); | |||||
| public void setFork(boolean value) { | |||||
| fork = value; | |||||
| } | |||||
| public boolean getFork() { | |||||
| return fork; | |||||
| } | |||||
| public void setHaltonerror(boolean value) { | |||||
| haltOnError = value; | |||||
| } | |||||
| public void setHaltonfailure(boolean value) { | |||||
| haltOnFail = value; | |||||
| } | |||||
| public boolean getHaltonerror() { | |||||
| return haltOnError; | |||||
| } | |||||
| public boolean getHaltonfailure() { | |||||
| return haltOnFail; | |||||
| } | |||||
| public void setIf(String propertyName) { | |||||
| ifProperty = propertyName; | |||||
| } | |||||
| public void setUnless(String propertyName) { | |||||
| unlessProperty = propertyName; | |||||
| } | |||||
| public void addFormatter(FormatterElement elem) { | |||||
| formatters.addElement(elem); | |||||
| } | |||||
| } | |||||
| @@ -68,16 +68,10 @@ import java.util.*; | |||||
| * @author <a href="mailto:jeff.martin@synamic.co.uk">Jeff Martin</a> | * @author <a href="mailto:jeff.martin@synamic.co.uk">Jeff Martin</a> | ||||
| * @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a> | ||||
| */ | */ | ||||
| public final class BatchTest { | |||||
| private boolean fork=false; | |||||
| private boolean haltOnError=false; | |||||
| private boolean haltOnFailure=false; | |||||
| public final class BatchTest extends BaseTest { | |||||
| private Project project; | private Project project; | ||||
| private String ifCond = null; | |||||
| private String unlessCond = null; | |||||
| private Vector filesets = new Vector(); | private Vector filesets = new Vector(); | ||||
| private Vector formatters = new Vector(); | |||||
| public BatchTest(Project project){ | public BatchTest(Project project){ | ||||
| this.project = project; | this.project = project; | ||||
| @@ -87,30 +81,10 @@ public final class BatchTest { | |||||
| filesets.addElement(fs); | filesets.addElement(fs); | ||||
| } | } | ||||
| public void addFormatter(FormatterElement elem) { | |||||
| formatters.addElement(elem); | |||||
| } | |||||
| public void setIf(String propertyName) { | |||||
| ifCond = propertyName; | |||||
| } | |||||
| public void setUnless(String propertyName) { | |||||
| unlessCond = propertyName; | |||||
| } | |||||
| public final void setFork(boolean value) { | |||||
| this.fork = value; | |||||
| } | |||||
| public final void setHaltonerror(boolean value) { | |||||
| this.haltOnError = value; | |||||
| } | |||||
| public final void setHaltonfailure(boolean value) { | |||||
| this.haltOnFailure = value; | |||||
| } | |||||
| public final Enumeration elements(){ | public final Enumeration elements(){ | ||||
| return new FileList(); | return new FileList(); | ||||
| } | } | ||||
| public class FileList implements Enumeration{ | public class FileList implements Enumeration{ | ||||
| private String files[]=null; | private String files[]=null; | ||||
| private int i=0; | private int i=0; | ||||
| @@ -142,10 +116,10 @@ public final class BatchTest { | |||||
| if(hasMoreElements()){ | if(hasMoreElements()){ | ||||
| JUnitTest test = new JUnitTest(javaToClass(files[i])); | JUnitTest test = new JUnitTest(javaToClass(files[i])); | ||||
| test.setHaltonerror(haltOnError); | test.setHaltonerror(haltOnError); | ||||
| test.setHaltonfailure(haltOnFailure); | |||||
| test.setHaltonfailure(haltOnFail); | |||||
| test.setFork(fork); | test.setFork(fork); | ||||
| test.setIf(ifCond); | |||||
| test.setUnless(unlessCond); | |||||
| test.setIf(ifProperty); | |||||
| test.setUnless(unlessProperty); | |||||
| Enumeration list = formatters.elements(); | Enumeration list = formatters.elements(); | ||||
| while (list.hasMoreElements()) { | while (list.hasMoreElements()) { | ||||
| test.addFormatter((FormatterElement)list.nextElement()); | test.addFormatter((FormatterElement)list.nextElement()); | ||||
| @@ -92,16 +92,23 @@ public class JUnitTask extends Task { | |||||
| private Vector batchTests = new Vector(); | private Vector batchTests = new Vector(); | ||||
| private Vector formatters = new Vector(); | private Vector formatters = new Vector(); | ||||
| private JUnitTest defaults = new JUnitTest(); | |||||
| private Integer timeout = null; | private Integer timeout = null; | ||||
| private boolean summary = false; | private boolean summary = false; | ||||
| public void setHaltonerror(boolean value) { | public void setHaltonerror(boolean value) { | ||||
| defaults.setHaltonerror(value); | |||||
| Enumeration enum = allTests(); | |||||
| while (enum.hasMoreElements()) { | |||||
| BaseTest test = (BaseTest) enum.nextElement(); | |||||
| test.setHaltonerror(value); | |||||
| } | |||||
| } | } | ||||
| public void setHaltonfailure(boolean value) { | public void setHaltonfailure(boolean value) { | ||||
| defaults.setHaltonfailure(value); | |||||
| Enumeration enum = allTests(); | |||||
| while (enum.hasMoreElements()) { | |||||
| BaseTest test = (BaseTest) enum.nextElement(); | |||||
| test.setHaltonfailure(value); | |||||
| } | |||||
| } | } | ||||
| public void setPrintsummary(boolean value) { | public void setPrintsummary(boolean value) { | ||||
| @@ -114,7 +121,6 @@ public class JUnitTask extends Task { | |||||
| } else { | } else { | ||||
| createJvmarg().setValue("-Xmx"+max); | createJvmarg().setValue("-Xmx"+max); | ||||
| } | } | ||||
| } | } | ||||
| public void setTimeout(Integer value) { | public void setTimeout(Integer value) { | ||||
| @@ -122,7 +128,11 @@ public class JUnitTask extends Task { | |||||
| } | } | ||||
| public void setFork(boolean value) { | public void setFork(boolean value) { | ||||
| defaults.setFork(value); | |||||
| Enumeration enum = allTests(); | |||||
| while (enum.hasMoreElements()) { | |||||
| BaseTest test = (BaseTest) enum.nextElement(); | |||||
| test.setFork(value); | |||||
| } | |||||
| } | } | ||||
| public void setJvm(String value) { | public void setJvm(String value) { | ||||
| @@ -138,17 +148,11 @@ public class JUnitTask extends Task { | |||||
| } | } | ||||
| public void addTest(JUnitTest test) { | public void addTest(JUnitTest test) { | ||||
| test.setHaltonerror(defaults.getHaltonerror()); | |||||
| test.setHaltonfailure(defaults.getHaltonfailure()); | |||||
| test.setFork(defaults.getFork()); | |||||
| tests.addElement(test); | tests.addElement(test); | ||||
| } | } | ||||
| public BatchTest createBatchTest() { | public BatchTest createBatchTest() { | ||||
| BatchTest test = new BatchTest(project); | BatchTest test = new BatchTest(project); | ||||
| test.setHaltonerror(defaults.getHaltonerror()); | |||||
| test.setHaltonfailure(defaults.getHaltonfailure()); | |||||
| test.setFork(defaults.getFork()); | |||||
| batchTests.addElement(test); | batchTests.addElement(test); | ||||
| return test; | return test; | ||||
| } | } | ||||
| @@ -171,16 +175,18 @@ public class JUnitTask extends Task { | |||||
| boolean errorOccurred = false; | boolean errorOccurred = false; | ||||
| boolean failureOccurred = false; | boolean failureOccurred = false; | ||||
| Vector runTests = (Vector) tests.clone(); | |||||
| Enumeration list = batchTests.elements(); | Enumeration list = batchTests.elements(); | ||||
| while (list.hasMoreElements()) { | while (list.hasMoreElements()) { | ||||
| BatchTest test = (BatchTest)list.nextElement(); | BatchTest test = (BatchTest)list.nextElement(); | ||||
| Enumeration list2 = test.elements(); | Enumeration list2 = test.elements(); | ||||
| while (list2.hasMoreElements()) { | while (list2.hasMoreElements()) { | ||||
| tests.addElement(list2.nextElement()); | |||||
| runTests.addElement(list2.nextElement()); | |||||
| } | } | ||||
| } | } | ||||
| list = tests.elements(); | |||||
| list = runTests.elements(); | |||||
| while (list.hasMoreElements()) { | while (list.hasMoreElements()) { | ||||
| JUnitTest test = (JUnitTest)list.nextElement(); | JUnitTest test = (JUnitTest)list.nextElement(); | ||||
| @@ -194,8 +200,6 @@ public class JUnitTask extends Task { | |||||
| int exitValue = JUnitTestRunner.ERRORS; | int exitValue = JUnitTestRunner.ERRORS; | ||||
| System.err.println(test.getFork()); | |||||
| if (!test.getFork()) { | if (!test.getFork()) { | ||||
| JUnitTestRunner runner = | JUnitTestRunner runner = | ||||
| new JUnitTestRunner(test, test.getHaltonerror(), | new JUnitTestRunner(test, test.getHaltonerror(), | ||||
| @@ -312,4 +316,24 @@ public class JUnitTask extends Task { | |||||
| if (dest.exists()) dest.delete(); | if (dest.exists()) dest.delete(); | ||||
| src.renameTo(dest); | src.renameTo(dest); | ||||
| } | } | ||||
| protected Enumeration allTests() { | |||||
| return new Enumeration() { | |||||
| private Enumeration testEnum = tests.elements(); | |||||
| private Enumeration batchEnum = batchTests.elements(); | |||||
| public boolean hasMoreElements() { | |||||
| return testEnum.hasMoreElements() || | |||||
| batchEnum.hasMoreElements(); | |||||
| } | |||||
| public Object nextElement() { | |||||
| if (testEnum.hasMoreElements()) { | |||||
| return testEnum.nextElement(); | |||||
| } | |||||
| return batchEnum.nextElement(); | |||||
| } | |||||
| }; | |||||
| } | |||||
| } | } | ||||
| @@ -65,18 +65,13 @@ import java.util.Vector; | |||||
| * @author Thomas Haas | * @author Thomas Haas | ||||
| * @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a> | ||||
| */ | */ | ||||
| public class JUnitTest { | |||||
| private boolean haltOnError = false; | |||||
| private boolean haltOnFail = false; | |||||
| public class JUnitTest extends BaseTest { | |||||
| private String name = null; | private String name = null; | ||||
| private File outfile = null; | private File outfile = null; | ||||
| private boolean fork = false; | |||||
| private long runs, failures, errors; | private long runs, failures, errors; | ||||
| private long runTime; | private long runTime; | ||||
| private Vector formatters = new Vector(); | |||||
| public JUnitTest() { | public JUnitTest() { | ||||
| } | } | ||||
| @@ -90,22 +85,6 @@ public class JUnitTest { | |||||
| this.haltOnFail = haltOnFail; | this.haltOnFail = haltOnFail; | ||||
| } | } | ||||
| public void setFork(boolean value) { | |||||
| fork = value; | |||||
| } | |||||
| public boolean getFork() { | |||||
| return fork; | |||||
| } | |||||
| public void setHaltonerror(boolean value) { | |||||
| haltOnError = value; | |||||
| } | |||||
| public void setHaltonfailure(boolean value) { | |||||
| haltOnFail = value; | |||||
| } | |||||
| public void setName(String value) { | public void setName(String value) { | ||||
| name = value; | name = value; | ||||
| } | } | ||||
| @@ -114,14 +93,6 @@ public class JUnitTest { | |||||
| outfile = value; | outfile = value; | ||||
| } | } | ||||
| public boolean getHaltonerror() { | |||||
| return haltOnError; | |||||
| } | |||||
| public boolean getHaltonfailure() { | |||||
| return haltOnFail; | |||||
| } | |||||
| public String getName() { | public String getName() { | ||||
| return name; | return name; | ||||
| } | } | ||||
| @@ -148,17 +119,6 @@ public class JUnitTest { | |||||
| public long errorCount() {return errors;} | public long errorCount() {return errors;} | ||||
| public long getRunTime() {return runTime;} | public long getRunTime() {return runTime;} | ||||
| private String ifProperty = null; | |||||
| private String unlessProperty = null; | |||||
| public void setIf(String propertyName) { | |||||
| ifProperty = propertyName; | |||||
| } | |||||
| public void setUnless(String propertyName) { | |||||
| unlessProperty = propertyName; | |||||
| } | |||||
| public boolean shouldRun(Project p) { | public boolean shouldRun(Project p) { | ||||
| if (ifProperty != null && p.getProperty(ifProperty) == null) { | if (ifProperty != null && p.getProperty(ifProperty) == null) { | ||||
| return false; | return false; | ||||
| @@ -169,10 +129,6 @@ public class JUnitTest { | |||||
| return true; | return true; | ||||
| } | } | ||||
| public void addFormatter(FormatterElement elem) { | |||||
| formatters.addElement(elem); | |||||
| } | |||||
| public FormatterElement[] getFormatters() { | public FormatterElement[] getFormatters() { | ||||
| FormatterElement[] fes = new FormatterElement[formatters.size()]; | FormatterElement[] fes = new FormatterElement[formatters.size()]; | ||||
| formatters.copyInto(fes); | formatters.copyInto(fes); | ||||