<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<project name="antunit-test"
      default="all"
         xmlns:au="antlib:org.apache.ant.antunit">

  <target name="all" depends="antunit-basetest,antunit-dir" />
  
  <target name="antunit-basetest">
    <au:antunit>
      <file file="antunit/base.xml"/>
      <au:plainlistener/>
    </au:antunit>
  </target>

  <target name="noTests">
    <au:antunit/>
  </target>

  <target name="emptyTests">
    <au:antunit>
      <resources />
    </au:antunit>
  </target>

  <target name="nonFile">
    <au:antunit>
      <url url="https://ant.apache.org/"/>
    </au:antunit>
  </target>

  <target name="nonExistingFile">
    <au:antunit failOnError="false">
      <filelist dir="antunit">
        <file name="base.xml"/>
        <file name="I don't exist.xml"/>
      </filelist>
    </au:antunit>
  </target>

  <target name="testNoPropertySet">
    <au:antunit>
      <file file="antunit/echo.xml"/>
      <au:plainlistener/>
    </au:antunit>
  </target>

  <target name="testPropertySet">
    <au:antunit>
      <file file="antunit/echo.xml"/>
      <au:plainlistener/>
      <propertyset>
        <propertyref builtin="system"/>
      </propertyset>
    </au:antunit>
  </target>

  <target name="testNewProject">
    <au:antunit>
      <file file="antunit/property.xml" />
      <au:plainlistener />
    </au:antunit>
  </target>

  <target name="testSystemIoHandling">
    <au:antunit>
      <file file="antunit/java-io.xml" />
      <au:plainlistener />
    </au:antunit>  	
  </target>

  <target name="testReference">
    <path id="inherited.ref" path="/some:/path:/value"/>
    <path id="uninherited.ref" path="some:other:value"/>
    <au:antunit>
      <file file="antunit/reference.xml" />
      <au:plainlistener />
      <reference refid="inherited.ref"/>
    </au:antunit>
  </target>
 
  <target name="testReferenceRegex">
    <path id="first.ref" path="/first"/>
    <path id="second.ref" path="/second"/>
    <path id="third.missing" path="ignored"/>
    <au:antunit>
      <file file="antunit/reference-regex.xml" />
      <au:plainlistener />
      <reference regex=".*\.ref"/>
    </au:antunit>
  </target>

  <target name="testReferenceSet">
    <path id="first.ref" path="/first"/>
    <path id="second.ref" path="/second"/>
    <path id="third.ref" path="/third"/>
    <au:antunit>
      <file file="antunit/reference-set.xml" />
      <au:plainlistener />
      <referenceSet>
        <reference refid="first.ref"/>
        <reference refid="third.ref"/>
      </referenceSet>
    </au:antunit>
  </target>

  <target name="testReferenceMapper">
    <path id="first.ref" path="/first"/>
    <path id="second.ref" path="/second"/>
    <au:antunit>
      <file file="antunit/reference-mapper.xml" />
      <au:plainlistener />
      <referenceSet>
        <reference refid="first.ref"/>
        <reference refid="second.ref"/>
        <mapper type="regexp" from="(.*)\.ref" to="\1.mapped"/>
      </referenceSet>
    </au:antunit>
  </target>

  <property name="reportsdir" location="../../../build/reports"/>
  <target name="antunit-dir">
    <mkdir dir="${reportsdir}"/>
    <au:antunit failonerror="false" errorproperty="antunit-failure">
      <fileset dir="antunit" includes="*.xml"/>
      <au:plainlistener sendLogTo="both" toDir="${reportsdir}"/>
      <au:xmllistener toDir="${reportsdir}"/>
    </au:antunit>
  </target>

  <target name="report" depends="antunit-dir">
    <sleep seconds="1"/>
    <mkdir dir="${reportsdir}-frames"/>
    <junitreport>
      <fileset dir="${reportsdir}" includes="*.xml"/>
      <report format="frames" styledir=".." todir="${reportsdir}-frames"/>
    </junitreport>
    <mkdir dir="${reportsdir}-noframes"/>
    <junitreport>
      <fileset dir="${reportsdir}" includes="*.xml"/>
      <report format="noframes" styledir=".." todir="${reportsdir}-noframes"/>
    </junitreport>
    <fail if="antunit-failure">At least one test has failed</fail>
  </target>
</project>
