Browse Source

creating temporary directory with a unique name

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1584252 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 11 years ago
parent
commit
2452098505
7 changed files with 181 additions and 171 deletions
  1. +15
    -16
      src/etc/testcases/taskdefs/available.xml
  2. +99
    -78
      src/etc/testcases/taskdefs/calltarget.xml
  3. +31
    -46
      src/etc/testcases/taskdefs/copy.xml
  4. +9
    -0
      src/tests/junit/org/apache/tools/ant/BuildFileTest.java
  5. +1
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java
  6. +1
    -3
      src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java
  7. +25
    -28
      src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java

+ 15
- 16
src/etc/testcases/taskdefs/available.xml View File

@@ -18,8 +18,10 @@

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

<target name="tearDown">
<delete dir="greatgrandparent"/>
<import file="../buildfiletest-base.xml"/>

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

<target name="test1">
@@ -153,14 +155,12 @@

<target name="test24">
<!-- create a dummy file and look for it -->
<mkdir dir="${user.dir}/test"/>
<echo message="package test;public class test {}" file="${user.dir}/test/test.java"/>
<javac srcdir="${user.dir}" includes="test/test.java"/>
<jar destfile="${user.dir}/test.jar" basedir="${user.dir}" includes="test/test.class"/>
<mkdir dir="${output}/test"/>
<echo message="package test;public class test {}" file="${output}/test/test.java"/>
<javac srcdir="${output}" includes="test/test.java"/>
<jar destfile="${output}/test.jar" basedir="${output}" includes="test/test.class"/>
<available property="test"
classname="test.test" classpath="${user.dir}/test.jar"/>
<delete dir="${user.dir}/test"/>
<delete file="${user.dir}/test.jar"/>
classname="test.test" classpath="${output}/test.jar"/>
</target>

<target name="searchInPathNotThere">
@@ -183,14 +183,13 @@
</target>

<target name="prep.parents">
<delete quiet="yes" dir="greatgrandparent"/>
<mkdir dir="greatgrandparent/grandparent/parent/dir"/>
<touch file="greatgrandparent/a.txt"/>
<touch file="greatgrandparent/grandparent/b.txt"/>
<touch file="greatgrandparent/grandparent/parent/c.txt"/>
<touch file="greatgrandparent/grandparent/parent/dir/d.txt"/>
<mkdir dir="${output}/greatgrandparent/grandparent/parent/dir"/>
<touch file="${output}/greatgrandparent/a.txt"/>
<touch file="${output}/greatgrandparent/grandparent/b.txt"/>
<touch file="${output}/greatgrandparent/grandparent/parent/c.txt"/>
<touch file="${output}/greatgrandparent/grandparent/parent/dir/d.txt"/>
<property name="available.test.dir"
value="greatgrandparent/grandparent/parent/dir"/>
value="${output}/greatgrandparent/grandparent/parent/dir"/>
</target>
<target name="search-parents" depends="prep.parents">
<echo>testing greatgrandparent - should see</echo>


+ 99
- 78
src/etc/testcases/taskdefs/calltarget.xml View File

@@ -15,85 +15,106 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name ="calltarget-test" default="testinheritreffileset" basedir=".">
<property name="tmp.dir" value="tmp.dir" />
<target name="setup">
<mkdir dir="${tmp.dir}"/>
</target>
<target name="cleanup">
<delete dir="${tmp.dir}" quiet="true"/>
</target>
<target name="mytarget">
<pathconvert property="myproperty" targetos="unix" refid="myfileset"/>
<echo message="myproperty=${myproperty}"/>
</target>
<target name="testinheritreffileset">
<project name="calltarget-test" default="testinheritreffileset" basedir=".">

<import file="../buildfiletest-base.xml"/>

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

<target name="mytarget">
<pathconvert property="myproperty" targetos="unix" refid="myfileset"/>
<echo message="myproperty=${myproperty}"/>
</target>

<target name="testinheritreffileset">
<!-- this testcase should show that the fileset defined here
can be read in the called target -->
<fileset dir="." id="myfileset">
<include name="calltarget.xml"/>
</fileset>
<antcall target="mytarget" inheritrefs="true"/>
</target>
<target name="copytest2">
<copy file="${tmp.dir}/copytest.in" toFile="${tmp.dir}/copytest1.out" overwrite="true">
<filterset refid="foo"/>
</copy>
</target>
<target name="testinheritreffilterset" depends="setup">
<echo file="${tmp.dir}/copytest.in">@@foo@@</echo>
<filterset id="foo" begintoken="@@" endtoken="@@">
<filter token="foo" value="bar"/>
</filterset>
<antcall target="copytest2" inheritrefs="true"/>
<copy file="${tmp.dir}/copytest.in" toFile="${tmp.dir}/copytest2.out" overwrite="true">
<filterset refid="foo"/>
</copy>
<loadfile srcFile="${tmp.dir}/copytest2.out" property="copytest2"/>
<loadfile srcFile="${tmp.dir}/copytest1.out" property="copytest1"/>
<condition property="success">
<equals arg1="${copytest1}" arg2="${copytest2}"/>
</condition>
<fail message="filterset not properly passed across by antcall" unless="success"/>
</target>

<property name="multi" value="DEFAULT"/>
<target name="multi">
<echo>multi is ${multi}</echo>
</target>
<target name="call-multi">
<antcall target="multi">
<param name="multi" value="SET"/>
</antcall>
</target>

<target name="blank-target">
<antcall>
<target name="" />
</antcall>
</target>

<target name="multiple-targets">
<antcall>
<target name="ta" />
<target name="tb" />
<target name="tc" />
</antcall>
</target>

<target name="multiple-targets-2">
<ant antfile="ant.xml">
<target name="tb" />
<target name="da" />
</ant>
</target>

<target name="ta"><echo>ta</echo></target>
<target name="tb" depends="da,dc"><echo>tb</echo></target>
<target name="tc" depends="db,dc"><echo>tc</echo></target>

<target name="da"><echo>da</echo></target>
<target name="db"><echo>db</echo></target>
<target name="dc"><echo>dc</echo></target>
<fileset dir="." id="myfileset">
<include name="calltarget.xml"/>
</fileset>
<antcall target="mytarget" inheritrefs="true"/>
</target>

<target name="copytest2">
<copy file="${output}/copytest.in" toFile="${output}/copytest1.out" overwrite="true">
<filterset refid="foo"/>
</copy>
</target>

<target name="testinheritreffilterset" depends="setUp">
<echo file="${output}/copytest.in">@@foo@@</echo>
<filterset id="foo" begintoken="@@" endtoken="@@">
<filter token="foo" value="bar"/>
</filterset>
<antcall target="copytest2" inheritrefs="true"/>
<copy file="${output}/copytest.in" toFile="${output}/copytest2.out" overwrite="true">
<filterset refid="foo"/>
</copy>
<loadfile srcFile="${output}/copytest2.out" property="copytest2"/>
<loadfile srcFile="${output}/copytest1.out" property="copytest1"/>
<condition property="success">
<equals arg1="${copytest1}" arg2="${copytest2}"/>
</condition>
<fail message="filterset not properly passed across by antcall" unless="success"/>
</target>

<property name="multi" value="DEFAULT"/>

<target name="multi">
<echo>multi is ${multi}</echo>
</target>

<target name="call-multi">
<antcall target="multi">
<param name="multi" value="SET"/>
</antcall>
</target>

<target name="blank-target">
<antcall>
<target name=""/>
</antcall>
</target>

<target name="multiple-targets">
<antcall>
<target name="ta"/>
<target name="tb"/>
<target name="tc"/>
</antcall>
</target>

<target name="multiple-targets-2">
<ant antfile="ant.xml">
<target name="tb"/>
<target name="da"/>
</ant>
</target>

<target name="ta">
<echo>ta</echo>
</target>

<target name="tb" depends="da,dc">
<echo>tb</echo>
</target>

<target name="tc" depends="db,dc">
<echo>tc</echo>
</target>

<target name="da">
<echo>da</echo>
</target>

<target name="db">
<echo>db</echo>
</target>

<target name="dc">
<echo>dc</echo>
</target>

</project>

+ 31
- 46
src/etc/testcases/taskdefs/copy.xml View File

@@ -18,64 +18,66 @@

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

<import file="../buildfiletest-base.xml"/>

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

<target name="test1">
<copy file="copy.xml" tofile="copytest1.tmp" />
<copy file="copy.xml" tofile="${output}/copytest1.tmp" />
</target>

<target name="test2">
<copy file="copy.xml" todir="copytest1dir" overwrite="true"/>
<copy file="copy.xml" todir="${output}/copytest1dir" overwrite="true"/>
</target>

<target name="filtertest">
<!-- check fix for bugzilla 23154 -->
<delete quiet="yes" file="copy.filter.out"/>
<delete quiet="yes" file="copy.filter.inp"/>
<concat destfile="copy.filter.inp">
<concat destfile="${output}/copy.filter.inp">
PRODUCT_VERSION=6.2.1.4
PRODUCT_BUILD=6.5 (BLD_65036)
PRODUCT_VERSION=6.2.1.4
PRODUCT_BUILD=6.5 (BLD_65036)
</concat>
<copy file="copy.filter.inp" tofile="copy.filter.out">
<copy file="${output}/copy.filter.inp" tofile="${output}/copy.filter.out">
<filterset begintoken="6" endtoken="4">
<filter token=".2.1." value="2.6.4" />
</filterset>
</copy>
<concat><path path="copy.filter.out"/></concat>
<concat><path path="${output}/copy.filter.out"/></concat>
</target>

<target name="infinitetest">
<delete quiet="yes" file="copy.filter.out"/>
<delete quiet="yes" file="copy.filter.inp"/>
<concat destfile="copy.filter.inp">
<concat destfile="${output}/copy.filter.inp">
a=b=
</concat>
<copy file="copy.filter.inp" tofile="copy.filter.out">
<copy file="${output}/copy.filter.inp" tofile="${output}/copy.filter.out">
<filterset begintoken="=" endtoken="=">
<filter token="b" value="=b="/>
</filterset>
</copy>
<concat><path path="copy.filter.out"/></concat>
<concat><path path="${output}/copy.filter.out"/></concat>
</target>

<target name="test3">
<!-- create an empty file -->
<touch file="copytest3.tmp"/>
<touch file="${output}/copytest3.tmp"/>
<!--wait -->
<sleep seconds="4"/>
<!-- copy a different file to two places -->
<copy file="copy.xml" tofile="copytest3a.tmp" overwrite="true"/>
<copy file="copy.xml" tofile="copytest3b.tmp" overwrite="true"/>
<copy file="copy.xml" tofile="${output}/copytest3a.tmp" overwrite="true"/>
<copy file="copy.xml" tofile="${output}/copytest3b.tmp" overwrite="true"/>
<!--wait -->
<sleep seconds="4"/>
<!-- copy an old file onto a newer file (should not work) -->
<copy file="copytest3.tmp" tofile="copytest3b.tmp" />
<copy file="${output}/copytest3.tmp" tofile="${output}/copytest3b.tmp" />
<!-- copy an older file onto a new one, should succeed -->
<copy file="copytest3.tmp" tofile="copytest3c.tmp"
<copy file="${output}/copytest3.tmp" tofile="${output}/copytest3c.tmp"
overwrite="true"
preservelastmodified="true" />
<!-- copy a newer file onto an older one (should work) -->
<copy file="copytest3a.tmp" tofile="copytest3.tmp"
<copy file="${output}/copytest3a.tmp" tofile="${output}/copytest3.tmp"
preservelastmodified="true" />
<!-- expected state :
3a.tmp==3.tmp==copy.xml
@@ -87,13 +89,13 @@ a=b=
</target>

<target name="test_single_file_fileset">
<copy tofile="copytest_single_file_fileset.tmp">
<copy tofile="${output}/copytest_single_file_fileset.tmp">
<fileset dir="." includes="copy.xml"/>
</copy>
</target>

<target name="test_single_file_path">
<copy tofile="copytest_single_file_path.tmp">
<copy tofile="${output}/copytest_single_file_path.tmp">
<path>
<pathelement location="copy.xml"/>
</path>
@@ -101,7 +103,7 @@ a=b=
</target>

<target name="testFilterSet">
<copy file="copy.filterset" tofile="copy.filterset.tmp">
<copy file="copy.filterset" tofile="${output}/copy.filterset.tmp">
<filterset>
<filter token="TITLE" value="Apache Ant Project"/>
</filterset>
@@ -109,7 +111,7 @@ a=b=
</target>

<target name="testFilterChain">
<copy file="copy.filterset" tofile="copy.filterchain.tmp">
<copy file="copy.filterset" tofile="${output}/copy.filterchain.tmp">
<filterchain>
<replacetokens>
<token key="TITLE" value="Apache Ant Project"/>
@@ -119,34 +121,34 @@ a=b=
</target>

<target name="testTranscoding">
<copy file="copy/input/iso8859-1" tofile="copytest1.tmp"
<copy file="copy/input/iso8859-1" tofile="${output}/copytest1.tmp"
encoding="ISO8859_1" outputencoding="UTF8"/>
</target>

<target name="testMissingFileIgnore">
<copy file="not-there" tofile="copytest1.tmp"
<copy file="not-there" tofile="${output}/copytest1.tmp"
failonerror="false"/>
</target>

<target name="testMissingFileBail">
<copy file="not-there" tofile="copytest1.tmp"
<copy file="not-there" tofile="${output}/copytest1.tmp"
failonerror="true"/>
</target>

<target name="testMissingDirIgnore">
<copy todir="copytest1dir" failonerror="false">
<copy todir="${output}" failonerror="false">
<fileset dir="not-there"/>
</copy>
</target>

<target name="testMissingDirBail">
<copy todir="copytest1dir" failonerror="true">
<copy todir="${output}" failonerror="true">
<fileset dir="not-there"/>
</copy>
</target>

<property name="to.dir" value="copy-todir-tmp"/>
<property name="from.dir" value="copy-fromdir-tmp"/>
<property name="to.dir" value="${output}/copy-todir-tmp"/>
<property name="from.dir" value="${output}/copy-fromdir-tmp"/>

<target name="testResource.prepare">
<mkdir dir="${from.dir}"/>
@@ -266,21 +268,4 @@ a=b=
</fail>
</target>

<target name="cleanup">
<delete file="copytest1.tmp"/>
<delete file="copytest3.tmp"/>
<delete file="copytest3a.tmp"/>
<delete file="copytest3b.tmp"/>
<delete file="copytest3c.tmp"/>
<delete file="copytest_single_file_fileset.tmp"/>
<delete file="copytest_single_file_path.tmp"/>
<delete file="copy.filterset.tmp"/>
<delete file="copy.filterchain.tmp"/>
<delete dir="copytest1dir"/>
<delete quiet="yes" file="copy.filter.out"/>
<delete quiet="yes" file="copy.filter.inp"/>
<delete dir="${from.dir}" quiet="true" />
<delete dir="${to.dir}" quiet="true" />
</target>

</project>

+ 9
- 0
src/tests/junit/org/apache/tools/ant/BuildFileTest.java View File

@@ -351,6 +351,15 @@ public abstract class BuildFileTest extends TestCase {
return project.getBaseDir();
}

/**
* get location of temporary directory pointed to by property "output"
* @return location of temporary directory pointed to by property "output"
* @since Ant 1.9.4
*/
public File getOutputDir() {
return new File(project.getProperty("output"));
}

/**
* Runs a target, wait for a build exception.
*


+ 1
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java View File

@@ -31,6 +31,7 @@ public class AvailableTest extends BuildFileTest {

public void setUp() {
configureProject("src/etc/testcases/taskdefs/available.xml");
executeTarget("setUp");
}

// Nothing specified -> Fail


+ 1
- 3
src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java View File

@@ -32,6 +32,7 @@ public class CallTargetTest extends BuildFileTest {

public void setUp() {
configureProject("src/etc/testcases/taskdefs/calltarget.xml");
executeTarget("setUp");
}

// see bugrep 21724 (references not passing through with antcall)
@@ -66,7 +67,4 @@ public class CallTargetTest extends BuildFileTest {
expectLog("multiple-targets-2", "dadctb");
}

public void tearDown() {
project.executeTarget("cleanup");
}
}

+ 25
- 28
src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java View File

@@ -39,23 +39,20 @@ public class CopyTest extends BuildFileTest {

public void setUp() {
configureProject("src/etc/testcases/taskdefs/copy.xml");
executeTarget("setUp");
}

public void test1() {
executeTarget("test1");
File f = new File(getProjectDir(), "copytest1.tmp");
File f = new File(getOutputDir(), "copytest1.tmp");
if ( !f.exists()) {
fail("Copy failed");
}
}

public void tearDown() {
executeTarget("cleanup");
}

public void test2() {
executeTarget("test2");
File f = new File(getProjectDir(), "copytest1dir/copy.xml");
File f = new File(getOutputDir(), "copytest1dir/copy.xml");
if ( !f.exists()) {
fail("Copy failed");
}
@@ -63,13 +60,13 @@ public class CopyTest extends BuildFileTest {

public void test3() {
executeTarget("test3");
File file3 = new File(getProjectDir(), "copytest3.tmp");
File file3 = new File(getOutputDir(), "copytest3.tmp");
assertTrue(file3.exists());
File file3a = new File(getProjectDir(), "copytest3a.tmp");
File file3a = new File(getOutputDir(), "copytest3a.tmp");
assertTrue(file3a.exists());
File file3b = new File(getProjectDir(), "copytest3b.tmp");
File file3b = new File(getOutputDir(), "copytest3b.tmp");
assertTrue(file3b.exists());
File file3c = new File(getProjectDir(), "copytest3c.tmp");
File file3c = new File(getOutputDir(), "copytest3c.tmp");
assertTrue(file3c.exists());

//file length checks rely on touch generating a zero byte file
@@ -101,7 +98,7 @@ public class CopyTest extends BuildFileTest {

public void testFilterSet() throws IOException {
executeTarget("testFilterSet");
File tmp = new File(getProjectDir(), "copy.filterset.tmp");
File tmp = new File(getOutputDir(), "copy.filterset.tmp");
File check = new File(getProjectDir(), "expected/copy.filterset.filtered");
assertTrue(tmp.exists());
assertTrue(FILE_UTILS.contentEquals(tmp, check));
@@ -109,7 +106,7 @@ public class CopyTest extends BuildFileTest {

public void testFilterChain() throws IOException {
executeTarget("testFilterChain");
File tmp = new File(getProjectDir(), "copy.filterchain.tmp");
File tmp = new File(getOutputDir(), "copy.filterchain.tmp");
File check = new File(getProjectDir(), "expected/copy.filterset.filtered");
assertTrue(tmp.exists());
assertTrue(FILE_UTILS.contentEquals(tmp, check));
@@ -117,14 +114,14 @@ public class CopyTest extends BuildFileTest {

public void testSingleFileFileset() {
executeTarget("test_single_file_fileset");
File file = new File(getProjectDir(),
File file = new File(getOutputDir(),
"copytest_single_file_fileset.tmp");
assertTrue(file.exists());
}

public void testSingleFilePath() {
executeTarget("test_single_file_path");
File file = new File(getProjectDir(),
File file = new File(getOutputDir(),
"copytest_single_file_path.tmp");
assertTrue(file.exists());
}
@@ -132,7 +129,7 @@ public class CopyTest extends BuildFileTest {
public void testTranscoding() throws IOException {
executeTarget("testTranscoding");
File f1 = getProject().resolveFile("copy/expected/utf-8");
File f2 = getProject().resolveFile("copytest1.tmp");
File f2 = new File(getOutputDir(), "copytest1.tmp");
assertTrue(FILE_UTILS.contentEquals(f1, f2));
}

@@ -158,9 +155,9 @@ public class CopyTest extends BuildFileTest {
public void testFileResourcePlain() {
executeTarget("testFileResourcePlain");
File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file1.txt");
File file2 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file2.txt");
File file3 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file3.txt");
File file1 = new File(getProject().getProperty("to.dir")+"/file1.txt");
File file2 = new File(getProject().getProperty("to.dir")+"/file2.txt");
File file3 = new File(getProject().getProperty("to.dir")+"/file3.txt");
assertTrue(file1.exists());
assertTrue(file2.exists());
assertTrue(file3.exists());
@@ -168,9 +165,9 @@ public class CopyTest extends BuildFileTest {
public void _testFileResourceWithMapper() {
executeTarget("testFileResourceWithMapper");
File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file1.txt.bak");
File file2 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file2.txt.bak");
File file3 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file3.txt.bak");
File file1 = new File(getProject().getProperty("to.dir")+"/file1.txt.bak");
File file2 = new File(getProject().getProperty("to.dir")+"/file2.txt.bak");
File file3 = new File(getProject().getProperty("to.dir")+"/file3.txt.bak");
assertTrue(file1.exists());
assertTrue(file2.exists());
assertTrue(file3.exists());
@@ -178,7 +175,7 @@ public class CopyTest extends BuildFileTest {
public void testFileResourceWithFilter() {
executeTarget("testFileResourceWithFilter");
File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/fileNR.txt");
File file1 = new File(getProject().getProperty("to.dir")+"/fileNR.txt");
assertTrue(file1.exists());
try {
String file1Content = FileUtils.readFully(new FileReader(file1));
@@ -190,9 +187,9 @@ public class CopyTest extends BuildFileTest {
public void testPathAsResource() {
executeTarget("testPathAsResource");
File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file1.txt");
File file2 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file2.txt");
File file3 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file3.txt");
File file1 = new File(getProject().getProperty("to.dir")+"/file1.txt");
File file2 = new File(getProject().getProperty("to.dir")+"/file2.txt");
File file3 = new File(getProject().getProperty("to.dir")+"/file3.txt");
assertTrue(file1.exists());
assertTrue(file2.exists());
assertTrue(file3.exists());
@@ -200,9 +197,9 @@ public class CopyTest extends BuildFileTest {
public void testZipfileset() {
executeTarget("testZipfileset");
File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file1.txt");
File file2 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file2.txt");
File file3 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file3.txt");
File file1 = new File(getProject().getProperty("to.dir")+"/file1.txt");
File file2 = new File(getProject().getProperty("to.dir")+"/file2.txt");
File file3 = new File(getProject().getProperty("to.dir")+"/file3.txt");
assertTrue(file1.exists());
assertTrue(file2.exists());
assertTrue(file3.exists());


Loading…
Cancel
Save