Browse Source

An attempt to run JUnit task tests in Surefire

(please note different exclude rules than for compiler…)
master
Gintas Grigelionis 6 years ago
parent
commit
9558adefe7
6 changed files with 129 additions and 90 deletions
  1. +37
    -7
      src/etc/poms/ant-junit/pom.xml
  2. +16
    -3
      src/etc/poms/ant-junitlauncher/pom.xml
  3. +68
    -74
      src/etc/testcases/taskdefs/optional/junit.xml
  4. +5
    -4
      src/etc/testcases/taskdefs/optional/junit/teardownlistener.xml
  5. +1
    -1
      src/etc/testcases/taskdefs/optional/junitlauncher.xml
  6. +2
    -1
      src/tests/junit/org/apache/tools/ant/types/PathTest.java

+ 37
- 7
src/etc/poms/ant-junit/pom.xml View File

@@ -48,6 +48,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<version>4.12</version> <version>4.12</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.0</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
@@ -55,16 +61,15 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<artifactId>maven-antrun-plugin</artifactId> <artifactId>maven-antrun-plugin</artifactId>
<executions> <executions>
<execution> <execution>
<id>create-timestamp-file</id>
<phase>generate-resources</phase>
<id>copy-junit-xsl</id>
<phase>process-classes</phase>
<goals> <goals>
<goal>run</goal> <goal>run</goal>
</goals> </goals>
<configuration> <configuration>
<tasks> <tasks>
<mkdir dir="${project.build.outputDirectory}"/>
<copy todir="${project.build.outputDirectory}/org/apache/tools/ant/taskdefs/optional/junit/xsl"> <copy todir="${project.build.outputDirectory}/org/apache/tools/ant/taskdefs/optional/junit/xsl">
<fileset dir="${project.build.sourceDirectory}/../etc">
<fileset dir="${project.build.scriptSourceDirectory}">
<include name="junit-frames.xsl"/> <include name="junit-frames.xsl"/>
<include name="junit-noframes.xsl"/> <include name="junit-noframes.xsl"/>
<include name="junit-frames-saxon.xsl"/> <include name="junit-frames-saxon.xsl"/>
@@ -84,11 +89,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<include>org/apache/tools/ant/taskdefs/optional/junit/*</include> <include>org/apache/tools/ant/taskdefs/optional/junit/*</include>
</includes> </includes>
<excludes> <excludes>
<exclude>org/apache/tools/ant/taskdefs/optional/junit/JUnit4TestMethodAdapter*</exclude>
<exclude>org/apache/tools/ant/taskdefs/optional/junit/CustomJUnit4TestAdapterCache*</exclude>
<exclude>org/apache/tools/ant/taskdefs/optional/junit/JUnit4TestMethodAdapter*</exclude>
<exclude>org/apache/tools/ant/taskdefs/optional/junit/CustomJUnit4TestAdapterCache*</exclude>
</excludes> </excludes>
<testIncludes> <testIncludes>
<include>org/apache/tools/ant/taskdefs/optional/junit/</include> <include>org/apache/tools/ant/taskdefs/optional/junit/</include>
<include>org/example/junit/</include>
<include>org/example/tasks/*.java</include>
<include>org/example/types/</include>
</testIncludes> </testIncludes>
</configuration> </configuration>
</plugin> </plugin>
@@ -112,7 +120,20 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<configuration> <configuration>
<basedir>../../../..</basedir> <basedir>../../../..</basedir>
<workingDirectory>../../../..</workingDirectory> <workingDirectory>../../../..</workingDirectory>
<skipTests>true</skipTests>
<systemProperties>
<property>
<name>build.tests.value</name>
<value>${project.basedir}/../../../../target/${project.artifactId}/testcases</value>
</property>
<property>
<name>ant.test.basedir.ignore</name>
<value>true</value>
</property>
</systemProperties>
<excludes>
<exclude>org/example/junit/*</exclude>
<exclude>org/apache/tools/ant/taskdefs/optional/junit/*$*</exclude>
</excludes>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
@@ -126,8 +147,17 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
</includes> </includes>
</resource> </resource>
</resources> </resources>
<testResources>
<testResource>
<directory>../../../../src/tests/junit</directory>
<includes>
<include>org/example/tasks/*.xml</include>
</includes>
</testResource>
</testResources>
<sourceDirectory>../../../../src/main</sourceDirectory> <sourceDirectory>../../../../src/main</sourceDirectory>
<testSourceDirectory>../../../../src/tests/junit</testSourceDirectory> <testSourceDirectory>../../../../src/tests/junit</testSourceDirectory>
<scriptSourceDirectory>../../../../src/etc</scriptSourceDirectory>
<outputDirectory>../../../../target/${project.artifactId}/classes</outputDirectory> <outputDirectory>../../../../target/${project.artifactId}/classes</outputDirectory>
<testOutputDirectory>../../../../target/${project.artifactId}/testcases</testOutputDirectory> <testOutputDirectory>../../../../target/${project.artifactId}/testcases</testOutputDirectory>
<directory>../../../../target/${project.artifactId}</directory> <directory>../../../../target/${project.artifactId}</directory>


+ 16
- 3
src/etc/poms/ant-junitlauncher/pom.xml View File

@@ -68,10 +68,11 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration> <configuration>
<includes> <includes>
<include>org/apache/tools/ant/taskdefs/optional/junitlauncher/*</include>
<include>org/apache/tools/ant/taskdefs/optional/junitlauncher/</include>
</includes> </includes>
<testIncludes> <testIncludes>
<include>org/apache/tools/ant/taskdefs/optional/junitlauncher/*</include>
<include>org/apache/tools/ant/taskdefs/optional/junitlauncher/</include>
<include>org/example/junitlauncher/</include>
</testIncludes> </testIncludes>
</configuration> </configuration>
</plugin> </plugin>
@@ -95,7 +96,19 @@
<configuration> <configuration>
<basedir>../../../..</basedir> <basedir>../../../..</basedir>
<workingDirectory>../../../..</workingDirectory> <workingDirectory>../../../..</workingDirectory>
<skipTests>true</skipTests>
<systemProperties>
<property>
<name>build.tests.value</name>
<value>${project.basedir}/../../../../target/${project.artifactId}/testcases</value>
</property>
<property>
<name>ant.test.basedir.ignore</name>
<value>true</value>
</property>
</systemProperties>
<excludes>
<exclude>org/example/junitlauncher/**</exclude>
</excludes>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>


+ 68
- 74
src/etc/testcases/taskdefs/optional/junit.xml View File

@@ -20,85 +20,85 @@
<import file="../../buildfiletest-base.xml"/> <import file="../../buildfiletest-base.xml"/>


<target name="setUp"> <target name="setUp">
<mkdir dir="${output}" />
<mkdir dir="${output}"/>
</target> </target>


<property name="showoutput" value="false" />
<property name="showoutput" value="false"/>

<path id="test"> <path id="test">
<pathelement path="${java.class.path}" />
<pathelement location="../../../../../build/testcases" />
<pathelement path="${java.class.path}"/>
<pathelement location="${build.tests.value}"/>
</path> </path>


<target name="testForkedOutput"> <target name="testForkedOutput">
<junit fork="yes" haltonerror="true" haltonfailure="true" <junit fork="yes" haltonerror="true" haltonfailure="true"
showoutput="${showoutput}"> showoutput="${showoutput}">
<test name="org.example.junit.Output" />
<classpath refid="test" />
<test name="org.example.junit.Output"/>
<classpath refid="test"/>
</junit> </junit>
</target> </target>


<target name="testNonForkedOutput"> <target name="testNonForkedOutput">
<junit fork="false" haltonerror="true" haltonfailure="true" <junit fork="false" haltonerror="true" haltonfailure="true"
showoutput="${showoutput}"> showoutput="${showoutput}">
<test name="org.example.junit.Output" />
<classpath refid="test" />
<test name="org.example.junit.Output"/>
<classpath refid="test"/>
</junit> </junit>
</target> </target>


<target name="testForkedThreadedOutput"> <target name="testForkedThreadedOutput">
<junit fork="yes" haltonerror="true" haltonfailure="true" <junit fork="yes" haltonerror="true" haltonfailure="true"
showoutput="${showoutput}"> showoutput="${showoutput}">
<test name="org.example.junit.ThreadedOutput" />
<classpath refid="test" />
<test name="org.example.junit.ThreadedOutput"/>
<classpath refid="test"/>
</junit> </junit>
</target> </target>


<target name="testNonForkedThreadedOutput"> <target name="testNonForkedThreadedOutput">
<junit fork="false" haltonerror="true" haltonfailure="true" <junit fork="false" haltonerror="true" haltonfailure="true"
showoutput="${showoutput}"> showoutput="${showoutput}">
<test name="org.example.junit.ThreadedOutput" />
<classpath refid="test" />
<test name="org.example.junit.ThreadedOutput"/>
<classpath refid="test"/>
</junit> </junit>
</target> </target>


<target name="outputTests" <target name="outputTests"
depends="testForkedOutput,testNonForkedOutput,testForkedThreadedOutput,testNonForkedThreadedOutput" />
depends="testForkedOutput,testNonForkedOutput,testForkedThreadedOutput,testNonForkedThreadedOutput"/>


<target name="crash"> <target name="crash">
<junit fork="true" errorproperty="crashed"> <junit fork="true" errorproperty="crashed">
<test name="org.apache.tools.ant.taskdefs.optional.junit.VmCrash"/> <test name="org.apache.tools.ant.taskdefs.optional.junit.VmCrash"/>
<classpath refid="test" />
<classpath refid="test"/>
</junit> </junit>
</target> </target>


<target name="nocrash"> <target name="nocrash">
<junit fork="true" errorproperty="crashed"> <junit fork="true" errorproperty="crashed">
<test name="org.apache.tools.ant.taskdefs.optional.junit.NoVmCrash"/> <test name="org.apache.tools.ant.taskdefs.optional.junit.NoVmCrash"/>
<classpath refid="test" />
<classpath refid="test"/>
</junit> </junit>
</target> </target>


<target name="timeout"> <target name="timeout">
<junit fork="true" errorproperty="timeout" timeout="1000"> <junit fork="true" errorproperty="timeout" timeout="1000">
<test name="org.apache.tools.ant.taskdefs.optional.junit.Sleeper"/> <test name="org.apache.tools.ant.taskdefs.optional.junit.Sleeper"/>
<classpath refid="test" />
<classpath refid="test"/>
</junit> </junit>
</target> </target>


<target name="notimeout"> <target name="notimeout">
<junit fork="true" errorproperty="timeout" timeout="15000"> <junit fork="true" errorproperty="timeout" timeout="15000">
<test name="org.apache.tools.ant.taskdefs.optional.junit.Sleeper"/> <test name="org.apache.tools.ant.taskdefs.optional.junit.Sleeper"/>
<classpath refid="test" />
<classpath refid="test"/>
</junit> </junit>
</target> </target>


<target name="capture" depends="setUp"> <target name="capture" depends="setUp">
<property name="fork" value="false"/> <property name="fork" value="false"/>
<junit fork="${fork}"> <junit fork="${fork}">
<test
name="org.apache.tools.ant.taskdefs.optional.junit.Printer"
todir="${output}"
outfile="testlog"/>
<test name="org.apache.tools.ant.taskdefs.optional.junit.Printer"
todir="${output}"
outfile="testlog"/>
<formatter type="plain"/> <formatter type="plain"/>
<classpath refid="test"/> <classpath refid="test"/>
</junit> </junit>
@@ -120,8 +120,7 @@
<classpath refid="test"/> <classpath refid="test"/>
<batchtest todir="${output}"> <batchtest todir="${output}">
<fileset dir="../../../../tests/junit"> <fileset dir="../../../../tests/junit">
<include
name="org/apache/tools/ant/taskdefs/optional/junit/*Test.java"/>
<include name="org/apache/tools/ant/taskdefs/optional/junit/*Test.java"/>
<!-- tests remove out-dir on tearDown --> <!-- tests remove out-dir on tearDown -->
<exclude name="**/JUnitTestListenerTest.java"/> <exclude name="**/JUnitTestListenerTest.java"/>
<exclude name="**/JUnitTaskTest.java"/> <exclude name="**/JUnitTaskTest.java"/>
@@ -139,8 +138,7 @@
<classpath refid="test"/> <classpath refid="test"/>
<batchtest todir="${output}"> <batchtest todir="${output}">
<fileset dir="../../../../tests/junit"> <fileset dir="../../../../tests/junit">
<include
name="org/apache/tools/ant/taskdefs/optional/junit/*Test.java"/>
<include name="org/apache/tools/ant/taskdefs/optional/junit/*Test.java"/>
<!-- tests remove out-dir on tearDown --> <!-- tests remove out-dir on tearDown -->
<exclude name="**/JUnitTestListenerTest.java"/> <exclude name="**/JUnitTestListenerTest.java"/>
<exclude name="**/JUnitTaskTest.java"/> <exclude name="**/JUnitTaskTest.java"/>
@@ -154,12 +152,11 @@
<mkdir dir="${output}"/> <mkdir dir="${output}"/>
<junit fork="true" forkmode="once"> <junit fork="true" forkmode="once">
<formatter extension="foo" <formatter extension="foo"
classname="org.apache.tools.ant.taskdefs.optional.junit.TestFormatter"/>
classname="org.apache.tools.ant.taskdefs.optional.junit.TestFormatter"/>
<classpath refid="test"/> <classpath refid="test"/>
<batchtest todir="${output}"> <batchtest todir="${output}">
<fileset dir="../../../../tests/junit"> <fileset dir="../../../../tests/junit">
<include
name="org/apache/tools/ant/taskdefs/optional/junit/*Test.java"/>
<include name="org/apache/tools/ant/taskdefs/optional/junit/*Test.java"/>
<!-- tests remove out-dir on tearDown --> <!-- tests remove out-dir on tearDown -->
<exclude name="**/JUnitTestListenerTest.java"/> <exclude name="**/JUnitTestListenerTest.java"/>
<exclude name="**/JUnitTaskTest.java"/> <exclude name="**/JUnitTaskTest.java"/>
@@ -244,8 +241,7 @@
<ant target="failureRecorder.internal" <ant target="failureRecorder.internal"
antfile="junit.xml" antfile="junit.xml"
inheritAll="false" inheritAll="false"
inheritRefs="false"
/>
inheritRefs="false"/>
</target> </target>
<target name="failureRecorder.fixing"> <target name="failureRecorder.fixing">
@@ -281,47 +277,46 @@
<target name="testSkippableTests"> <target name="testSkippableTests">
<mkdir dir="${output}"/> <mkdir dir="${output}"/>
<junit> <junit>
<formatter type="xml"/>
<classpath refid="test"/>
<batchtest todir="${output}">
<fileset dir="../../../../tests/junit">
<include name="org/example/junit/JUnit4Skippable.java"/>
<!-- tests remove out-dir on tearDown -->
</fileset>
</batchtest>
<formatter type="xml"/>
<classpath refid="test"/>
<batchtest todir="${output}">
<fileset dir="../../../../tests/junit">
<include name="org/example/junit/JUnit4Skippable.java"/>
<!-- tests remove out-dir on tearDown -->
</fileset>
</batchtest>
</junit> </junit>
</target> </target>



<!-- Skipping classes that are not tests --> <!-- Skipping classes that are not tests -->
<target name="testNonTests"> <target name="testNonTests">
<mkdir dir="${output}"/> <mkdir dir="${output}"/>
<junit>
<formatter type="xml"/>
<classpath refid="test"/>
<batchtest todir="${output}" skipNonTests="true">
<fileset dir="../../../../tests/junit">
<include name="org/example/junit/*Missed.java"/>
<!-- tests remove out-dir on tearDown -->
</fileset>
</batchtest>
<junit>
<formatter type="xml"/>
<classpath refid="test"/>
<batchtest todir="${output}" skipNonTests="true">
<fileset dir="../../../../tests/junit">
<include name="org/example/junit/*Missed.java"/>
<!-- tests remove out-dir on tearDown -->
</fileset>
</batchtest>
</junit> </junit>
</target> </target>


<!-- Not skipping classes that are not tests -->
<target name="testNonTestsRun">
<mkdir dir="${output}"/>
<junit>
<formatter type="xml"/>
<classpath refid="test"/>
<batchtest todir="${output}" skipNonTests="false">
<fileset dir="../../../../tests/junit">
<include name="org/example/junit/*Missed.java"/>
<!-- tests remove out-dir on tearDown -->
</fileset>
</batchtest>
</junit>
</target>
<!-- Not skipping classes that are not tests -->
<target name="testNonTestsRun">
<mkdir dir="${output}"/>
<junit>
<formatter type="xml"/>
<classpath refid="test"/>
<batchtest todir="${output}" skipNonTests="false">
<fileset dir="../../../../tests/junit">
<include name="org/example/junit/*Missed.java"/>
<!-- tests remove out-dir on tearDown -->
</fileset>
</batchtest>
</junit>
</target>


<target name="testTestMethods" > <target name="testTestMethods" >
<property name="tmp.dir" value="${output}"/> <property name="tmp.dir" value="${output}"/>
@@ -342,29 +337,28 @@
<property name="source" value="8"/> <property name="source" value="8"/>
<javac srcdir="${tmp.dir}" destdir="${tmp.dir}" includes="T1.java,T2.java" <javac srcdir="${tmp.dir}" destdir="${tmp.dir}" includes="T1.java,T2.java"
source="${source}"> source="${source}">

</javac> </javac>
<junit fork="false" printsummary="true" haltonerror="true"> <junit fork="false" printsummary="true" haltonerror="true">
<classpath> <classpath>
<pathelement location="${tmp.dir}" />
<path refid="test" />
<pathelement location="${tmp.dir}"/>
<path refid="test"/>
</classpath> </classpath>
<test name="T1" methods="testOK" />
<test name="T2" methods="ok" />
<test name="T1" methods="testOK"/>
<test name="T2" methods="ok"/>
</junit> </junit>
</target> </target>


<target name="testCheckForkedPath"> <target name="testCheckForkedPath">
<property name="includeantruntime" value="yes" />
<property name="includeantruntime" value="yes"/>
<!-- duplicate the Ant classes into a jar --> <!-- duplicate the Ant classes into a jar -->
<jar destfile="${output}/ant.jar" basedir="${antclasses}" />
<jar destfile="${output}/ant.jar" basedir="${antclasses}"/>
<junit fork="yes" haltonerror="true" haltonfailure="true" <junit fork="yes" haltonerror="true" haltonfailure="true"
showoutput="${showoutput}" includeantruntime="${includeantruntime}">
<test name="org.example.junit.Output" />
showoutput="${showoutput}" includeantruntime="${includeantruntime}">
<test name="org.example.junit.Output"/>
<classpath> <classpath>
<pathelement location="../../../../../build/testcases" />
<pathelement location="${junitjar}" />
<pathelement location="${output}/ant.jar" />
<pathelement location="${build.tests.value}"/>
<pathelement location="${junitjar}"/>
<pathelement location="${output}/ant.jar"/>
</classpath> </classpath>
</junit> </junit>
</target> </target>


+ 5
- 4
src/etc/testcases/taskdefs/optional/junit/teardownlistener.xml View File

@@ -18,15 +18,15 @@
<project> <project>


<path id="test"> <path id="test">
<pathelement path="${java.class.path}" />
<pathelement location="../../../../../../build/testcases" />
<pathelement path="${java.class.path}"/>
<pathelement location="${build.tests.value}"/>
</path> </path>


<target name="testNoTeardown"> <target name="testNoTeardown">
<junit haltonerror="false" errorproperty="error" fork="true" timeout="1000"> <junit haltonerror="false" errorproperty="error" fork="true" timeout="1000">
<formatter type="plain" usefile="false"/> <formatter type="plain" usefile="false"/>
<batchtest> <batchtest>
<fileset dir="../../../../../../build/testcases">
<fileset dir="${build.tests.value}">
<include name="org/example/junit/Timeout*"/> <include name="org/example/junit/Timeout*"/>
</fileset> </fileset>
</batchtest> </batchtest>
@@ -40,11 +40,12 @@
<formatter classname="org.apache.tools.ant.taskdefs.optional.junit.TearDownOnVmCrash" <formatter classname="org.apache.tools.ant.taskdefs.optional.junit.TearDownOnVmCrash"
usefile="false"/> usefile="false"/>
<batchtest> <batchtest>
<fileset dir="../../../../../../build/testcases">
<fileset dir="${build.tests.value}">
<include name="org/example/junit/Timeout*"/> <include name="org/example/junit/Timeout*"/>
</fileset> </fileset>
</batchtest> </batchtest>
<classpath refid="test"/> <classpath refid="test"/>
</junit> </junit>
</target> </target>

</project> </project>

+ 1
- 1
src/etc/testcases/taskdefs/optional/junitlauncher.xml View File

@@ -19,7 +19,7 @@
<project name="junitlauncher-test" basedir="."> <project name="junitlauncher-test" basedir=".">


<property name="output.dir" location="${java.io.tmpdir}"/> <property name="output.dir" location="${java.io.tmpdir}"/>
<property name="build.classes.dir" value="../../../../../build/testcases"/>
<property name="build.classes.dir" value="${build.tests.value}"/>
<target name="init"> <target name="init">
<mkdir dir="${output.dir}"/> <mkdir dir="${output.dir}"/>
</target> </target>


+ 2
- 1
src/tests/junit/org/apache/tools/ant/types/PathTest.java View File

@@ -577,7 +577,8 @@ public class PathTest {
d.setDir(project.resolveFile(".")); d.setDir(project.resolveFile("."));
String s = System.getProperty("build.tests.value"); String s = System.getProperty("build.tests.value");
assertNotNull("build.tests.value not set", s); assertNotNull("build.tests.value not set", s);
String n = Paths.get(s).getParent().equals("ant") ? "ant" : "build";
String n = Paths.get(s).getParent().getFileName().toString().equals("ant")
? "target" : "build";
d.setIncludes(n); d.setIncludes(n);
p.addDirset(d); p.addDirset(d);
String[] l = p.list(); String[] l = p.list();


Loading…
Cancel
Save