You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ad...@apache.org on 2002/03/02 07:24:10 UTC
cvs commit: jakarta-ant/proposal/myrmidon/etc/testcases/org/apache/antlib/core if.ant
adammurdoch 02/03/01 22:24:10
Modified: proposal/myrmidon/src/java/org/apache/antlib/core
IfTask.java
Added: proposal/myrmidon/src/testcases/org/apache/antlib/core
IfTest.java
proposal/myrmidon/etc/testcases/org/apache/antlib/core
if.ant
Log:
<if> wasn't checking its condition. Fixed, and added some test cases.
Revision Changes Path
1.1 jakarta-ant/proposal/myrmidon/src/testcases/org/apache/antlib/core/IfTest.java
Index: IfTest.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.antlib.core;
import java.io.File;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.AbstractProjectTest;
import org.apache.myrmidon.LogMessageTracker;
/**
* Test cases for the <if> task.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/03/02 06:24:09 $
*/
public class IfTest
extends AbstractProjectTest
{
private final static Resources REZ
= ResourceManager.getPackageResources( IfTest.class );
public IfTest( String name )
{
super( name );
}
/**
* Test checking whether a property is set and not 'false'.
*/
public void testConditions()
throws Exception
{
final File projectFile = getTestResource( "if.ant" );
// Test when property is set to 'true'
LogMessageTracker listener = new LogMessageTracker();
listener.addExpectedMessage( "true-prop", "test-prop is set" );
executeTarget( projectFile, "true-prop", listener );
// Test when property is set to a value other than 'true' or 'false'
listener = new LogMessageTracker();
listener.addExpectedMessage( "set-prop", "test-prop is set" );
executeTarget( projectFile, "set-prop", listener );
// Test when property is set to 'false'
listener = new LogMessageTracker();
listener.addExpectedMessage( "false-prop", "test-prop is not set" );
executeTarget( projectFile, "false-prop", listener );
// Test when property is not set
listener = new LogMessageTracker();
listener.addExpectedMessage( "not-set-prop", "test-prop is not set" );
executeTarget( projectFile, "not-set-prop", listener );
}
/**
* Tests that the <if> task can handle multiple nested tasks.
*/
public void testMultipleTasks() throws Exception
{
final File projectFile = getTestResource( "if.ant" );
// Test when property is not set
LogMessageTracker listener = new LogMessageTracker();
listener.addExpectedMessage( "multiple-nested-tasks", "task 1" );
listener.addExpectedMessage( "multiple-nested-tasks", "task 2" );
listener.addExpectedMessage( "multiple-nested-tasks", "task 3" );
listener.addExpectedMessage( "multiple-nested-tasks", "task 4" );
executeTarget( projectFile, "multiple-nested-tasks", listener );
}
/**
* Tests validation.
*/
public void testValidation() throws Exception
{
final File projectFile = getTestResource( "if.ant" );
// Check for missing condition
String message = REZ.getString( "if.no-condition.error" );
executeTargetExpectError( projectFile, "no-condition", message );
// Check for too many conditions
String[] messages =
{
null,
null,
REZ.getString( "if.ifelse-duplicate.error" )
};
executeTargetExpectError( projectFile, "too-many-conditions", messages );
}
}
1.3 +8 -1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/IfTask.java
Index: IfTask.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/IfTask.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- IfTask.java 9 Feb 2002 02:54:04 -0000 1.2
+++ IfTask.java 2 Mar 2002 06:24:09 -0000 1.3
@@ -22,7 +22,7 @@
* then it will execute the inner tasks, else it won't.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
- * @version $Revision: 1.2 $ $Date: 2002/02/09 02:54:04 $
+ * @version $Revision: 1.3 $ $Date: 2002/03/02 06:24:09 $
* @ant:task name="if"
*/
public class IfTask
@@ -74,9 +74,16 @@
throw new TaskException( message );
}
+ // Evaluate the condition
+ if( ! m_condition.evaluate( getContext() ) )
+ {
+ return;
+ }
+
final Configuration[] tasks =
(Configuration[])m_tasks.toArray( new Configuration[ m_tasks.size() ] );
+ // TODO - don't use getService()
final ExecutionFrame frame = (ExecutionFrame)getService( ExecutionFrame.class );
final Executor executor = (Executor)getService( Executor.class );
1.1 jakarta-ant/proposal/myrmidon/etc/testcases/org/apache/antlib/core/if.ant
Index: if.ant
===================================================================
<project version="2.0">
<target name="true-prop">
<property name="test-prop" value="true"/>
<if test="test-prop">
<log>test-prop is set</log>
</if>
<if not-test="test-prop">
<log>test-prop is not set</log>
</if>
</target>
<target name="set-prop">
<property name="test-prop" value="some value"/>
<if test="test-prop">
<log>test-prop is set</log>
</if>
<if not-test="test-prop">
<log>test-prop is not set</log>
</if>
</target>
<target name="not-set-prop">
<if test="test-prop">
<log>test-prop is set</log>
</if>
<if not-test="test-prop">
<log>test-prop is not set</log>
</if>
</target>
<target name="false-prop">
<property name="test-prop" value="false"/>
<if test="test-prop">
<log>test-prop is set</log>
</if>
<if not-test="test-prop">
<log>test-prop is not set</log>
</if>
</target>
<target name="multiple-nested-tasks">
<property name="test-prop" value="true"/>
<if test="test-prop">
<log>task 1</log>
<log>task 2</log>
<log>task 3</log>
<log>task 4</log>
</if>
</target>
<target name="no-condition">
<if>
<log>no go</log>
</if>
</target>
<target name="too-many-conditions">
<if test="test-prop" not-test="test-prop">
<log>no go</log>
</if>
</target>
</project>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>