
<project name="junit4" default="statuses" xmlns:junit4="antlib:com.carrotsearch.junit4">
    <property name="native.libs" location="${basedir}/../../src/native/lib" />

    <path id="junit.classpath">
        <fileset dir="..">
            <include name="dependency/junit-*.jar" />
        </fileset>
    </path>

    <path id="tests.classpath">
        <path location="." />
        <path refid="junit.classpath" />
    </path>

    <taskdef uri="antlib:com.carrotsearch.junit4">
        <classpath refid="junit.classpath" />
        <classpath>
            <fileset dir=".." id="fileset.junit4">
                <include name="junit4-ant*.jar" />
                <exclude name="*proguard_base.jar" />
            </fileset>
        </classpath>
    </taskdef>

    <presetdef name="junit4.preconf">
        <junit4:junit4 haltonfailure="true" parallelism="1" shuffleOnSlave="true">
            <classpath refid="tests.classpath" />

            <listeners>
                <junit4:report-text 
                    showThrowable="true" 
                    showStackTraces="true" 
                    showOutput="always"

                    showStatusOk="true" 
                    showStatusError="true" 
                    showStatusFailure="true" 
                    showStatusIgnored="true"

                    showSuiteSummary="true" 
                />
            </listeners>
        </junit4:junit4>
    </presetdef>

    <!-- Targets below are connected with test cases. -->
    <target name="sourcesuites">
        <junit4.preconf>
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>

            <fileset dir="${basedir}/../../src/test/java">
                <include name="**/TestSuccess.java" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="sysstreams">
        <junit4.preconf>
            <fileset dir="${basedir}">
                <include name="**/tests/TestSysstreams.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="nojunit">
        <junit4:junit4>
            <fileset dir="${basedir}">
                <include name="**/tests/TestSysstreams.class" />
            </fileset>
        </junit4:junit4>
    </target>

    <target name="oldjunit">
        <junit4:junit4>
            <classpath>
                <path location="." />
                <fileset dir="${basedir}/../.." includes="lib/junit*.jar" />
            </classpath>
            <fileset dir="${basedir}">
                <include name="**/tests/TestStatuses.class" />
            </fileset>
        </junit4:junit4>
    </target>

    <target name="statuses">
        <junit4.preconf debugstream="true">
            <fileset dir="${basedir}">
                <include name="**/tests/TestStatuses.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="ignoredSuite">
        <junit4.preconf>
            <fileset dir="${basedir}">
                <include name="**/tests/TestIgnoredSuite.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="beforeClassError">
        <junit4.preconf>
            <fileset dir="${basedir}">
                <include name="**/tests/TestBeforeClassError.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="afterClassError">
        <junit4.preconf>
            <fileset dir="${basedir}">
                <include name="**/tests/TestAfterClassError.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="hierarchicalSuiteDescription">
        <junit4.preconf>
            <fileset dir="${basedir}">
                <include name="**/tests/TestHierarchicalSuiteDescription.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="dir">
        <delete dir="empty" failonerror="false" />
        <mkdir dir="empty" />

        <junit4.preconf dir="empty" leaveTemporary="true">
            <fileset dir="${basedir}">
                <include name="**/tests/TestDir.class" />
            </fileset>
        </junit4.preconf>

        <fail message="Expected marker file to appear at ${basedir}/empty/S0/touch.me">
            <condition>
                <not>
                    <available file="empty/J0/touch.me" type="file" />
                </not>
            </condition>
        </fail>

        <junit4.preconf dir="empty" isolateWorkingDirectories="false">
            <fileset dir="${basedir}">
                <include name="**/tests/TestDir.class" />
            </fileset>
        </junit4.preconf>

        <fail message="Expected marker file to appear.">
            <condition>
                <not>
                    <available file="empty/touch.me" type="file" />
                </not>
            </condition>
        </fail>
    </target>

    <target name="maxmem">
        <junit4.preconf maxmemory="100m">
            <fileset dir="${basedir}">
                <include name="**/tests/TestMaxMem.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="jvmarg">
        <junit4.preconf>
            <jvmarg value="-Xmx100m" />
            <jvmarg value="-Dtest.param=foobar" />

            <fileset dir="${basedir}">
                <include name="**/tests/TestMaxMem.class" />
                <include name="**/tests/TestJvmArg.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="sysproperty">
        <junit4.preconf>
            <sysproperty key="test.param" value="foobar" />

            <fileset dir="${basedir}">
                <include name="**/tests/TestJvmArg.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="env">
        <junit4.preconf>
            <env key="env.variable" value="foobar" />

            <fileset dir="${basedir}">
                <include name="**/tests/TestEnvVar.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="failureProperty">
        <junit4.preconf haltonfailure="false">
            <fileset dir="${basedir}">
                <include name="**/tests/TestStatuses.class" />
            </fileset>
        </junit4.preconf>

        <junit4.preconf haltonfailure="false" failureProperty="tests.failed">
            <fileset dir="${basedir}">
                <include name="**/tests/TestStatuses.class" />
            </fileset>
        </junit4.preconf>

        <fail message="Expected failure property to be set.">
            <condition>
                <not>
                    <isset property="tests.failed" />
                </not>
            </condition>
        </fail>
    </target>

    <target name="failureTypePassing">
        <junit4.preconf haltonfailure="false">
            <classpath>
                <fileset dir=".." includes="dependency/asm*.jar" />
            </classpath>

            <fileset dir="${basedir}">
                <include name="**/tests/TestFailureTypePassing.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="jvmcrash">
        <echo>${native.libs}</echo>
        <junit4.preconf jvmOutputAction="pipe,fail">
            <jvmarg value="-Djava.library.path=${native.libs}" />

            <fileset dir="${basedir}">
                <include name="**/tests/TestJvmCrash.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="antxml">
        <delete dir="ant-xmls" failonerror="false" />
        <mkdir dir="ant-xmls" />

        <junit4:junit4 
            haltonfailure="false" 
            uniqueSuiteNames="false"
            parallelism="3">

            <classpath refid="tests.classpath" />
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>

            <listeners>
                <junit4:report-ant-xml dir="ant-xmls">
                    <!--
                    <tokenfilter>
                      <replaceregex pattern="" replace="" flags="gi" />
                    </tokenfilter>
                    -->
                </junit4:report-ant-xml>
            </listeners>

            <fileset dir="${basedir}">
                <include name="**/tests/TestStatuses.class" />
                <include name="**/tests/TestSysstreams.class" />
                <include name="**/tests/TestIgnoredSuite.class" />
                <include name="**/tests/TestBeforeClassError.class" />
                <include name="**/tests/TestHierarchicalSuiteDescription.class" />
                <include name="**/tests/TestInvalidUtfCharacter.class" />
                <include name="**/TestSuiteReplicated.class" />
            </fileset>
        </junit4:junit4>
    </target>

    <target name="json">
        <delete dir="json" failonerror="false" />
        <mkdir dir="json" />

        <junit4:junit4 haltonfailure="false">
            <classpath refid="tests.classpath" />

            <listeners>
                <junit4:report-json file="json/report.json" />
                <junit4:report-json jsonpMethod="callbackMethod" file="json/report.jsonp" />
                <junit4:report-json file="json/output.html" projectName="Nice project" />
            </listeners>

            <fileset dir="${basedir}">
                <include name="**/tests/TestStatuses.class" />
                <include name="**/tests/TestSysstreams.class" />
                <include name="**/tests/TestIgnoredSuite.class" />
                <include name="**/tests/TestBeforeClassError.class" />
                <include name="**/tests/TestHierarchicalSuiteDescription.class" />
                <include name="**/tests/EscapeSequences.class" />
            </fileset>
        </junit4:junit4>
    </target>

    <target name="classfilter">
        <local name="tests.class" />
        <property name="tests.class" value="*Statuses" />
        <junit4.preconf haltonfailure="false">
            <fileset dir="${basedir}">
                <include name="**/tests/Test*.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="methodfilter">
        <local name="tests.class" />
        <local name="tests.method" />
        <property name="tests.class" value="*Statuses" />
        <property name="tests.method" value="ignored*" />
        <junit4.preconf haltonfailure="false">
            <fileset dir="${basedir}">
                <include name="**/tests/Test*.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="filterexpression">
        <junit4.preconf haltonfailure="false">
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>
        
            <sysproperty key="tests.filter" value="@foo and not @bar" />

            <fileset dir="${basedir}">
                <include name="**/tests/TestFilteringExpressions$Example*.class" />
            </fileset>

            <listeners>
                <junit4:report-text />
            </listeners>
        </junit4.preconf>
    </target>

    <target name="nojunit-task">
        <taskdef name="junit4-nojunit" classname="com.carrotsearch.ant.tasks.junit4.JUnit4">
            <classpath>
                <fileset refid="fileset.junit4" />
            </classpath>
        </taskdef>

        <junit4-nojunit>
            <classpath refid="tests.classpath" />
            <fileset dir="${basedir}">
                <include name="**/tests/TestStatuses.class" />
            </fileset>
        </junit4-nojunit>
    </target>

    <target name="oldjunit-task">
        <taskdef name="junit4-oldjunit" classname="com.carrotsearch.ant.tasks.junit4.JUnit4">
            <classpath>
                <fileset dir="../..">
                    <include name="lib/junit-4.9.jar" />
                </fileset>
                <fileset refid="fileset.junit4" />
            </classpath>
        </taskdef>

        <junit4-oldjunit>
            <classpath refid="tests.classpath" />
            <fileset dir="${basedir}">
                <include name="**/tests/TestStatuses.class" />
            </fileset>
        </junit4-oldjunit>
    </target>

    <target name="escaping">
        <delete dir="empty" failonerror="false" />
        <mkdir dir="empty" />

        <junit4.preconf dir="empty">
            <sysproperty key="sysprop.key" value="${nonexistent-1}" />
            <sysproperty key="sysprop.key2" value="abc def" />
            <jvmarg value="-Dsysprop.key3=%PATH%" />
            <env key="env.variable" value="${nonexistent-3}" />

            <fileset dir="${basedir}">
                <include name="**/tests/TestEscaping.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="seedpassing">
        <junit4.preconf seed="[DEADBEEF:CAFEBABE]">
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>
            <fileset dir="${basedir}">
                <include name="**/tests/TestSeedPassing.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="seedpassing.invalid">
        <junit4.preconf seed="invalid">
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>
            <fileset dir="${basedir}">
                <include name="**/tests/TestSeedPassing.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="reproducestring">
        <junit4.preconf haltonfailure="false">
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>
            <fileset dir="${basedir}">
                <include name="**/tests/TestReproduceString.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="assertions">
        <junit4.preconf>
            <fileset dir="${basedir}">
                <include name="**/tests/sub1/TestAssertions.class" />
            </fileset>

            <assertions>
                <enable package="com.carrotsearch.ant.tasks.junit4.tests.sub1" />
            </assertions>
        </junit4.preconf>
    </target>

    <target name="balancing">
        <delete dir="${basedir}" includes="hints*.log" excludes="hints-fixed.log" />
        <junit4.preconf parallelism="2">
            <fileset dir="${basedir}">
                <include name="**/tests/sub2/Test*.class" />
            </fileset>

            <listeners>
                <junit4:report-execution-times file="${basedir}/hints.log" historyLength="5" />
            </listeners>

            <balancers>
                <junit4:execution-times>
                    <fileset dir="${basedir}" includes="hints*.log" />
                </junit4:execution-times>
            </balancers>
        </junit4.preconf>

        <fail message="Expected hints file to appear.">
            <condition>
                <not>
                    <available file="${basedir}/hints.log" type="file" />
                </not>
            </condition>
        </fail>
    </target>

    <target name="balancing_nohints">
        <junit4.preconf parallelism="2">
            <fileset dir="${basedir}">
                <include name="**/tests/sub2/Test*.class" />
            </fileset>

            <balancers>
                <junit4:execution-times>
                    <fileset dir="${basedir}" includes="nohints*.log" />
                </junit4:execution-times>
            </balancers>
        </junit4.preconf>
    </target>

    <target name="alt-vendor">
        <fail unless="jvm.exec">jvm.exec property must be set.</fail>
        <junit4.preconf parallelism="1" leaveTemporary="true" jvm="${jvm.exec}">
            <fileset dir="${basedir}">
                <include name="**/tests/TestStatuses.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="notaclass">
        <junit4.preconf>
            <fileset dir="${basedir}">
                <include name="junit4.xml" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="notinstantiable">
        <junit4.preconf>
            <fileset dir="${basedir}">
                <include name="**/tests/NotInstantiable.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="customprefix">
        <local name="blah.class" />
        <property name="blah.class" value="*Statuses" />
        <property name="blah.seed" value="deadbeef" />
        <junit4.preconf haltonfailure="false" prefix="blah">
            <fileset dir="${basedir}">
                <include name="**/tests/Test*.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="cwdconflict">
        <junit4.preconf haltonfailure="true" parallelism="2">
            <fileset dir="${basedir}">
                <include name="**/CwdConflict*.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="slavehanging">
        <junit4.preconf haltonfailure="false" parallelism="1">
            <fileset dir="${basedir}">
                <include name="**/SlaveHanging*.class" />
                <exclude name="**/*$*" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="outofordersysouts">
        <junit4.preconf haltonfailure="true" parallelism="1">
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>

            <fileset dir="${basedir}">
                <include name="**/OutOfOrderSysouts.class" />
                <exclude name="**/*$*" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="mergehints">
        <junit4.preconf parallelism="4">
            <fileset dir="${basedir}">
                <include name="**/tests/sub2/Test*.class" />
            </fileset>

            <listeners>
                <junit4:report-execution-times file="${basedir}/hints-1.log" />
                <junit4:report-execution-times file="${basedir}/hints-2.log" />
                <junit4:report-execution-times file="${basedir}/hints-3.log" />
            </listeners>
        </junit4.preconf>

        <junit4:mergehints file="${basedir}/hints-merged.log" historyLength="3">
            <fileset dir="${basedir}" includes="hints-?.log" />
        </junit4:mergehints>

        <junit4:tophints max="3">
            <fileset dir="${basedir}" includes="hints-merged.log" />
        </junit4:tophints>
    </target>

    <target name="staticScopeOutput">
        <junit4:junit4>
            <classpath refid="tests.classpath" />

            <fileset dir="${basedir}">
                <include name="**/TestStaticScopeOutput.class" />
            </fileset>

            <listeners>
                <junit4:report-text />
                <junit4:report-json file="json/static-scope.json" />
            </listeners>
        </junit4:junit4>
    </target>

    <target name="iters">
        <junit4.preconf haltonfailure="true">
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>
            <sysproperty key="tests.iters" value="5" />
            <fileset dir="${basedir}">
                <include name="**/TestSuccess.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="junitcompat1">
        <junit4.preconf fork="true" forkmode="once" haltonerror="true" errorproperty="dummy" filtertrace="yes" timeout="60" includeantruntime="true" showoutput="yes" outputtoformatters="true" reloading="true" clonevm="true" logfailedtests="true" enableTestListenerEvents="true">
            <formatter type="plain" />
        </junit4.preconf>
    </target>

    <target name="junitcompat2">
        <junit4.preconf>
            <test name="my.test.TestCase" haltonfailure="no" outfile="result">
                <formatter type="xml" />
            </test>

            <batchtest fork="yes" todir="${reports.tests}">
                <fileset dir="${src.tests}">
                    <include name="**/*Test*.java" />
                    <exclude name="**/AllTests.java" />
                </fileset>
            </batchtest>
        </junit4.preconf>
    </target>

    <target name="junitcompat3">
        <junit4.preconf>
            <batchtest fork="yes" todir="${reports.tests}">
                <fileset dir="${src.tests}">
                    <include name="**/*Test*.java" />
                    <exclude name="**/AllTests.java" />
                </fileset>
            </batchtest>
        </junit4.preconf>
    </target>

    <target name="suiteerror">
        <junit4:junit4 haltonfailure="false">
            <classpath refid="tests.classpath" />

            <listeners>
                <junit4:report-text showStatusOk="false" />
            </listeners>

            <fileset dir="${basedir}">
                <include name="**/FailInAfterClass.class" />
            </fileset>
        </junit4:junit4>
    </target>

    <target name="reasonForSuiteAssumptionIgnored">
        <junit4:junit4>
            <classpath refid="tests.classpath" />
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>

            <fileset dir="${basedir}">
                <include name="**/ReasonForAssumptionIgnored$*.class" />
            </fileset>

            <listeners>
                <junit4:report-text />
            </listeners>
        </junit4:junit4>
    </target>

    <target name="reasonForIgnored">
        <junit4:junit4>
            <classpath refid="tests.classpath" />
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>

            <fileset dir="${basedir}">
                <include name="**/ReasonForIgnored$*.class" />
            </fileset>

            <listeners>
                <junit4:report-text />
            </listeners>
        </junit4:junit4>
    </target>

    <target name="reasonForIgnoredByDisabledGroup">
        <junit4:junit4>
            <classpath refid="tests.classpath" />
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>

            <fileset dir="${basedir}">
                <include name="**/ReasonForIgnoredByDisabledGroup.class" />
            </fileset>

            <listeners>
                <junit4:report-text />
            </listeners>
        </junit4:junit4>
    </target>
    
    

    <target name="jvmverbose">
        <junit4:junit4 haltonfailure="false">
            <classpath refid="tests.classpath" />

            <jvmarg value="-verbose:class" />
            <jvmarg value="-verbose:gc" />

            <fileset dir="${basedir}">
                <include name="**/TestStatuses.class" />
            </fileset>

            <listeners>
                <junit4:report-text />
            </listeners>
        </junit4:junit4>
    </target>

    <target name="sysouts">
        <junit4:junit4 sysouts="true" jvmoutputaction="pipe,ignore">
            <classpath refid="tests.classpath" />

            <jvmarg value="-verbose:class" />

            <fileset dir="${basedir}">
                <include name="**/TestSysstreams.class" />
            </fileset>
        </junit4:junit4>
    </target>

    <target name="weirdclasses">
        <junit haltonfailure="false" haltonerror="false" printsummary="false" showoutput="false" filtertrace="false">
            <classpath refid="tests.classpath" />
            <classpath>
                <fileset dir="../..">
                    <include name="lib/junit-4.9.jar" />
                </fileset>
            </classpath>

            <batchtest>
                <formatter type="plain" usefile="false" />
                <fileset dir="${basedir}/../../src/test/java" includes="**/bad/*.java" />
            </batchtest>
        </junit>
    </target>

    <target name="listeners">
        <junit4:junit4 haltonfailure="false">
            <classpath refid="tests.classpath" />
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>

            <fileset dir="${basedir}">
                <include name="**/SuiteListeners.class" />
            </fileset>

            <listeners>
                <junit4:report-text />
            </listeners>
        </junit4:junit4>
    </target>
  
    <target name="syspropertyset">
        <junit4:junit4 haltonfailure="false">
            <classpath refid="tests.classpath" />
    
            <fileset dir="${basedir}">
                <include name="**/SysPropertySets.class" />
            </fileset>

            <listeners>
                <junit4:report-text />
            </listeners>
            
            <syspropertyset>
                <propertyref prefix="prefix" />
            </syspropertyset>
        </junit4:junit4>
    </target>
  
    <target name="randomsysproperty">
        <!-- Fix the master seed in advance to allow repeatable selection of attributes. -->
        <local name="tests.seed" />
        <junit4:pickseed property="tests.seed" />

        <junit4:pickfromlist property="prefix.dummy1" allowundefined="false" seed="${tests.seed}">
            <value>UTF-8</value>
            <value>UTF-16</value>
            <value>US-ASCII</value>
            <value>iso8859-1</value>
        </junit4:pickfromlist>

        <junit4:pickfromlist property="prefix.dummy2" allowundefined="false" seed="${tests.seed}">
            <value>UTF-8</value>
            <value><!-- Empty for ignored property. --></value>
            <value><!-- Empty for ignored property. --></value>
            <value><!-- Empty for ignored property. --></value>
        </junit4:pickfromlist>

        <junit4:junit4 haltonfailure="false" seed="${tests.seed}">
            <classpath refid="tests.classpath" />

            <fileset dir="${basedir}">
                <include name="**/RandomSysProperty.class" />
            </fileset>

            <listeners>
                <junit4:report-text />
            </listeners>

            <sysproperty key="prefix.dummy1" value="${prefix.dummy1}" ignoreEmpty="true" />
            <sysproperty key="prefix.dummy2" value="${prefix.dummy2}" ignoreEmpty="true" />

            <!--
            It'd be nicest to use local refs but they're not working due to: 
            https://issues.apache.org/bugzilla/show_bug.cgi?id=50179
            -->

            <syspropertyset ignoreEmpty="true">
                <propertyref prefix="prefix." />
                <mapper type="glob" from="prefix.*" to="replaced.*" />
            </syspropertyset>
        </junit4:junit4>
    </target>
    
    <target name="fileencodings">
        <macrodef name="check.encoding">
           <attribute name="encoding" />
           <sequential>
              <junit4:junit4>
                  <classpath refid="tests.classpath" />
      
                  <fileset dir="${basedir}">
                      <include name="**/FileEncoding.class" />
                  </fileset>
      
                  <listeners>
                      <!-- Always in UTF-8 -->
                      <junit4:report-text file="${log.file}" append="true" />
                      <!-- Console output, environment-specific but show nonetheless. -->
                      <junit4:report-text />
                  </listeners>
      
                  <sysproperty key="file.encoding" value="@{encoding}" />
              </junit4:junit4>
           </sequential>
        </macrodef>

        <property name="log.file" location="fileencodings.log" />
        <delete file="${log.file}" failonerror="true" />
        <check.encoding encoding="US-ASCII" />
        <check.encoding encoding="iso8859-1" />
        <check.encoding encoding="UTF-8" />
        <check.encoding encoding="UTF-16" />
        <check.encoding encoding="UTF-16LE" />
        <check.encoding encoding="UTF-32" />
    </target>
    
    <target name="testHeartbeat">
        <junit4:junit4 heartbeat="1">
            <classpath refid="tests.classpath" />

            <fileset dir="${basedir}">
                <include name="**/HeartbeatSlow.class" />
            </fileset>

            <listeners>
                <junit4:report-text />
            </listeners>
        </junit4:junit4>
    </target>
    
    <target name="timestamps">
        <junit4:junit4 haltonfailure="false">
            <classpath refid="tests.classpath" />
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>

            <fileset dir="${basedir}">
                <include name="**/TestStatuses.class" />
                <include name="**/TestSuccess.class" />
            </fileset>

            <listeners>
                <junit4:report-text timestamps="true" />
            </listeners>
        </junit4:junit4>
    </target>

    <target name="sysoutsOnSuiteFailure">
        <junit4:junit4 haltonfailure="false">
            <classpath refid="tests.classpath" />

            <fileset dir="${basedir}">
                <include name="**/SysoutsOnSuiteFailure.class" />
            </fileset>

            <listeners>
                <junit4:report-text />
            </listeners>
        </junit4:junit4>
    </target>

    <target name="sysoutsOnSuiteTimeout">
        <junit4:junit4 haltonfailure="false">
            <classpath refid="tests.classpath" />
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>

            <fileset dir="${basedir}">
                <include name="**/SysoutsOnSuiteTimeout.class" />
            </fileset>

            <listeners>
                <junit4:report-text showStatusOk="false" />
            </listeners>
        </junit4:junit4>
   </target>

   <target name="sysoutoom">
      <junit4:junit4 haltonfailure="true" parallelism="2" shuffleOnSlave="true">
          <classpath refid="tests.classpath" />

          <fileset dir="${basedir}">
              <include name="**/SysoutOom*.class" />
          </fileset>

          <listeners>
              <junit4:report-text file="${basedir}/large.log" />
              <junit4:report-json file="${basedir}/large.json" outputStreams="no" />
              <junit4:report-ant-xml dir="${basedir}/large.xml" outputStreams="no" />
          </listeners>
      </junit4:junit4>

      <delete includeemptydirs="true">
          <fileset dir="${basedir}">
              <include name="large.*/**" />
          </fileset>
      </delete>
   </target>
   
   <target name="sysouts_passthrough">
      <junit4:junit4 haltonfailure="true" parallelism="1" shuffleOnSlave="true">
          <classpath refid="tests.classpath" />

          <fileset dir="${basedir}">
              <include name="**/SysoutPassthrough.class" />
          </fileset>

          <listeners>
              <junit4:report-text />
          </listeners>
      </junit4:junit4>

      <delete file="${basedir}/large.log" />
   </target>

    <target name="slavemainfailure">
        <junit4.preconf haltonfailure="true">
            <fileset dir="${basedir}">
                <include name="**/FireUnhandledRunnerException.class" />
            </fileset>
        </junit4.preconf>
    </target>

    <target name="suiteduplicate">
        <junit4.preconf parallelism="2" uniqueSuiteNames="false">
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>

            <fileset dir="${basedir}">
                <include name="**/TestSuccess.class" />
            </fileset>
            <fileset dir="${basedir}">
                <include name="**/TestSuccess.class" />
            </fileset>

            <balancers>
                <junit4:execution-times>
                    <fileset dir="${basedir}" includes="hints*.log" />
                </junit4:execution-times>
            </balancers>
        </junit4.preconf>
    </target>

    <target name="duplicateresources">
        <junit4.preconf parallelism="2" uniqueSuiteNames="false">
            <classpath>
                <fileset dir=".." includes="dependency/randomized*.jar" />
            </classpath>

            <junit4:duplicate times="10">
                <fileset dir="${basedir}">
                    <include name="**/TestSuccess.class" />
                </fileset>
            </junit4:duplicate>
            
            <listeners>
                <junit4:report-text />
            </listeners>           
        </junit4.preconf>
    </target>
    
   <target name="failureslist">
      <junit4:junit4 haltonfailure="false" parallelism="2" uniqueSuiteNames="false">
          <classpath refid="tests.classpath" />

          <junit4:duplicate times="3">
            <fileset dir="${basedir}">
                <include name="**/TestStatuses.class" />
            </fileset>
          </junit4:duplicate>

          <listeners>
              <junit4:report-text showNumFailures="3" />
          </listeners>
      </junit4:junit4>

      <delete file="${basedir}/large.log" />
   </target>
  
   <target name="shutdownhook">
     <junit4.preconf haltonfailure="true">
       <fileset dir="${basedir}">
         <include name="**/ShutdownHook.class" />
       </fileset>
     </junit4.preconf>
  
     <delete file="${basedir}/large.log" />
   </target>
  
   <target name="childvm_sysprops">
     <junit4.preconf>
       <fileset dir="${basedir}">
           <include name="**/tests/ChildVmSysprops.class" />
       </fileset>
     </junit4.preconf>
   </target>

   <target name="oomcode">
      <junit4:junit4 haltonfailure="true">
          <classpath refid="tests.classpath" />

          <fileset dir="${basedir}">
              <include name="**/OomCode.class" />
          </fileset>

          <listeners>
              <junit4:report-text 
                    showThrowable="true" 
                    showStackTraces="true" 
                    showOutput="always"
              />
          </listeners>
      </junit4:junit4>
   </target>
   
   <target name="oompermgen">
      <junit4:junit4 haltonfailure="true">
          <classpath refid="tests.classpath" />
          <classpath>
            <fileset dir=".." includes="dependency/asm*.jar" />
          </classpath>
          

          <fileset dir="${basedir}">
              <include name="**/OomPermGen.class" />
          </fileset>

          <listeners>
              <junit4:report-text 
                    showThrowable="true" 
                    showStackTraces="true" 
                    showOutput="always"
              />
          </listeners>
      </junit4:junit4>
   </target>

  <target name="filtertrace_default">
    <junit4:junit4 haltonfailure="false">
      <classpath refid="tests.classpath" />

      <fileset dir="${basedir}">
        <include name="**/TestStatuses.class" />
      </fileset>

      <listeners>
        <junit4:report-text>
          <junit4:filtertrace>
            <!-- custom filters. 
                <containsstring contains=".SlaveMain." /> 
                <containsregex pattern="^(\s+at )(org\.junit\.)" /> 
             -->
          </junit4:filtertrace>
        </junit4:report-text>
      </listeners>
    </junit4:junit4>
  </target>
  
  <target name="filtertrace_custom">
    <junit4:junit4 haltonfailure="false">
      <classpath refid="tests.classpath" />

      <fileset dir="${basedir}">
        <include name="**/TestStatuses.class" />
      </fileset>

      <listeners>
        <junit4:report-text>
          <junit4:filtertrace defaults="false">
              <containsstring contains=".SlaveMain." /> 
              <containsregex pattern="^(\s+at )(org\.junit\.)" /> 
          </junit4:filtertrace>
        </junit4:report-text>
      </listeners>
    </junit4:junit4>
  </target>
  
  <target name="allFilteredOut">
    <junit4:junit4 ifNoTests="fail">
      <classpath refid="tests.classpath" />

      <fileset dir="${basedir}">
        <include name="**/TestStatuses.class" />
      </fileset>

      <sysproperty key="tests.method" value="-nonexistent-" />
    </junit4:junit4>
  </target>
  
  <target name="oneIgnored">
    <junit4:junit4 ifNoTests="fail">
      <classpath refid="tests.classpath" />

      <fileset dir="${basedir}">
        <include name="**/TestStatuses.class" />
      </fileset>

      <sysproperty key="tests.method" value="ignored" />
    </junit4:junit4>
  </target>
  
  <target name="oneAssumptionIgnored">
    <junit4:junit4 ifNoTests="fail">
      <classpath refid="tests.classpath" />

      <fileset dir="${basedir}">
        <include name="**/TestStatuses.class" />
      </fileset>

      <sysproperty key="tests.method" value="ignored" />
    </junit4:junit4>
  </target>      

  <target name="oneSuccessful">
    <junit4:junit4 ifNoTests="fail">
      <classpath refid="tests.classpath" />

      <fileset dir="${basedir}">
        <include name="**/TestStatuses.class" />
      </fileset>

      <sysproperty key="tests.method" value="ok" />
    </junit4:junit4>
  </target>      

  <target name="oneFailure">
    <junit4:junit4 ifNoTests="fail">
      <classpath refid="tests.classpath" />

      <fileset dir="${basedir}">
        <include name="**/TestStatuses.class" />
      </fileset>

      <sysproperty key="tests.method" value="failure" />
    </junit4:junit4>
  </target>      

  <target name="oneError">
    <junit4:junit4 ifNoTests="fail">
      <classpath refid="tests.classpath" />

      <fileset dir="${basedir}">
        <include name="**/TestStatuses.class" />
      </fileset>

      <sysproperty key="tests.method" value="error" />
    </junit4:junit4>
  </target>      

  <target name="statsProperties">
    <sequential>
      <local name="junit4.stats.tests" />
      <local name="junit4.stats.errors" />
      <local name="junit4.stats.failures" />
      <local name="junit4.stats.ignores" />
      <local name="junit4.stats.suites" />
      <local name="junit4.stats.assumptions" />
      <local name="junit4.stats.suiteErrors" />
      <local name="junit4.stats.nonIgnored" />
      <local name="junit4.stats.successful" />

      <junit4:junit4 statsPropertyPrefix="junit4.stats" haltonfailure="false">
        <classpath refid="tests.classpath" />
  
        <fileset dir="${basedir}">
          <include name="**/TestStatuses.class" />
        </fileset>
      </junit4:junit4>
  
      <echo>
        ${junit4.stats.tests}
        ${junit4.stats.errors}
        ${junit4.stats.failures}
        ${junit4.stats.ignores}
        ${junit4.stats.suites}
        ${junit4.stats.assumptions}
        ${junit4.stats.suiteErrors}
        ${junit4.stats.nonIgnored}
        ${junit4.stats.successful}
      </echo>

      <fail><condition><not><equals arg1="${junit4.stats.tests}"    arg2="5" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.errors}"   arg2="1" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.failures}" arg2="1" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.ignores}"  arg2="1" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.suites}"   arg2="1" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.assumptions}" arg2="1" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.suiteErrors}" arg2="0" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.nonIgnored}"  arg2="3" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.successful}"  arg2="false" /></not></condition></fail>
    </sequential>

    <sequential>
      <local name="junit4.stats.tests" />
      <local name="junit4.stats.errors" />
      <local name="junit4.stats.failures" />
      <local name="junit4.stats.ignores" />
      <local name="junit4.stats.suites" />
      <local name="junit4.stats.assumptions" />
      <local name="junit4.stats.suiteErrors" />
      <local name="junit4.stats.nonIgnored" />
      <local name="junit4.stats.successful" />

      <junit4:junit4 haltonfailure="false" statsPropertyPrefix="junit4.stats">
        <classpath refid="tests.classpath" />
  
        <fileset dir="${basedir}">
          <include name="**/TestStatuses.class" />
        </fileset>
  
        <sysproperty key="tests.method" value="error" />
      </junit4:junit4>
  
      <echo>
        ${junit4.stats.tests}
        ${junit4.stats.errors}
        ${junit4.stats.failures}
        ${junit4.stats.ignores}
        ${junit4.stats.suites}
        ${junit4.stats.assumptions}
        ${junit4.stats.suiteErrors}
        ${junit4.stats.nonIgnored}
        ${junit4.stats.successful}
      </echo>
      
      <fail><condition><not><equals arg1="${junit4.stats.tests}"    arg2="1" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.errors}"   arg2="1" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.failures}" arg2="0" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.ignores}"  arg2="0" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.suites}"   arg2="1" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.assumptions}" arg2="0" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.suiteErrors}" arg2="0" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.nonIgnored}"  arg2="1" /></not></condition></fail>
      <fail><condition><not><equals arg1="${junit4.stats.successful}"  arg2="false" /></not></condition></fail>      
    </sequential>
  </target>

  <target name="replicateSingleTest">
    <junit4:junit4 
        ifNoTests="fail" 
        haltonfailure="true" 
        parallelism="3"
        uniqueSuiteNames="false">
      <classpath refid="tests.classpath" />
      <classpath>
          <fileset dir=".." includes="dependency/randomized*.jar" />
      </classpath>

      <listeners>
          <junit4:report-text showOutput="always" />
      </listeners>

      <fileset dir="${basedir}">
        <include name="**/TestSuiteReplicated.class" />
      </fileset>
    </junit4:junit4>
  </target>

  <target name="replicationAndBalancing">
    <junit4:junit4 
        ifNoTests="fail" 
        haltonfailure="true" 
        parallelism="3"
        uniqueSuiteNames="false">
      <classpath refid="tests.classpath" />
      <classpath>
          <fileset dir=".." includes="dependency/randomized*.jar" />
      </classpath>

      <listeners>
          <junit4:report-text showOutput="always" />
      </listeners>

      <fileset dir="${basedir}">
        <include name="**/TestSuiteReplicated.class" />
        <include name="**/TestNonReplicated*.class" />
      </fileset>
    </junit4:junit4>
  </target>
  
  <target name="pseudoBalancing">
    <junit4:junit4 
        ifNoTests="fail" 
        haltonfailure="true" 
        parallelism="3"
        uniqueSuiteNames="false">
      <classpath refid="tests.classpath" />
      <classpath>
          <fileset dir=".." includes="dependency/randomized*.jar" />
      </classpath>

      <listeners>
          <junit4:report-text showOutput="always" />
      </listeners>

      <fileset dir="${basedir}">
        <include name="**/TestPseudoLoadBalancing.class" />
      </fileset>
    </junit4:junit4>
  </target>

  <target name="stackoverflow">
    <junit4:junit4 
        haltonfailure="true" parallelism="1" 
        jvmoutputaction="pipe,ignore"
        debugstream="true"
        leavetemporary="true">
      <classpath refid="tests.classpath" />

      <fileset dir="${basedir}">
          <include name="**/StackOverflow*.class" />
      </fileset>
      
      <listeners>
          <junit4:report-text showOutput="always" showStatusOk="true" showSuiteSummary="true" />
      </listeners>      
    </junit4:junit4>
  </target> 
</project>
