Submitted by: David Rees <d.rees.l@usa.net> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268778 13f79535-47bb-0310-9956-ffa450edef68master
@@ -3,7 +3,17 @@ | |||||
<project name="copy-test" basedir="." default="test1"> | <project name="copy-test" basedir="." default="test1"> | ||||
<target name="test1"> | <target name="test1"> | ||||
<copy file="copy.xml" todir="." overwrite="true"/> | |||||
<copy file="copy.xml" tofile="copytest1.tmp" /> | |||||
</target> | </target> | ||||
<target name="test2"> | |||||
<copy file="copy.xml" todir="copytest1dir" overwrite="true"/> | |||||
</target> | |||||
<target name="cleanup"> | |||||
<delete file="copytest1.tmp"/> | |||||
<delete dir="copytest1dir"/> | |||||
</target> | |||||
</project> | </project> |
@@ -25,8 +25,13 @@ | |||||
</target> | </target> | ||||
<target name="test6"> | <target name="test6"> | ||||
<mkdir dir="testdir" /> | |||||
<copyfile src="copyfile.xml" | <copyfile src="copyfile.xml" | ||||
dest="testdir"/> | |||||
dest="testdir" | |||||
forceoverwrite="true" /> | |||||
</target> | </target> | ||||
<target name="cleanup"> | |||||
<delete dir="testdir" /> | |||||
</target> | |||||
</project> | </project> |
@@ -7,7 +7,7 @@ | |||||
</target> | </target> | ||||
<target name="test2"> | <target name="test2"> | ||||
<deltree dir="src/etc/testcases/taskdefs.tmp"/> | |||||
<deltree dir="taskdefs.tmp"/> | |||||
</target> | </target> | ||||
</project> | </project> |
@@ -19,11 +19,11 @@ | |||||
</target> | </target> | ||||
<target name="test5"> | <target name="test5"> | ||||
<get src="http://localhost" dest=""/> | |||||
<get src="http://www.apache.org" dest=""/> | |||||
</target> | </target> | ||||
<target name="test6"> | <target name="test6"> | ||||
<get src="http://localhost" dest="get.tmp"/> | |||||
<get src="http://www.apache.org" dest="get.tmp"/> | |||||
</target> | </target> | ||||
</project> | </project> |
@@ -0,0 +1,91 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs; | |||||
/** | |||||
* Tests FileSet using the Copy task. | |||||
* | |||||
* @author David Rees <dave@ubiqsoft.com> | |||||
*/ | |||||
public class CopyTest extends TaskdefsTest { | |||||
public CopyTest(String name) { | |||||
super(name); | |||||
} | |||||
public void setUp() { | |||||
configureProject("src/etc/testcases/taskdefs/copy.xml"); | |||||
} | |||||
public void test1() { | |||||
executeTarget("test1"); | |||||
java.io.File f = new java.io.File(getProjectDir(), "copytest1.tmp"); | |||||
if ( !f.exists()) { | |||||
fail("Copy failed"); | |||||
} | |||||
} | |||||
public void tearDown() { | |||||
executeTarget("cleanup"); | |||||
} | |||||
public void test2() { | |||||
executeTarget("test2"); | |||||
java.io.File f = new java.io.File(getProjectDir(), "copytest1dir/copy.xml"); | |||||
if ( !f.exists()) { | |||||
fail("Copy failed"); | |||||
} | |||||
} | |||||
} |
@@ -54,6 +54,8 @@ | |||||
package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
import java.io.File; | |||||
/** | /** | ||||
* @author Nico Seessle <nico@seessle.de> | * @author Nico Seessle <nico@seessle.de> | ||||
*/ | */ | ||||
@@ -85,7 +87,7 @@ public class CopydirTest extends TaskdefsTest { | |||||
public void test5() { | public void test5() { | ||||
executeTarget("test5"); | executeTarget("test5"); | ||||
java.io.File f = new java.io.File("src/etc/testcases/taskdefs.tmp"); | |||||
java.io.File f = new java.io.File(getProjectDir(), "../taskdefs.tmp"); | |||||
if (!f.exists() || !f.isDirectory()) { | if (!f.exists() || !f.isDirectory()) { | ||||
fail("Copy failed"); | fail("Copy failed"); | ||||
} | } | ||||
@@ -54,11 +54,17 @@ | |||||
package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
import java.io.File; | |||||
/** | /** | ||||
* @author Nico Seessle <nico@seessle.de> | * @author Nico Seessle <nico@seessle.de> | ||||
*/ | */ | ||||
public class CopyfileTest extends TaskdefsTest { | public class CopyfileTest extends TaskdefsTest { | ||||
public void test6() { | |||||
expectBuildException("test6", "target is directory"); | |||||
} | |||||
public CopyfileTest(String name) { | public CopyfileTest(String name) { | ||||
super(name); | super(name); | ||||
} | } | ||||
@@ -67,6 +73,10 @@ public class CopyfileTest extends TaskdefsTest { | |||||
configureProject("src/etc/testcases/taskdefs/copyfile.xml"); | configureProject("src/etc/testcases/taskdefs/copyfile.xml"); | ||||
} | } | ||||
public void tearDown() { | |||||
executeTarget("cleanup"); | |||||
} | |||||
public void test1() { | public void test1() { | ||||
expectBuildException("test1", "required argument not specified"); | expectBuildException("test1", "required argument not specified"); | ||||
} | } | ||||
@@ -85,7 +95,7 @@ public class CopyfileTest extends TaskdefsTest { | |||||
public void test5() { | public void test5() { | ||||
executeTarget("test5"); | executeTarget("test5"); | ||||
java.io.File f = new java.io.File("src/etc/testcases/taskdefs/copyfile.tmp"); | |||||
java.io.File f = new java.io.File(getProjectDir(), "copyfile.tmp"); | |||||
if (f.exists()) { | if (f.exists()) { | ||||
f.delete(); | f.delete(); | ||||
} else { | } else { | ||||
@@ -64,15 +64,13 @@ import java.io.IOException; | |||||
* @author Nico Seessle <nico@seessle.de> | * @author Nico Seessle <nico@seessle.de> | ||||
*/ | */ | ||||
public class FilterTest extends TaskdefsTest { | public class FilterTest extends TaskdefsTest { | ||||
private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/"; | |||||
public FilterTest(String name) { | public FilterTest(String name) { | ||||
super(name); | super(name); | ||||
} | } | ||||
public void setUp() { | public void setUp() { | ||||
configureProject(TASKDEFS_DIR + "filter.xml"); | |||||
configureProject("src/etc/testcases/taskdefs/filter.xml"); | |||||
} | } | ||||
public void test1() { | public void test1() { | ||||
@@ -94,32 +92,32 @@ public class FilterTest extends TaskdefsTest { | |||||
public void test5() { | public void test5() { | ||||
executeTarget("test5"); | executeTarget("test5"); | ||||
assertEquals("2000", | assertEquals("2000", | ||||
getFilteredFile("5", TASKDEFS_DIR + "filtered.tmp")); | |||||
getFilteredFile("5", "filtered.tmp")); | |||||
} | } | ||||
public void test6() { | public void test6() { | ||||
executeTarget("test6"); | executeTarget("test6"); | ||||
assertEquals("2000", | assertEquals("2000", | ||||
getFilteredFile("6", TASKDEFS_DIR + "taskdefs.tmp/filter1.txt")); | |||||
getFilteredFile("6", "taskdefs.tmp/filter1.txt")); | |||||
} | } | ||||
public void test7() { | public void test7() { | ||||
executeTarget("test7"); | executeTarget("test7"); | ||||
assertEquals("<%@ include file=\"root/some/include.jsp\"%>", | assertEquals("<%@ include file=\"root/some/include.jsp\"%>", | ||||
getFilteredFile("7", TASKDEFS_DIR + "filtered.tmp")); | |||||
getFilteredFile("7", "filtered.tmp")); | |||||
} | } | ||||
public void test8() { | public void test8() { | ||||
executeTarget("test8"); | executeTarget("test8"); | ||||
assertEquals("<%@ include file=\"root/some/include.jsp\"%>", | assertEquals("<%@ include file=\"root/some/include.jsp\"%>", | ||||
getFilteredFile("8", TASKDEFS_DIR + "taskdefs.tmp/filter2.txt")); | |||||
getFilteredFile("8", "taskdefs.tmp/filter2.txt")); | |||||
} | } | ||||
private String getFilteredFile(String testNumber, String filteredFile) { | private String getFilteredFile(String testNumber, String filteredFile) { | ||||
String line = null; | String line = null; | ||||
File f = new File(filteredFile); | |||||
File f = new File(getProjectDir(), filteredFile); | |||||
if (!f.exists()) { | if (!f.exists()) { | ||||
fail("filter test"+testNumber+" failed"); | fail("filter test"+testNumber+" failed"); | ||||
} else { | } else { | ||||
@@ -52,7 +52,9 @@ | |||||
* <http://www.apache.org/>. | * <http://www.apache.org/>. | ||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs; | |||||
package org.apache.tools.ant.taskdefs; | |||||
import java.io.File; | |||||
/** | /** | ||||
* @author Nico Seessle <nico@seessle.de> | * @author Nico Seessle <nico@seessle.de> | ||||
@@ -77,12 +79,12 @@ public class GUnzipTest extends TaskdefsTest { | |||||
public void test3() { | public void test3() { | ||||
executeTarget("test3"); | executeTarget("test3"); | ||||
java.io.File f = new java.io.File("src/etc/testcases/taskdefs/gzip.tmp2"); | |||||
java.io.File f = new File(getProjectDir(), "gzip.tmp2"); | |||||
if (!f.exists()) { | if (!f.exists()) { | ||||
fail("gzip failed"); | fail("gzip failed"); | ||||
} else { | } else { | ||||
f.delete(); | f.delete(); | ||||
f = new java.io.File("src/etc/testcases/taskdefs/gzip.tmp"); | |||||
f = new File(getProjectDir(), "gzip.tmp"); | |||||
if (f.exists()) f.delete(); | if (f.exists()) f.delete(); | ||||
} | } | ||||
} | } | ||||
@@ -54,6 +54,8 @@ | |||||
package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
import java.io.File; | |||||
/** | /** | ||||
* @author Nico Seessle <nico@seessle.de> | * @author Nico Seessle <nico@seessle.de> | ||||
*/ | */ | ||||
@@ -84,21 +86,18 @@ public class GetTest extends TaskdefsTest { | |||||
} | } | ||||
public void test5() { | public void test5() { | ||||
// We can't expect a build-system to have a webserver installed... | |||||
//expectBuildException("test5", "dest invalid (or no http-server on local machine)"); | |||||
expectBuildException("test5", "dest invalid (or no http-server on local machine)"); | |||||
} | } | ||||
public void test6() { | public void test6() { | ||||
// We can't expect a build-system to have a webserver installed... | |||||
/* | |||||
executeTarget("test6"); | executeTarget("test6"); | ||||
java.io.File f = new java.io.File("src/etc/testcases/taskdefs/get.tmp"); | |||||
java.io.File f = new File(getProjectDir(), "get.tmp"); | |||||
if (!f.exists()) { | if (!f.exists()) { | ||||
fail("get failed"); | fail("get failed"); | ||||
} else { | } else { | ||||
f.delete(); | f.delete(); | ||||
} | } | ||||
*/ | |||||
} | } | ||||
} | } |
@@ -54,6 +54,8 @@ | |||||
package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
import java.io.File; | |||||
/** | /** | ||||
* @author Nico Seessle <nico@seessle.de> | * @author Nico Seessle <nico@seessle.de> | ||||
*/ | */ | ||||
@@ -85,7 +87,7 @@ public class GzipTest extends TaskdefsTest { | |||||
public void test5() { | public void test5() { | ||||
executeTarget("test5"); | executeTarget("test5"); | ||||
java.io.File f = new java.io.File("src/etc/testcases/taskdefs/gzip.tmp"); | |||||
java.io.File f = new java.io.File(getProjectDir(), "gzip.tmp"); | |||||
if (!f.exists()) { | if (!f.exists()) { | ||||
fail("gzip failed"); | fail("gzip failed"); | ||||
} | } | ||||
@@ -63,7 +63,7 @@ import java.util.Date; | |||||
public class JarTest extends TaskdefsTest { | public class JarTest extends TaskdefsTest { | ||||
private static long jarModifiedDate; | private static long jarModifiedDate; | ||||
private static String tempJar = "src/etc/testcases/taskdefs/tmp.jar"; | |||||
private static String tempJar = "tmp.jar"; | |||||
public JarTest(String name) { | public JarTest(String name) { | ||||
super(name); | super(name); | ||||
@@ -87,14 +87,14 @@ public class JarTest extends TaskdefsTest { | |||||
public void test4() { | public void test4() { | ||||
executeTarget("test4"); | executeTarget("test4"); | ||||
File jarFile = new File(tempJar); | |||||
File jarFile = new File(getProjectDir(), tempJar); | |||||
assert(jarFile.exists()); | assert(jarFile.exists()); | ||||
jarModifiedDate = jarFile.lastModified(); | jarModifiedDate = jarFile.lastModified(); | ||||
} | } | ||||
public void XXXtest5() { | public void XXXtest5() { | ||||
executeTarget("test5"); | executeTarget("test5"); | ||||
File jarFile = new File(tempJar); | |||||
File jarFile = new File(getProjectDir(), tempJar); | |||||
assertEquals(jarModifiedDate, jarFile.lastModified()); | assertEquals(jarModifiedDate, jarFile.lastModified()); | ||||
} | } | ||||
} | } |
@@ -1,3 +1,5 @@ | |||||
package org.apache.tools.ant.taskdefs; | |||||
/* | /* | ||||
* The Apache Software License, Version 1.1 | * The Apache Software License, Version 1.1 | ||||
* | * | ||||
@@ -52,8 +54,6 @@ | |||||
* <http://www.apache.org/>. | * <http://www.apache.org/>. | ||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs; | |||||
/** | /** | ||||
* @author Nico Seessle <nico@seessle.de> | * @author Nico Seessle <nico@seessle.de> | ||||
*/ | */ | ||||
@@ -61,8 +61,8 @@ public class MkdirTest extends TaskdefsTest { | |||||
public MkdirTest(String name) { | public MkdirTest(String name) { | ||||
super(name); | super(name); | ||||
} | |||||
} | |||||
public void setUp() { | public void setUp() { | ||||
configureProject("src/etc/testcases/taskdefs/mkdir.xml"); | configureProject("src/etc/testcases/taskdefs/mkdir.xml"); | ||||
} | } | ||||
@@ -77,12 +77,11 @@ public class MkdirTest extends TaskdefsTest { | |||||
public void test3() { | public void test3() { | ||||
executeTarget("test3"); | executeTarget("test3"); | ||||
java.io.File f = new java.io.File("src/etc/testcases/taskdefs/testdir.tmp"); | |||||
java.io.File f = new java.io.File(getProjectDir(), "testdir.tmp"); | |||||
if (!f.exists() || !f.isDirectory()) { | if (!f.exists() || !f.isDirectory()) { | ||||
fail("mkdir failed"); | fail("mkdir failed"); | ||||
} else { | } else { | ||||
f.delete(); | f.delete(); | ||||
} | } | ||||
} | } | ||||
} | } |
@@ -79,12 +79,7 @@ public abstract class TaskdefsTest extends TestCase { | |||||
} | } | ||||
protected void expectBuildException(String taskname, String cause) { | protected void expectBuildException(String taskname, String cause) { | ||||
try { | |||||
executeTarget(taskname); | |||||
} catch (org.apache.tools.ant.BuildException ex) { | |||||
return; | |||||
} | |||||
fail("Should throw BuildException because: " + cause); | |||||
expectSpecificBuildException(taskname, cause, null); | |||||
} | } | ||||
protected void expectOutput(String taskname, String output) { | protected void expectOutput(String taskname, String output) { | ||||
@@ -170,6 +165,21 @@ public abstract class TaskdefsTest extends TestCase { | |||||
} | } | ||||
protected File getProjectDir() { | |||||
return project.getBaseDir(); | |||||
} | |||||
protected void expectSpecificBuildException(String taskname, String cause, String msg) { | |||||
try { | |||||
executeTarget(taskname); | |||||
} catch (org.apache.tools.ant.BuildException ex) { | |||||
if ((null != msg) && (ex.getMessage() != msg)) { | |||||
fail("Should throw BuildException because '" + cause + "' with message '" + msg + "' (received message '" + ex.getMessage() + "' instead)"); | |||||
} | |||||
return; | |||||
} | |||||
fail("Should throw BuildException because: " + cause); | |||||
} | |||||
private class AntOutputStream extends java.io.OutputStream { | private class AntOutputStream extends java.io.OutputStream { | ||||
public void write(int b) { | public void write(int b) { | ||||
outBuffer.append((char)b); | outBuffer.append((char)b); | ||||