Browse Source

starting the tests for this, fixing the code as the problems show up. Task is not yet ready for use.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@745433 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 16 years ago
parent
commit
8d0bd81aae
2 changed files with 170 additions and 11 deletions
  1. +46
    -11
      src/main/org/apache/tools/ant/taskdefs/optional/testing/Funtest.java
  2. +124
    -0
      src/tests/antunit/taskdefs/optional/funtest-test.xml

+ 46
- 11
src/main/org/apache/tools/ant/taskdefs/optional/testing/Funtest.java View File

@@ -24,6 +24,7 @@ import org.apache.tools.ant.BuildException;
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 @@ public class Funtest extends Task {
* 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 @@ public class Funtest extends Task {
/** {@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 @@ public class Funtest extends Task {
*/
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;
}

/**
@@ -368,6 +372,17 @@ public class Funtest extends Task {
return par;
}

/**
* 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/>
@@ -379,7 +394,14 @@ public class Funtest extends Task {
*/
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 @@ public class Funtest extends Task {
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 @@ public class Funtest extends Task {
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();
}
}
}

+ 124
- 0
src/tests/antunit/taskdefs/optional/funtest-test.xml View File

@@ -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>

Loading…
Cancel
Save