You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ke...@apache.org on 2007/10/04 06:13:33 UTC
svn commit: r581771 - in /ant/antlibs/antunit/trunk: ./ src/etc/testcases/
src/etc/testcases/antunit/setupandteardown/
src/main/org/apache/ant/antunit/ src/tests/junit/org/apache/ant/antunit/
Author: kevj
Date: Wed Oct 3 21:13:24 2007
New Revision: 581771
URL: http://svn.apache.org/viewvc?rev=581771&view=rev
Log:
-bugzilla #43466
Added:
ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/
ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/both.xml
ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedsetup.xml
ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedteardown.xml
ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedtest.xml
ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/nosetup.xml
ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/noteardown.xml
ant/antlibs/antunit/trunk/src/etc/testcases/setupandteardown.xml
ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/SetUpAndTearDownTest.java
Modified:
ant/antlibs/antunit/trunk/contributors.xml
ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java
Modified: ant/antlibs/antunit/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/contributors.xml?rev=581771&r1=581770&r2=581771&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/contributors.xml (original)
+++ ant/antlibs/antunit/trunk/contributors.xml Wed Oct 3 21:13:24 2007
@@ -15,6 +15,10 @@
These are some of the many people who have helped with this Ant Library.
</introduction>
<name>
+ <first>David</first>
+ <last>Jackman</last>
+ </name>
+ <name>
<first>Jan</first>
<last>Matèrne</last>
</name>
Added: ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/both.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/both.xml?rev=581771&view=auto
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/both.xml (added)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/both.xml Wed Oct 3 21:13:24 2007
@@ -0,0 +1,55 @@
+<?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 name="setup-and-teardown"
+ default="all"
+ xmlns:au="antlib:org.apache.ant.antunit">
+
+ <target name="all">
+ <fail message="These are not standalone tests." />
+ </target>
+
+ <target name="setUp">
+ <fail message="outputfile property is not set." unless="outputfile" />
+ <echo file="${outputfile}" append="true" message="S" />
+ </target>
+
+ <target name="test1">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+ <target name="test2">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+ <target name="test3">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+ <target name="test4">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+ <target name="tearDown">
+ <echo file="${outputfile}" append="true" message="T" />
+ </target>
+
+</project>
Added: ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedsetup.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedsetup.xml?rev=581771&view=auto
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedsetup.xml (added)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedsetup.xml Wed Oct 3 21:13:24 2007
@@ -0,0 +1,43 @@
+<?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 name="failed-test"
+ default="all"
+ xmlns:au="antlib:org.apache.ant.antunit">
+
+ <target name="all">
+ <fail message="These are not standalone tests." />
+ </target>
+
+ <target name="setUp">
+ <echo file="${outputfile}" append="true" message="S" />
+ <fail message="Expected failure" />
+ </target>
+
+ <target name="test1">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+ <target name="tearDown">
+ <echo file="${outputfile}" append="true" message="T" />
+ </target>
+
+</project>
Added: ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedteardown.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedteardown.xml?rev=581771&view=auto
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedteardown.xml (added)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedteardown.xml Wed Oct 3 21:13:24 2007
@@ -0,0 +1,43 @@
+<?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 name="failed-test"
+ default="all"
+ xmlns:au="antlib:org.apache.ant.antunit">
+
+ <target name="all">
+ <fail message="These are not standalone tests." />
+ </target>
+
+ <target name="setUp">
+ <echo file="${outputfile}" append="true" message="S" />
+ </target>
+
+ <target name="test1">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+ <target name="tearDown">
+ <echo file="${outputfile}" append="true" message="T" />
+ <fail message="Expected failure" />
+ </target>
+
+</project>
Added: ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedtest.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedtest.xml?rev=581771&view=auto
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedtest.xml (added)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/failedtest.xml Wed Oct 3 21:13:24 2007
@@ -0,0 +1,44 @@
+<?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 name="failed-test"
+ default="all"
+ xmlns:au="antlib:org.apache.ant.antunit">
+
+ <target name="all">
+ <fail message="These are not standalone tests." />
+ </target>
+
+ <target name="setUp">
+ <fail message="outputfile property is not set." unless="outputfile" />
+ <echo file="${outputfile}" append="true" message="S" />
+ </target>
+
+ <target name="test1">
+ <echo file="${outputfile}" append="true" message="E" />
+ <fail message="Expected failure" />
+ </target>
+
+ <target name="tearDown">
+ <echo file="${outputfile}" append="true" message="T" />
+ </target>
+
+</project>
Added: ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/nosetup.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/nosetup.xml?rev=581771&view=auto
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/nosetup.xml (added)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/nosetup.xml Wed Oct 3 21:13:24 2007
@@ -0,0 +1,50 @@
+<?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 name="no-setup"
+ default="all"
+ xmlns:au="antlib:org.apache.ant.antunit">
+
+ <target name="all">
+ <fail message="These are not standalone tests." />
+ </target>
+
+ <target name="test1">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+ <target name="test2">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+ <target name="test3">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+ <target name="test4">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+ <target name="tearDown">
+ <echo file="${outputfile}" append="true" message="T" />
+ </target>
+
+</project>
Added: ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/noteardown.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/noteardown.xml?rev=581771&view=auto
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/noteardown.xml (added)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/antunit/setupandteardown/noteardown.xml Wed Oct 3 21:13:24 2007
@@ -0,0 +1,51 @@
+<?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 name="no-teardown"
+ default="all"
+ xmlns:au="antlib:org.apache.ant.antunit">
+
+ <target name="all">
+ <fail message="These are not standalone tests." />
+ </target>
+
+ <target name="setUp">
+ <fail message="outputfile property is not set." unless="outputfile" />
+ <echo file="${outputfile}" append="true" message="S" />
+ </target>
+
+ <target name="test1">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+ <target name="test2">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+ <target name="test3">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+ <target name="test4">
+ <echo file="${outputfile}" append="true" message="E" />
+ </target>
+
+</project>
Added: ant/antlibs/antunit/trunk/src/etc/testcases/setupandteardown.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/setupandteardown.xml?rev=581771&view=auto
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/setupandteardown.xml (added)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/setupandteardown.xml Wed Oct 3 21:13:24 2007
@@ -0,0 +1,119 @@
+<?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 name="setupandteardown-test"
+ default="all"
+ xmlns:au="antlib:org.apache.ant.antunit">
+
+ <target name="all">
+ <au:antunit>
+ <file file="${ant.file}" />
+ <au:plainlistener/>
+ </au:antunit>
+ </target>
+
+ <!-- Verifies that both setup and teardown are called for each test -->
+ <target name="testBoth">
+ <tempfile property="outputfile" deleteonexit="true" />
+ <au:antunit>
+ <file file="antunit/setupandteardown/both.xml" />
+ <propertyset>
+ <propertyref name="outputfile" />
+ </propertyset>
+ </au:antunit>
+ <au:assertFileExists file="${outputfile}" message="Output file doesn't exist" />
+ <loadfile property="output" srcFile="${outputfile}" />
+ <au:assertEquals expected="SETSETSETSET" actual="${output}" />
+ </target>
+
+ <!-- Tests no setup -->
+ <target name="testNoSetup">
+ <tempfile property="outputfile" deleteonexit="true" />
+ <au:antunit>
+ <file file="antunit/setupandteardown/nosetup.xml" />
+ <propertyset>
+ <propertyref name="outputfile" />
+ </propertyset>
+ </au:antunit>
+ <au:assertFileExists file="${outputfile}" message="Output file doesn't exist" />
+ <loadfile property="output" srcFile="${outputfile}" />
+ <au:assertEquals expected="ETETETET" actual="${output}" />
+ </target>
+
+ <!-- Tests no teardown -->
+ <target name="testNoTeardown">
+ <tempfile property="outputfile" deleteonexit="true" />
+ <au:antunit>
+ <file file="antunit/setupandteardown/noteardown.xml" />
+ <propertyset>
+ <propertyref name="outputfile" />
+ </propertyset>
+ </au:antunit>
+ <au:assertFileExists file="${outputfile}" message="Output file doesn't exist" />
+ <loadfile property="output" srcFile="${outputfile}" />
+ <au:assertEquals expected="SESESESE" actual="${output}" />
+ </target>
+
+ <!-- Verifies teardown is called for a failed test -->
+ <target name="testFailedTest">
+ <tempfile property="outputfile" deleteonexit="true" />
+ <au:antunit failOnError="false" errorProperty="failure">
+ <file file="antunit/setupandteardown/failedtest.xml" />
+ <propertyset>
+ <propertyref name="outputfile" />
+ </propertyset>
+ </au:antunit>
+ <fail unless="failure" message="Test should have failed." />
+ <au:assertFileExists file="${outputfile}" message="Output file doesn't exist" />
+ <loadfile property="output" srcFile="${outputfile}" />
+ <au:assertEquals expected="SET" actual="${output}" />
+ </target>
+
+ <!-- Tests a failure in setup -->
+ <target name="testFailedSetup">
+ <tempfile property="outputfile" deleteonexit="true" />
+ <au:antunit failOnError="false" errorProperty="failure">
+ <file file="antunit/setupandteardown/failedsetup.xml" />
+ <propertyset>
+ <propertyref name="outputfile" />
+ </propertyset>
+ </au:antunit>
+ <fail unless="failure" message="Test should have failed." />
+ <au:assertFileExists file="${outputfile}" message="Output file doesn't exist" />
+ <loadfile property="output" srcFile="${outputfile}" />
+ <au:assertEquals expected="ST" actual="${output}" />
+ </target>
+
+ <!-- Tests a failure in teardown -->
+ <target name="testFailedTeardown">
+ <tempfile property="outputfile" deleteonexit="true" />
+ <au:antunit failOnError="false" errorProperty="failure">
+ <file file="antunit/setupandteardown/failedteardown.xml" />
+ <propertyset>
+ <propertyref name="outputfile" />
+ </propertyset>
+ </au:antunit>
+ <fail unless="failure" message="Test should have failed." />
+ <au:assertFileExists file="${outputfile}" message="Output file doesn't exist" />
+ <loadfile property="output" srcFile="${outputfile}" />
+ <au:assertEquals expected="SET" actual="${output}" />
+ </target>
+
+</project>
Modified: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java?rev=581771&r1=581770&r2=581771&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java (original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java Wed Oct 3 21:13:24 2007
@@ -274,7 +274,30 @@
fireEndTest(name);
// clean up
if (tearDown) {
- newProject.executeTarget(TEARDOWN);
+ try {
+ newProject.executeTarget(TEARDOWN);
+ } catch (final AssertionFailedException e) {
+ fireFail(name, e);
+ } catch (final BuildException e) {
+ boolean failed = false;
+
+ // try to see whether the BuildException masks
+ // an AssertionFailedException. If so, treat
+ // it as failure instead of error.
+ Throwable t = e.getCause();
+ while (t != null && t instanceof BuildException) {
+ if (t instanceof AssertionFailedException) {
+ failed = true;
+ fireFail(name, (AssertionFailedException) t);
+ break;
+ }
+ t = ((BuildException) t).getCause();
+ }
+
+ if (!failed) {
+ fireError(name, e);
+ }
+ }
}
if (iter.hasNext()) {
newProject = createProjectForFile(f);
Added: ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/SetUpAndTearDownTest.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/SetUpAndTearDownTest.java?rev=581771&view=auto
==============================================================================
--- ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/SetUpAndTearDownTest.java (added)
+++ ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/SetUpAndTearDownTest.java Wed Oct 3 21:13:24 2007
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.ant.antunit;
+
+import org.apache.tools.ant.BuildFileTest;
+
+public class SetUpAndTearDownTest extends BuildFileTest {
+
+ public SetUpAndTearDownTest(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ configureProject("src/etc/testcases/setupandteardown.xml");
+ }
+
+
+ public void testBoth() {
+ executeTarget("testBoth");
+ }
+
+ public void testNoSetup() {
+ executeTarget("testNoSetup");
+ }
+
+ public void testNoTeardown() {
+ executeTarget("testNoTeardown");
+ }
+
+ public void testFailedTest() {
+ executeTarget("testFailedTest");
+ }
+
+ public void testFailedSetup() {
+ executeTarget("testFailedSetup");
+ }
+
+ public void testFailedTeardown() {
+ executeTarget("testFailedTeardown");
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org