Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 18694 invoked from network); 2 Mar 2002 06:24:17 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 2 Mar 2002 06:24:17 -0000 Received: (qmail 29358 invoked by uid 97); 2 Mar 2002 06:24:23 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 29300 invoked by uid 97); 2 Mar 2002 06:24:22 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 29289 invoked by uid 97); 2 Mar 2002 06:24:22 -0000 Date: 2 Mar 2002 06:24:10 -0000 Message-ID: <20020302062410.24840.qmail@icarus.apache.org> From: adammurdoch@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/proposal/myrmidon/etc/testcases/org/apache/antlib/core if.ant X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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: 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 task. * * @author Adam Murdoch * @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 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 Peter Donald - * @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 =================================================================== test-prop is set test-prop is not set test-prop is set test-prop is not set test-prop is set test-prop is not set test-prop is set test-prop is not set task 1 task 2 task 3 task 4 no go no go -- To unsubscribe, e-mail: For additional commands, e-mail: