<?xml version="1.0"?>

<project name="delete-test" basedir="." default="test1">

  <property name="dirname" value="taskdefs.tmp" />
  <property name="dir" location="${dirname}" />

  <macrodef name="expectabsent">
    <sequential>
      <fail>
        <condition>
          <available file="${dir}" />
        </condition>
    </fail>
    </sequential>
  </macrodef>

  <macrodef name="expectdirsonly">
    <sequential>
      <fail>
        <condition>
          <or>
            <resourcecount when="greater" count="0">
              <fileset refid="fs" />
            </resourcecount>
            <not>
              <resourcecount count="${srcdirs}">
                <dirset dir="${dir}" />
              </resourcecount>
            </not>
          </or>
        </condition>
      </fail>
    </sequential>
  </macrodef>

  <target name="init">
    <resourcecount property="srcdirs">
      <dirset dir="${basedir}" />
    </resourcecount>

    <resourcecount property="srcsize">
      <files includes="${basedir}/" />
    </resourcecount>

    <mkdir dir="${dir}" />

    <copy todir="${dir}">
      <fileset dir="${basedir}" excludes="${dirname},${dirname}/**" />
    </copy>
  </target>

  <target name="test1">
    <delete />
  </target>

  <target name="test2" depends="init">
    <delete file="${dir}" />
    <fail>
      <condition>
        <not>
          <resourcecount count="${srcsize}">
            <files includes="${dir}/" />
          </resourcecount>
        </not>
      </condition>
    </fail>
  </target>

  <target name="test4" depends="init">
    <delete dir="${dir}" />
    <expectabsent />
  </target>

  <target name="test5" depends="init">
    <delete dir="${dir}" includes="**" />
    <expectdirsonly />
  </target>

  <target name="test6" depends="init">
    <delete dir="${dir}" includes="**" includeemptydirs="true" />
    <expectabsent />
  </target>

  <target name="test7" depends="init">
    <delete>
      <fileset id="fs" dir="${dir}" />
    </delete>
    <expectdirsonly />
  </target>

  <target name="test8" depends="init">
    <delete includeemptydirs="true">
      <fileset dir="${dir}" />
    </delete>
    <expectabsent />
  </target>

  <target name="test9" depends="init">
    <delete>
      <files includes="${dir}/**" />
    </delete>
    <expectabsent />
  </target>

  <target name="test10">
    <delete>
      <filelist dir="${dir}" files="test10absentfile" />
    </delete>
  </target>

  <target name="test11">
    <delete failonerror="false">
      <fileset dir="thisdenotesadirectorythatwillneverexistblah" />
    </delete>
  </target>

  <target name="test12">
    <delete failonerror="false" includeemptydirs="true">
      <fileset dir="thisdenotesadirectorythatwillneverexistblah" />
    </delete>
  </target>

  <target name="test13" depends="init">
    <delete includeemptydirs="true">
      <fileset dir="${dir}" />
      <fileset dir="${dir}" />
    </delete>
    <expectabsent />
  </target>

  <target name="test14" depends="init">
	<delete quiet="false">
		<fileset dir="${dir}" />
		<fileset dir="${dir}" />
	</delete>
  </target>

  <target name="test15" depends="init">
	<delete quiet="true">
		<fileset dir="${dir}" />
		<fileset dir="${dir}" />
	</delete>
  </target>

  <target name="cleanup" depends="test4" />

</project>
