You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by st...@apache.org on 2009/02/18 09:43:51 UTC
svn commit: r745433 - in /ant/core/trunk/src:
main/org/apache/tools/ant/taskdefs/optional/testing/Funtest.java
tests/antunit/taskdefs/optional/funtest-test.xml
Author: stevel
Date: Wed Feb 18 08:43:51 2009
New Revision: 745433
URL: http://svn.apache.org/viewvc?rev=745433&view=rev
Log:
starting the tests for this, fixing the code as the problems show up. Task is not yet ready for use.
Added:
ant/core/trunk/src/tests/antunit/taskdefs/optional/funtest-test.xml
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/testing/Funtest.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/testing/Funtest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/testing/Funtest.java?rev=745433&r1=745432&r2=745433&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/testing/Funtest.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/testing/Funtest.java Wed Feb 18 08:43:51 2009
@@ -24,6 +24,7 @@
import org.apache.tools.ant.TaskAdapter;
import org.apache.tools.ant.util.WorkerAnt;
import org.apache.tools.ant.taskdefs.condition.Condition;
+import org.apache.tools.ant.taskdefs.condition.ConditionBase;
import org.apache.tools.ant.taskdefs.Parallel;
import org.apache.tools.ant.taskdefs.Sequential;
import org.apache.tools.ant.taskdefs.WaitFor;
@@ -63,7 +64,8 @@
* easier to define complex tests that only
* run if certain conditions are met, such as OS or network state.
*/
- private Condition condition;
+
+ private NestedCondition condition;
/**
@@ -165,9 +167,9 @@
/** {@value} */
public static final String SKIPPING_TESTS
= "Condition failed -skipping tests";
- /** Application exception */
+ /** Application exception : {@value} */
public static final String APPLICATION_EXCEPTION = "Application Exception";
- /** Teardown exception */
+ /** Teardown exception : {@value} */
public static final String TEARDOWN_EXCEPTION = "Teardown Exception";
/**
@@ -178,17 +180,19 @@
*/
private void logOverride(String name, Object definition) {
if (definition != null) {
- log(WARN_OVERRIDING + '<' + name + '>', Project.MSG_WARN);
+ log(WARN_OVERRIDING + '<' + name + '>', Project.MSG_INFO);
}
}
/**
- * Add a condition.
- * @param newCondition the condition to add.
- */
- public void addCondition(Condition newCondition) {
+ * Add a condition element.
+ * @return <code>ConditionBase</code>.
+ * @since Ant 1.6.2
+ */
+ public ConditionBase createCondition() {
logOverride("condition", condition);
- condition = newCondition;
+ condition = new NestedCondition();
+ return condition;
}
/**
@@ -369,6 +373,17 @@
}
/**
+ * Add any task validation needed to ensure internal code quality
+ * @param task task
+ * @param role role of the task
+ */
+ private void validateTask(Task task, String role) {
+ if (task!=null && task.getProject() == null) {
+ throw new BuildException(role + " task is not bound to the project" + task);
+ }
+ }
+
+ /**
* Run the functional test sequence.
* <p/>
* This is a fairly complex workflow -what is going on is that we try to clean up
@@ -379,7 +394,14 @@
*/
public void execute() throws BuildException {
- //before anything else, check the condition
+ //validation
+ validateTask(setup, "setup");
+ validateTask(application, "application");
+ validateTask(tests, "tests");
+ validateTask(reporting, "reporting");
+ validateTask(teardown, "teardown");
+
+ //check the condition
//and bail out if it is defined but not true
if (condition != null && !condition.eval()) {
//we are skipping the test
@@ -403,7 +425,10 @@
bind(testRun);
if (block != null) {
//waitfor is not a task, it needs to be adapted
- testRun.addTask(new TaskAdapter(block));
+ TaskAdapter ta = new TaskAdapter(block);
+ ta.bindToOwner(this);
+ validateTask(ta, "block");
+ testRun.addTask(ta);
//add the block time to the total test run timeout
testRunTimeout = block.calculateMaxWaitMillis();
}
@@ -539,4 +564,14 @@
thrown,
Project.MSG_WARN);
}
+
+ private static class NestedCondition extends ConditionBase implements Condition {
+ public boolean eval() {
+ if (countConditions() != 1) {
+ throw new BuildException(
+ "A single nested condition is required.");
+ }
+ return ((Condition) (getConditions().nextElement())).eval();
+ }
+ }
}
Added: ant/core/trunk/src/tests/antunit/taskdefs/optional/funtest-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/optional/funtest-test.xml?rev=745433&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/optional/funtest-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/optional/funtest-test.xml Wed Feb 18 08:43:51 2009
@@ -0,0 +1,124 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
+ <import file="../../antunit-base.xml"/>
+
+ <!-- three presets for state-->
+ <presetdef name="p1">
+ <property name="p1" value="true"/>
+ </presetdef>
+ <presetdef name="p2">
+ <property name="p2" value="true"/>
+ </presetdef>
+ <presetdef name="p3">
+ <property name="p3" value="true"/>
+ </presetdef>
+ <presetdef name="p4">
+ <property name="p4" value="true"/>
+ </presetdef>
+ <presetdef name="p5">
+ <property name="p5" value="true"/>
+ </presetdef>
+
+ <presetdef name="assertP1">
+ <au:assertPropertySet name="p1"/>
+ </presetdef>
+ <presetdef name="assertP2">
+ <au:assertPropertySet name="p2"/>
+ </presetdef>
+ <presetdef name="assertP3">
+ <au:assertPropertySet name="p3"/>
+ </presetdef>
+ <presetdef name="assertP4">
+ <au:assertPropertySet name="p4"/>
+ </presetdef>
+ <presetdef name="assertP5">
+ <au:assertPropertySet name="p5"/>
+ </presetdef>
+
+
+ <target name="testPresets"
+ description="test the presets behave">
+ <p1/>
+ <assertP1/>
+ <p2/>
+ <assertP2/>
+ <p3/>
+ <assertP3/>
+ <p4/>
+ <assertP4/>
+ <p5/>
+ <assertP5/>
+ </target>
+
+ <target name="testToSuccess">
+ <funtest>
+ <setup>
+ <p1/>
+ </setup>
+ <application>
+ <assertP1/>
+ <p2/>
+ </application>
+ <block>
+ <isset property="p2"/>
+ </block>
+ <tests>
+ <assertP1/>
+ <assertP2/>
+ <p3/>
+ </tests>
+ <reporting>
+ <assertP3/>
+ <p4/>
+ </reporting>
+ <teardown>
+ <assertP4/>
+ <p5/>
+ </teardown>
+ </funtest>
+ <assertP5/>
+ </target>
+
+ <target name="testCondition">
+ <funtest >
+ <condition>
+ <isset property="unset"/>
+ </condition>
+ <setup>
+ <fail>should not be reached</fail>
+ </setup>
+ </funtest>
+ </target>
+
+ <target name="testSetupFailureSkipsTeardown">
+ <au:expectfailure message="setup failed">
+ <funtest>
+ <setup>
+ <p1/>
+ <fail>setup failed</fail>
+ </setup>
+ <teardown>
+ <p5/>
+ </teardown>
+ </funtest>
+ </au:expectfailure>
+ <assertP1/>
+ </target>
+
+</project>