Browse Source

changing tests to adopt unique temporary directories

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1585881 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 11 years ago
parent
commit
7881277034
2 changed files with 52 additions and 18 deletions
  1. +36
    -7
      src/etc/testcases/types/mapper.xml
  2. +16
    -11
      src/tests/junit/org/apache/tools/ant/types/MapperTest.java

+ 36
- 7
src/etc/testcases/types/mapper.xml View File

@@ -18,21 +18,50 @@


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


<target name="test1">
<mkdir dir="copytest" />
<copy todir="copytest">
<import file="../buildfiletest-base.xml"/>

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

<target name="test1" depends="setUp">
<union id="source.resourcecollection">
<fileset dir="../../../main"> <fileset dir="../../../main">
<include name="**/taskdefs/*.java" /> <include name="**/taskdefs/*.java" />
</fileset> </fileset>
<fileset dir="../../../tests/junit"> <fileset dir="../../../tests/junit">
<include name="**/taskdefs/*.java" /> <include name="**/taskdefs/*.java" />
</fileset> </fileset>
</union>
<copy todir="${output}">
<union refid="source.resourcecollection"/>
<mapper type="flatten" /> <mapper type="flatten" />
</copy> </copy>
</target>

<target name="cleanup">
<delete dir="copytest" />
<resourcecount property="sourcefiles.count">
<union refid="source.resourcecollection"/>
</resourcecount>
<resourcecount property="destfiles.count">
<fileset dir="${output}"/>
</resourcecount>
<resourcecount property="destdirs.count">
<dirset dir="${output}"/>
</resourcecount>
<fail message="different number of files in source and destination ${sourcefiles.count} ${destfiles.count}">
<condition>
<not>
<equals arg1="${sourcefiles.count}" arg2="${destfiles.count}"/>
</not>
</condition>
</fail>
<!-- one expects the output of resourcecount on a dirset which does not contain subdirectories to be 1 -->
<!-- it looks like the folder of the dirset itself is counted -->
<fail message="flatten mapper should not copy folders">
<condition>
<not>
<equals arg1="${destdirs.count}" arg2="1"/>
</not>
</condition>
</fail>
</target> </target>


</project> </project>

+ 16
- 11
src/tests/junit/org/apache/tools/ant/types/MapperTest.java View File

@@ -18,6 +18,8 @@


package org.apache.tools.ant.types; package org.apache.tools.ant.types;


import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;


@@ -34,7 +36,6 @@ import org.apache.tools.ant.util.MergingMapper;


/** /**
* JUnit 3 testcases for org.apache.tools.ant.types.Mapper. * JUnit 3 testcases for org.apache.tools.ant.types.Mapper.
*
*/ */


public class MapperTest extends TestCase { public class MapperTest extends TestCase {
@@ -58,7 +59,7 @@ public class MapperTest extends TestCase {
fail("Can add reference to Mapper with from attribute set"); fail("Can add reference to Mapper with from attribute set");
} catch (BuildException be) { } catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid", assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
be.getMessage());
} }


m = new Mapper(project); m = new Mapper(project);
@@ -68,7 +69,7 @@ public class MapperTest extends TestCase {
fail("Can set from in Mapper that is a reference."); fail("Can set from in Mapper that is a reference.");
} catch (BuildException be) { } catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid", assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
be.getMessage());
} }


m = new Mapper(project); m = new Mapper(project);
@@ -78,7 +79,7 @@ public class MapperTest extends TestCase {
fail("Can set to in Mapper that is a reference."); fail("Can set to in Mapper that is a reference.");
} catch (BuildException be) { } catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid", assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
be.getMessage());
} }
try { try {
Mapper.MapperType mt = new Mapper.MapperType(); Mapper.MapperType mt = new Mapper.MapperType();
@@ -87,7 +88,7 @@ public class MapperTest extends TestCase {
fail("Can set type in Mapper that is a reference."); fail("Can set type in Mapper that is a reference.");
} catch (BuildException be) { } catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid", assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
be.getMessage());
} }
} }


@@ -100,7 +101,7 @@ public class MapperTest extends TestCase {
fail("Can make Mapper a Reference to itself."); fail("Can make Mapper a Reference to itself.");
} catch (BuildException be) { } catch (BuildException be) {
assertEquals("This data type contains a circular reference.", assertEquals("This data type contains a circular reference.",
be.getMessage());
be.getMessage());
} }


// dummy1 --> dummy2 --> dummy3 --> dummy1 // dummy1 --> dummy2 --> dummy3 --> dummy1
@@ -118,7 +119,7 @@ public class MapperTest extends TestCase {
fail("Can make circular reference."); fail("Can make circular reference.");
} catch (BuildException be) { } catch (BuildException be) {
assertEquals("This data type contains a circular reference.", assertEquals("This data type contains a circular reference.",
be.getMessage());
be.getMessage());
} }


// dummy1 --> dummy2 --> dummy3 // dummy1 --> dummy2 --> dummy3
@@ -167,11 +168,11 @@ public class MapperTest extends TestCase {
assertEquals("wrong number of filenames mapped", 3, targets.length); assertEquals("wrong number of filenames mapped", 3, targets.length);
List list = Arrays.asList(targets); List list = Arrays.asList(targets);
assertTrue("cannot find expected target \"tofilename\"", assertTrue("cannot find expected target \"tofilename\"",
list.contains("tofilename"));
list.contains("tofilename"));
assertTrue("cannot find expected target \"fromfilename\"", assertTrue("cannot find expected target \"fromfilename\"",
list.contains("fromfilename"));
list.contains("fromfilename"));
assertTrue("cannot find expected target \"mergefile\"", assertTrue("cannot find expected target \"mergefile\"",
list.contains("mergefile"));
list.contains("mergefile"));
} }


public void testChained() { public void testChained() {
@@ -236,7 +237,11 @@ public class MapperTest extends TestCase {
} }


public void tearDown() { public void tearDown() {
executeTarget("cleanup");
try {
super.tearDown();
} catch (Exception exc) {
// ignore
}
} }


public void test1() { public void test1() {


Loading…
Cancel
Save