git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268059 13f79535-47bb-0310-9956-ffa450edef68master
@@ -298,7 +298,7 @@ | |||||
<!-- Run testcase --> | <!-- Run testcase --> | ||||
<!-- =================================================================== --> | <!-- =================================================================== --> | ||||
<target name="runtests" depends="compiletests" if="junit.present"> | <target name="runtests" depends="compiletests" if="junit.present"> | ||||
<junit printsummary="no" fork="yes" haltonfailure="yes"> | |||||
<junit printsummary="no" haltonfailure="yes"> | |||||
<classpath> | <classpath> | ||||
<pathelement location="${lib.dir}/${name}.jar" /> | <pathelement location="${lib.dir}/${name}.jar" /> | ||||
<pathelement location="${build.tests}" /> | <pathelement location="${build.tests}" /> | ||||
@@ -330,7 +330,7 @@ | |||||
</target> | </target> | ||||
<target name="run.single.test" if="testcase" depends="compiletests"> | <target name="run.single.test" if="testcase" depends="compiletests"> | ||||
<junit printsummary="no" fork="yes" haltonfailure="yes"> | |||||
<junit printsummary="no" haltonfailure="yes"> | |||||
<classpath> | <classpath> | ||||
<pathelement location="${lib.dir}/${name}.jar" /> | <pathelement location="${lib.dir}/${name}.jar" /> | ||||
<pathelement location="${build.tests}" /> | <pathelement location="${build.tests}" /> | ||||
@@ -76,8 +76,7 @@ elements</a>.</p> | |||||
<p><code>junit</code> supports a nested <code><classpath></code> | <p><code>junit</code> supports a nested <code><classpath></code> | ||||
element, that represents a <a href="index.html#path">PATH like | element, that represents a <a href="index.html#path">PATH like | ||||
structure</a>. The value is ignored if <code>fork</code> is | |||||
disabled.</p> | |||||
structure</a>.</p> | |||||
<h4>jvmarg</h4> | <h4>jvmarg</h4> | ||||
@@ -20,22 +20,26 @@ | |||||
<target name="test5"> | <target name="test5"> | ||||
<filter token="year" value="2000" /> | <filter token="year" value="2000" /> | ||||
<copyfile src="filter1.txt" dest="filtered.tmp" filtering="yes"/> | |||||
<copy file="filter1.txt" tofile="filtered.tmp" filtering="yes" overwrite="yes" /> | |||||
</target> | </target> | ||||
<target name="test6"> | <target name="test6"> | ||||
<filter token="year" value="2000" /> | <filter token="year" value="2000" /> | ||||
<copydir src="." dest="./taskdefs.tmp" filtering="yes" includes="filter1.txt"/> | |||||
<copy todir="./taskdefs.tmp" filtering="yes" overwrite="yes"> | |||||
<fileset dir="." includes="filter1.txt" /> | |||||
</copy> | |||||
</target> | </target> | ||||
<target name="test7"> | <target name="test7"> | ||||
<filter token="ROOT" value="root" /> | <filter token="ROOT" value="root" /> | ||||
<copyfile src="filter2.txt" dest="filtered.tmp" filtering="yes"/> | |||||
<copy file="filter2.txt" tofile="filtered.tmp" filtering="yes" overwrite="yes" /> | |||||
</target> | </target> | ||||
<target name="test8"> | <target name="test8"> | ||||
<filter token="ROOT" value="root" /> | <filter token="ROOT" value="root" /> | ||||
<copydir src="." dest="./taskdefs.tmp" filtering="yes" includes="filter2.txt"/> | |||||
<copy todir="./taskdefs.tmp" filtering="yes" overwrite="yes"> | |||||
<fileset dir="." includes="filter2.txt"/> | |||||
</copy> | |||||
</target> | </target> | ||||
</project> | </project> |
@@ -19,7 +19,7 @@ | |||||
</target> | </target> | ||||
<target name="test5"> | <target name="test5"> | ||||
<taskdef name="test" classname="org.apache.tools.ant.ProjectTest"/> | |||||
<taskdef name="test" classname="org.apache.tools.ant.Project" /> | |||||
</target> | </target> | ||||
</project> | </project> |
@@ -113,6 +113,7 @@ public class AntClassLoader extends ClassLoader { | |||||
if (project.getJavaVersion().startsWith("1.1")) { | if (project.getJavaVersion().startsWith("1.1")) { | ||||
// JDK > 1.1 adds these by default | // JDK > 1.1 adds these by default | ||||
addSystemPackageRoot("java"); | addSystemPackageRoot("java"); | ||||
addSystemPackageRoot("javax"); | |||||
} | } | ||||
} | } | ||||
@@ -749,7 +749,7 @@ public class Javac extends MatchingTask { | |||||
try { | try { | ||||
/* | /* | ||||
* Many system have been reported to get into trouble with | * Many system have been reported to get into trouble with | ||||
* long command lines - no, not only Windows 8^). | |||||
* long command lines - no, not only Windows ;-). | |||||
* | * | ||||
* POSIX seems to define a lower limit of 4k, so use a temporary | * POSIX seems to define a lower limit of 4k, so use a temporary | ||||
* file if the total length of the command line exceeds this limit. | * file if the total length of the command line exceeds this limit. | ||||
@@ -54,6 +54,7 @@ | |||||
package org.apache.tools.ant.taskdefs.optional.junit; | package org.apache.tools.ant.taskdefs.optional.junit; | ||||
import org.apache.tools.ant.AntClassLoader; | |||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
@@ -76,14 +77,13 @@ import java.util.Vector; | |||||
* | * | ||||
* <p>JUnit is a framework to create unit test. It has been initially | * <p>JUnit is a framework to create unit test. It has been initially | ||||
* created by Erich Gamma and Kent Beck. JUnit can be found at <a | * created by Erich Gamma and Kent Beck. JUnit can be found at <a | ||||
* href="http://www.xprogramming.com/software.htm">http://www.xprogramming.com/software.htm</a>. | |||||
* href="http://www.junit.org">http://www.junit.org</a>. | |||||
* | * | ||||
* <p> This ant task runs a single TestCase. By default it spans a new | |||||
* Java VM to prevent interferences between different testcases, | |||||
* unless <code>fork</code> has been disabled. | |||||
* <p> To spawn a new Java VM to prevent interferences between | |||||
* different testcases, you need to enable <code>fork</code>. | |||||
* | * | ||||
* @author Thomas Haas | * @author Thomas Haas | ||||
* @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a> | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
*/ | */ | ||||
public class JUnitTask extends Task { | public class JUnitTask extends Task { | ||||
@@ -217,9 +217,24 @@ public class JUnitTask extends Task { | |||||
Project.MSG_WARN); | Project.MSG_WARN); | ||||
} | } | ||||
JUnitTestRunner runner = | |||||
new JUnitTestRunner(test, test.getHaltonerror(), | |||||
test.getHaltonfailure()); | |||||
JUnitTestRunner runner = null; | |||||
Path classpath = commandline.getClasspath(); | |||||
if (classpath != null) { | |||||
log("Using CLASSPATH " + classpath, Project.MSG_VERBOSE); | |||||
AntClassLoader l = new AntClassLoader(project, classpath, | |||||
false); | |||||
// make sure the test will be accepted as a TestCase | |||||
l.addSystemPackageRoot("junit"); | |||||
// will cause trouble in JDK 1.1 if omitted | |||||
l.addSystemPackageRoot("org.apache.tools.ant"); | |||||
runner = new JUnitTestRunner(test, test.getHaltonerror(), | |||||
test.getHaltonfailure(), l); | |||||
} else { | |||||
runner = new JUnitTestRunner(test, test.getHaltonerror(), | |||||
test.getHaltonfailure()); | |||||
} | |||||
if (summary) { | if (summary) { | ||||
log("Running " + test.getName(), Project.MSG_INFO); | log("Running " + test.getName(), Project.MSG_INFO); | ||||
@@ -75,7 +75,7 @@ import java.util.Vector; | |||||
* | * | ||||
* <p>Summary output is generated at the end. | * <p>Summary output is generated at the end. | ||||
* | * | ||||
* @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a> | |||||
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
*/ | */ | ||||
public class JUnitTestRunner implements TestListener { | public class JUnitTestRunner implements TestListener { | ||||
@@ -135,14 +135,31 @@ public class JUnitTestRunner implements TestListener { | |||||
*/ | */ | ||||
private JUnitTest junitTest; | private JUnitTest junitTest; | ||||
/** | |||||
* Constructor for fork=true or when the user hasn't specified a | |||||
* classpath. | |||||
*/ | |||||
public JUnitTestRunner(JUnitTest test, boolean haltOnError, | public JUnitTestRunner(JUnitTest test, boolean haltOnError, | ||||
boolean haltOnFailure) { | boolean haltOnFailure) { | ||||
this(test, haltOnError, haltOnFailure, null); | |||||
} | |||||
/** | |||||
* Constructor to use when the user has specified a classpath. | |||||
*/ | |||||
public JUnitTestRunner(JUnitTest test, boolean haltOnError, | |||||
boolean haltOnFailure, ClassLoader loader) { | |||||
this.junitTest = test; | this.junitTest = test; | ||||
this.haltOnError = haltOnError; | this.haltOnError = haltOnError; | ||||
this.haltOnFailure = haltOnFailure; | this.haltOnFailure = haltOnFailure; | ||||
try { | try { | ||||
Class testClass = Class.forName(test.getName()); | |||||
Class testClass = null; | |||||
if (loader == null) { | |||||
testClass = Class.forName(test.getName()); | |||||
} else { | |||||
testClass = loader.loadClass(test.getName()); | |||||
} | |||||
try { | try { | ||||
Method suiteMethod= testClass.getMethod("suite", new Class[0]); | Method suiteMethod= testClass.getMethod("suite", new Class[0]); | ||||