Browse Source

lets test condition

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270747 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 23 years ago
parent
commit
51b5caf9a8
2 changed files with 437 additions and 0 deletions
  1. +219
    -0
      src/etc/testcases/taskdefs/condition.xml
  2. +218
    -0
      src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java

+ 219
- 0
src/etc/testcases/taskdefs/condition.xml View File

@@ -0,0 +1,219 @@
<?xml version="1.0"?>

<!-- test conditioning -->
<project name="condition-test" basedir="." default="test1">

<target name="basic">
<condition property="basic">
<equals arg1="a" arg2="a" />
</condition>
<echo>${basic}</echo>
</target>

<target name="condition-incomplete">
<condition >
<equals arg1="a" arg2="a" />
</condition>
</target>

<target name="condition-empty">
<condition property="condition-empty"/>
<echo>${condition-empty}</echo>
</target>
<target name="shortcut">
<property name="shortcut" value="set"/>
<condition property="shortcut">
<equals arg1="a" arg2="a" />
</condition>
<echo>${shortcut}</echo>
</target>

<target name="dontset">
<condition property="dontset">
<equals arg1="a" arg2="b" />
</condition>
<echo>${dontset}</echo>
</target>

<target name="setvalue">
<condition property="setvalue" value="woowoo" >
<equals arg1="a" arg2="a" />
</condition>
<echo>${setvalue}</echo>
</target>

<target name="negation">
<condition property="negation">
<not>
<equals arg1="a" arg2="B" />
</not>
</condition>
<echo>${negation}</echo>
</target>
<target name="negationfalse">
<condition property="negationfalse">
<not>
<equals arg1="a" arg2="a" />
</not>
</condition>
<echo>${negationfalse}</echo>
</target>
<target name="negationincomplete">
<condition property="negationincomplete">
<not />
</condition>
<echo>${negationincomplete}</echo>
</target>
<target name="and">
<condition property="and">
<and>
<equals arg1="a" arg2="a" />
<equals arg1="B" arg2="B" />
</and>
</condition>
<echo>${and}</echo>
</target>

<target name="andfails">
<condition property="andfails">
<and>
<equals arg1="a" arg2="B" />
<equals arg1="B" arg2="a" />
</and>
</condition>
<echo>${andfails}</echo>
</target>
<target name="andincomplete">
<condition property="andincomplete">
<and>
<equals arg1="a" arg2="B" />
</and>
</condition>
<echo>${andincomplete}</echo>
</target>
<target name="andempty">
<condition property="andempty">
<and/>
</condition>
<echo>${andempty}</echo>
</target>
<target name="or">
<condition property="or">
<or>
<equals arg1="a" arg2="B" />
<equals arg1="B" arg2="B" />
</or>
</condition>
<echo>${or}</echo>
</target>
<target name="orincomplete">
<condition property="orincomplete">
<or>
<equals arg1="a" arg2="a" />
</or>
</condition>
<echo>${orincomplete}</echo>
</target>
<target name="orempty">
<condition property="orempty">
<or/>
</condition>
<echo>${orempty}</echo>
</target>
<target name="orfails">
<condition property="orfails">
<or>
<equals arg1="a" arg2="B" />
<equals arg1="B" arg2="a" />
</or>
</condition>
<echo>${orfails}</echo>
</target>

<target name="orboth">
<condition property="orboth">
<or>
<equals arg1="a" arg2="a" />
<equals arg1="B" arg2="B" />
</or>
</condition>
<echo>${orboth}</echo>
</target>
<target name="filesmatch-identical" >
<condition property="filesmatch-identical">
<filesmatch
file1="condition.xml"
file2="condition.xml" />
</condition>
<echo>${filesmatch-identical}</echo>
</target>
<target name="filesmatch-incomplete" >
<condition property="filesmatch-incomplete">
<filesmatch
file1="condition.xml"/>
</condition>
<echo>${filesmatch-incomplete}</echo>
</target>
<target name="filesmatch-oddsizes" >
<condition property="filesmatch-oddsizes">
<filesmatch
file1="condition.xml"
file2="property.xml" />
</condition>
<echo>${filesmatch-oddsizes}</echo>
</target>

<target name="filesmatch-existence" >
<condition property="filesmatch-existence">
<filesmatch
file1="condition.xml"
file2="this-file-doesnt-exist.xml" />
</condition>
<echo>${filesmatch-existence}</echo>
</target>

<target name="filesmatch-different">
<echo file="match1.txt" message="012345676890" />
<echo file="match2.txt" message="012345676889" />
<condition property="filesmatch-different">
<filesmatch
file1="match1.txt"
file2="match2.txt" />
</condition>
<echo>${filesmatch-different}</echo>
</target>
<target name="filesmatch-match" >
<echo file="match3.txt" message="012345676890" />
<echo file="match4.txt" message="012345676890" />
<condition property="filesmatch-match">
<filesmatch
file1="match3.txt"
file2="match4.txt" />
</condition>
<echo>${filesmatch-match}</echo>
</target>
<target name="cleanup" >
<delete file="match1.txt" />
<delete file="match2.txt" />
<delete file="match3.txt" />
<delete file="match4.txt" />
</target>
</project>

+ 218
- 0
src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java View File

@@ -0,0 +1,218 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 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;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileTest;
import java.lang.reflect.InvocationTargetException;

/**
* @author steve_l
* @created 13 January 2002
*/
public class ConditionTest extends BuildFileTest {

/**
* Constructor for the ConditionTest object
*
* @param name we dont know
*/
public ConditionTest(String name) {
super(name);
}


/**
* The JUnit setup method
*/
public void setUp() {
configureProject("src/etc/testcases/taskdefs/condition.xml");
}


/**
* The teardown method for JUnit
*/
public void tearDown() {
executeTarget("cleanup");
}

public void testBasic() {
expectPropertySet("basic","basic");
}

/**
* @todo have this reject the current error
*/
public void testConditionIncomplete() {
try {
executeTarget("condition-incomplete");
} catch(Exception e) {
}
}
/**
* @todo have this reject the current error
*/
public void testConditionEmpty() {
try {
executeTarget("condition-empty");
} catch(Exception e) {
}
}

public void testShortcut() {
expectPropertySet("shortcut","shortcut","set");
}
public void testUnset() {
expectPropertyUnset("dontset","dontset");
}
public void testSetValue() {
expectPropertySet("setvalue","setvalue","woowoo");
}
public void testNegation() {
expectPropertySet("negation","negation");
}
public void testNegationFalse() {
expectPropertyUnset("negationfalse","negationfalse");
}
/**
* @todo have this reject the current error
*/
public void testNegationIncomplete() {
try {
executeTarget("negationincomplete");
} catch(Exception e) {
}
}
public void testAnd() {
expectPropertySet("and","and");
}
public void testAndFails() {
expectPropertyUnset("andfails","andfails");
}
public void testAndIncomplete() {
expectPropertyUnset("andincomplete","andincomplete");
}

public void testAndempty() {
expectPropertySet("andempty","andempty");
}
public void testOr() {
expectPropertySet("or","or");
}

public void testOrincomplete() {
expectPropertySet("or","or");
}
public void testOrFails() {
expectPropertyUnset("orfails","orfails");
}
public void testOrboth() {
expectPropertySet("orboth","orboth");
}

public void testFilesmatchIdentical() {
expectPropertySet("filesmatch-identical","filesmatch-identical");
}
/**
* @todo have this reject the current error
*/
public void testFilesmatchIncomplete() {
try {
executeTarget("filesmatch-incomplete");
} catch(Exception e) {
}
}
public void testFilesmatchOddsizes() {
expectPropertyUnset("filesmatch-oddsizes","filesmatch-oddsizes");
}
/**
* @todo have this reject the current error
*/
public void testFilesmatchExistence() {
try {
executeTarget("filesmatch-existence");
} catch(Exception e) {
}
}

/**
* @todo have this reject the current error
*/
public void testFilesmatchDifferent() {
expectPropertyUnset("filesmatch-different","filesmatch-different");
}
public void testFilesmatchMatch() {
expectPropertySet("filesmatch-match","filesmatch-match");
}
}


Loading…
Cancel
Save