blob: 0ed2bc2bff25a60596111b4cb276b0d78ce2a93c [file] [log] [blame]
<project name="length-test" default="antunit"
xmlns:au="antlib:org.apache.ant.antunit">
<import file="../antunit-base.xml" />
<property name="dir" location="lengthtestdir" />
<property name="dir.a" location="${dir}/a" />
<property name="dir.b" location="${dir}/b" />
<property name="zipfile" location="lengthtest.zip" />
<target name="setUp">
<mkdir dir="${dir.a}" />
<mkdir dir="${dir.b}" />
<property name="foo" location="${dir.a}/foo" />
<property name="bar" location="${dir.b}/bar" />
<echo file="${foo}" message="foo" />
<echo file="${bar}" message="bar" />
</target>
<target name="tearDown">
<delete dir="${dir}" />
<delete file="${zipfile}" />
</target>
<target name="testEach" depends="setUp">
<length mode="each" property="length.each">
<fileset id="fs" dir="${dir}" />
</length>
<length string="${length.each}" property="length.length.each" />
<length string="${foo}${bar}........${line.separator}"
property="length.expected" />
<au:assertTrue>
<!-- test that both files are represented, and that the
output is the expected length; do not assume order. -->
<and>
<contains string="${length.each}" substring="${foo} : 3" />
<contains string="${length.each}" substring="${bar} : 3" />
<equals arg1="${length.length.each}" arg2="${length.expected}" />
</and>
</au:assertTrue>
</target>
<target name="testEachCondition" depends="setUp">
<length mode="each" property="length.each">
<fileset id="fs" dir="${dir}" />
</length>
<length string="${foo}${bar}........${line.separator}"
property="length.expected" />
<au:assertTrue>
<!-- test that both files are represented, and that the
output is the expected length; do not assume order. -->
<and>
<contains string="${length.each}" substring="${foo} : 3" />
<contains string="${length.each}" substring="${bar} : 3" />
<length string="${length.each}" length="${length.expected}" />
</and>
</au:assertTrue>
</target>
<target name="testAll" depends="setUp">
<length property="length.all">
<fileset id="foo" file="${dir.a}/foo" />
<fileset id="bar" file="${dir.b}/bar" />
</length>
<au:assertTrue>
<equals arg1="6" arg2="${length.all}" />
</au:assertTrue>
</target>
<target name="testAllCondition" depends="setUp">
<au:assertTrue>
<length length="6">
<fileset id="foo" file="${dir.a}/foo" />
<fileset id="bar" file="${dir.b}/bar" />
</length>
</au:assertTrue>
</target>
<target name="testFile" depends="setUp">
<length property="length.foo" file="${dir.a}/foo" />
<au:assertTrue>
<equals arg1="3" arg2="${length.foo}" />
</au:assertTrue>
</target>
<target name="testFileCondition" depends="setUp">
<au:assertTrue>
<length length="3" file="${dir.a}/foo" />
</au:assertTrue>
</target>
<target name="testBoth" depends="setUp">
<length property="length.foo" file="${dir.a}/foo">
<fileset file="${dir.b}/bar" />
</length>
<au:assertTrue>
<equals arg1="6" arg2="${length.foo}" />
</au:assertTrue>
</target>
<target name="testBothCondition" depends="setUp">
<au:assertTrue>
<length length="6" file="${dir.a}/foo">
<fileset file="${dir.b}/bar" />
</length>
</au:assertTrue>
</target>
<target name="testDupes" depends="setUp">
<length property="length.foo" file="${dir.a}/foo">
<fileset dir="${dir}" />
</length>
<au:assertTrue>
<equals arg1="9" arg2="${length.foo}" />
</au:assertTrue>
</target>
<target name="testDupesCondition" depends="setUp">
<au:assertTrue>
<length length="9" file="${dir.a}/foo">
<fileset dir="${dir}" />
</length>
</au:assertTrue>
</target>
<target name="testString">
<length string="foo" property="length.string" />
<au:assertTrue>
<equals arg1="3" arg2="${length.string}" />
</au:assertTrue>
</target>
<target name="testStringCondition">
<au:assertTrue>
<length string="foo" length="3" />
</au:assertTrue>
</target>
<target name="testTrimString">
<length string=" foo " trim="true" property="length.string" />
<au:assertTrue>
<equals arg1="3" arg2="${length.string}" />
</au:assertTrue>
</target>
<target name="testTrimStringCondition">
<au:assertTrue>
<length string=" foo " trim="true" length="3" />
</au:assertTrue>
</target>
<target name="testNoTrimString">
<length string=" foo " property="length.string" />
<au:assertTrue>
<equals arg1="5" arg2="${length.string}" />
</au:assertTrue>
</target>
<target name="testNoTrimStringCondition">
<au:assertTrue>
<length string=" foo " length="5" />
</au:assertTrue>
</target>
<target name="testTrimFile" description="should fail">
<au:expectfailure>
<length file="${ant.file}" trim="false" />
</au:expectfailure>
</target>
<target name="testStringFile" description="should fail">
<au:expectfailure>
<length string="foo" file="${ant.file}" />
</au:expectfailure>
</target>
<target name="testImmutable">
<length string="foo" property="length.string" />
<length string="foobar" property="length.string" />
<au:assertTrue>
<equals arg1="3" arg2="${length.string}" />
</au:assertTrue>
</target>
<target name="zip" depends="setUp">
<zip destfile="${zipfile}">
<fileset file="${foo}" />
<fileset file="${bar}" />
</zip>
</target>
<target name="testZipFileSet" depends="zip">
<length property="length.zipfile1">
<zipfileset src="${zipfile}" />
</length>
<length property="length.zipfile2">
<zipfileset src="${zipfile}" includes="bar" />
</length>
<au:assertTrue>
<and>
<equals arg1="6" arg2="${length.zipfile1}" />
<equals arg1="3" arg2="${length.zipfile2}" />
</and>
</au:assertTrue>
</target>
<target name="testZipFileSetCondition" depends="zip">
<au:assertTrue>
<and>
<length length="6">
<zipfileset src="${zipfile}" />
</length>
<length length="3">
<zipfileset src="${zipfile}" includes="bar" />
</length>
</and>
</au:assertTrue>
</target>
</project>