You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2011/01/25 10:29:02 UTC

svn commit: r1063181 - in /ant/antlibs/antunit/trunk: ./ docs/ src/etc/testcases/ src/main/org/apache/ant/antunit/ src/tests/junit/org/apache/ant/antunit/

Author: bodewig
Date: Tue Jan 25 09:29:02 2011
New Revision: 1063181

URL: http://svn.apache.org/viewvc?rev=1063181&view=rev
Log:
new assertResourceExists and assertResourceDoesntExist conditions

Added:
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ResourceExists.java   (with props)
Modified:
    ant/antlibs/antunit/trunk/NOTICE
    ant/antlibs/antunit/trunk/changes.xml
    ant/antlibs/antunit/trunk/docs/assertions.html
    ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml
    ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java

Modified: ant/antlibs/antunit/trunk/NOTICE
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/NOTICE?rev=1063181&r1=1063180&r2=1063181&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/NOTICE (original)
+++ ant/antlibs/antunit/trunk/NOTICE Tue Jan 25 09:29:02 2011
@@ -1,5 +1,5 @@
    Apache AntUnit
-   Copyright 2005-2007 The Apache Software Foundation
+   Copyright 2005-2011 The Apache Software Foundation
 
    This product includes software developed by
    The Apache Software Foundation (http://www.apache.org/).

Modified: ant/antlibs/antunit/trunk/changes.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/changes.xml?rev=1063181&r1=1063180&r2=1063181&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/changes.xml (original)
+++ ant/antlibs/antunit/trunk/changes.xml Tue Jan 25 09:29:02 2011
@@ -38,6 +38,10 @@
   </properties>
 
   <release version="1.2" date="not-released">
+    <action type="add">
+      New assertion assertResourceExists and assertResourceDoesntExist
+      have been added.
+    </action>
     <action type="fix" breaks-bwc="true">
       The XSLT stylesheets now create HTML files instead of plain text
       for logs sent to System.err and System.out.  You can always get

Modified: ant/antlibs/antunit/trunk/docs/assertions.html
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/docs/assertions.html?rev=1063181&r1=1063180&r2=1063181&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/docs/assertions.html (original)
+++ ant/antlibs/antunit/trunk/docs/assertions.html Tue Jan 25 09:29:02 2011
@@ -285,6 +285,80 @@
       &lt;assertFileDoesntExist file="${ant.home}/lib/ant.jar"/&gt;
     </pre>
 
+    <h2><a name="assertResourceExists">assertResourceExists</a></h2>
+
+    <p><em>Since AntUnit 1.2</em></p>
+
+    <p>Asserts that a given resource exists.  This is a
+      generalization of assertFileExists and allows to test for
+      arbitrary resources.</p>
+
+    <table border="1" cellpadding="2" cellspacing="0">
+        <tr>
+          <td valign="top"><b>Attribute</b></td>
+          <td valign="top"><b>Description</b></td>
+          <td align="center" valign="top"><b>Required</b></td>
+        </tr>
+        <tr>
+          <td valign="top">resource</td>
+          <td valign="top">Location of the resource.</td>
+          <td valign="top" align="center">Yes</td>
+        </tr>
+        <tr>
+          <td valign="top">message</td>
+          <td valign="top">Message for the exception if the condition
+            doesn't hold true.  Defaults to "Expected
+            resource '<em>resource</em>' to exist".</td>
+          <td align="center">No.</td>
+        </tr>
+    </table>
+
+    <h3>Examples</h3>
+
+    <p>Make the build fail if the resource ${ant.home}/lib/ant.jar doesn't
+      exist:</p>
+
+    <pre>
+      &lt;assertResourceExists resource="${ant.home}/lib/ant.jar"/&gt;
+    </pre>
+
+    <h2><a name="assertResourceDoesntExist">assertResourceDoesntExist</a></h2>
+
+    <p><em>Since AntUnit 1.2</em></p>
+
+    <p>Asserts that a given resource does not exist.  This is a
+      generalization of assertFileDoesntExist and allows to test for
+      arbitrary resources.</p>
+
+    <table border="1" cellpadding="2" cellspacing="0">
+        <tr>
+          <td valign="top"><b>Attribute</b></td>
+          <td valign="top"><b>Description</b></td>
+          <td align="center" valign="top"><b>Required</b></td>
+        </tr>
+        <tr>
+          <td valign="top">resource</td>
+          <td valign="top">Location of the resource.</td>
+          <td valign="top" align="center">Yes</td>
+        </tr>
+        <tr>
+          <td valign="top">message</td>
+          <td valign="top">Message for the exception if the condition
+            doesn't hold true.  Defaults to "Didn't expect
+            resource '<em>resource</em>' to exist".</td>
+          <td align="center">No.</td>
+        </tr>
+    </table>
+
+    <h3>Examples</h3>
+
+    <p>Make the build fail if the resource ${ant.home}/lib/ant.jar
+      exists:</p>
+
+    <pre>
+      &lt;assertResourceDoesntExist resource="${ant.home}/lib/ant.jar"/&gt;
+    </pre>
+
     <h2><a name="assertDestIsUptodate">assertDestIsUptodate</a></h2>
 
     <p>Asserts that a dest file is more recent than the source

Modified: ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml?rev=1063181&r1=1063180&r2=1063181&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml (original)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml Tue Jan 25 09:29:02 2011
@@ -136,6 +136,22 @@ under the License.
     <au:assertFileDoesntExist file="assert.xml"/>
   </target>
 
+  <target name="assertResourceExistsPass">
+    <au:assertResourceExists resource="assert.xml"/>
+  </target>
+
+  <target name="assertResourceExistsFail">
+    <au:assertResourceExists resource="assert.txt"/>
+  </target>
+
+  <target name="assertResourceDoesntExistPass">
+    <au:assertResourceDoesntExist resource="assert.txt"/>
+  </target>
+
+  <target name="assertResourceDoesntExistFail">
+    <au:assertResourceDoesntExist resource="assert.xml"/>
+  </target>
+
   <target name="assertDestIsUptodatePass">
     <au:assertDestIsUptodate
       src="../../main/org/apache/ant/antunit/AssertTask.java"

Added: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ResourceExists.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ResourceExists.java?rev=1063181&view=auto
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ResourceExists.java (added)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ResourceExists.java Tue Jan 25 09:29:02 2011
@@ -0,0 +1,65 @@
+/*
+ * 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.BuildException;
+import org.apache.tools.ant.ProjectComponent;
+import org.apache.tools.ant.taskdefs.condition.Condition;
+import org.apache.tools.ant.types.Resource;
+
+/**
+ * A condition that tests whether a given resource exists.
+ *
+ * @since AntUnit 1.2
+ */
+public class ResourceExists extends ProjectComponent implements Condition {
+    private Resource resource;
+
+    /**
+     * The resource to check as attribute.
+     *
+     * <p>Exactly one resource must be specfied either as attribute or
+     * nested element.</p>
+     */
+    public void setResource(Resource r) {
+        if (resource != null) {
+            throw new BuildException("Only one resource can be tested.");
+        }
+        resource = r;
+    }
+
+    /**
+     * The resource to check as nested element.
+     *
+     * <p>Exactly one resource must be specfied either as attribute or
+     * nested element.</p>
+     */
+    public void add(Resource r) {
+        setResource(r);
+    }
+
+    public boolean eval() {
+        if (resource == null) {
+            throw new BuildException("You must specify a resource.");
+        }
+        return resource.isExists();
+    }
+}

Propchange: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ResourceExists.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml?rev=1063181&r1=1063180&r2=1063181&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml (original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml Tue Jan 25 09:29:02 2011
@@ -45,6 +45,9 @@ under the License.
   <typedef name="logcontent"
     classname="org.apache.ant.antunit.LogContent" />
 
+  <typedef name="resourcExists"
+    classname="org.apache.ant.antunit.ResourceExists"/>
+
   <!-- Actually just an alias of fail that expects a condition -->
   <macrodef name="assertTrue" backtrace="false">
     <attribute name="message" default="Assertion failed"/>
@@ -143,6 +146,28 @@ under the License.
     </sequential>
   </macrodef>
 
+  <macrodef name="assertResourceExists" backtrace="false">
+    <attribute name="resource"/>
+    <attribute name="message"
+      default="Expected resource '@{resource}' to exist"/>
+    <sequential>
+      <au:fail message="@{message}">
+        <au:resourceExists resource="@{resource}"/>
+      </au:fail>
+    </sequential>
+  </macrodef>
+
+  <macrodef name="assertResourceDoesntExist" backtrace="false">
+    <attribute name="resource"/>
+    <attribute name="message"
+      default="Didn't expect resource '@{resource}' to exist"/>
+    <sequential>
+      <au:assertFalse message="@{message}">
+        <au:resourceExists resource="@{resource}"/>
+      </au:assertFalse>
+    </sequential>
+  </macrodef>
+
   <macrodef name="assertResourceContains">
     <attribute name="resource"/>
     <attribute name="value"/>

Modified: ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java?rev=1063181&r1=1063180&r2=1063181&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java (original)
+++ ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java Tue Jan 25 09:29:02 2011
@@ -64,6 +64,12 @@ public class AssertTest extends BuildFil
     public void testFileDoesntExistPass() {
         testPass("assertFileDoesntExistPass");
     }
+    public void testResourceExistsPass() {
+        testPass("assertResourceExistsPass");
+    }
+    public void testResourceDoesntExistPass() {
+        testPass("assertResourceDoesntExistPass");
+    }
     public void testDestIsUptodatePass() {
         testPass("assertDestIsUptodatePass");
     }
@@ -121,6 +127,14 @@ public class AssertTest extends BuildFil
         testFail("assertFileDoesntExistFail",
                  "Didn't expect file 'assert.xml' to exist");
     }
+    public void testResourceExistsFail() {
+        testFail("assertResourceExistsFail",
+                 "Expected resource 'assert.txt' to exist");
+    }
+    public void testResourceDoesntExistFail() {
+        testFail("assertResourceDoesntExistFail",
+                 "Didn't expect resource 'assert.xml' to exist");
+    }
     public void testDestIsUptodateFail() {
         testFail("assertDestIsUptodateFail",
                  "Expected '../../main/org/apache/ant/antunit/AssertTask.java' to be more recent than '../../../build/classes/org/apache/ant/antunit/AssertTask.class'");



Re: ResourceExists condition

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-01-25, Matt Benson wrote:

> On Jan 25, 2011, at 4:25 AM, Stefan Bodewig wrote:

>> On 2011-01-25, <bo...@apache.org> wrote:

>>> Added:
>>>    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ResourceExists.java   (with props)

>> This is a plain ant condition with no dependency on AntUnit that might
>> be useful in core Ant as well.


> Shorthand for

> <resourcecount count="1">
>   <restrict>
>     <exists>
>       <resource refid="myresource" />
>     </exists>
>   </restrict>
> </resourcecount>

> ?  ;)

Only that the resource can be specified as attribute (which implies
property helper syntax) and is likely a bit more efficient.  Other than
that, yes 8-)

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: ResourceExists condition (was Re: svn commit: r1063181 - in /ant/antlibs/antunit/trunk: ./ docs/ src/etc/testcases/ src/main/org/apache/ant/antunit/ src/tests/junit/org/apache/ant/antunit/)

Posted by Matt Benson <gu...@gmail.com>.
On Jan 25, 2011, at 4:25 AM, Stefan Bodewig wrote:

> On 2011-01-25, <bo...@apache.org> wrote:
> 
>> Added:
>>    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ResourceExists.java   (with props)
> 
> This is a plain ant condition with no dependency on AntUnit that might
> be useful in core Ant as well.
> 

Shorthand for

<resourcecount count="1">
  <restrict>
    <exists>
      <resource refid="myresource" />
    </exists>
  </restrict>
</resourcecount>

?  ;)

-Matt

> I added it to AntUnit rather than Ant's trunk so that we can release
> AntUnit (if we ever want to) without having to release Ant first.
> 
> Stefan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


ResourceExists condition (was Re: svn commit: r1063181 - in /ant/antlibs/antunit/trunk: ./ docs/ src/etc/testcases/ src/main/org/apache/ant/antunit/ src/tests/junit/org/apache/ant/antunit/)

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-01-25, <bo...@apache.org> wrote:

> Added:
>     ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/ResourceExists.java   (with props)

This is a plain ant condition with no dependency on AntUnit that might
be useful in core Ant as well.

I added it to AntUnit rather than Ant's trunk so that we can release
AntUnit (if we ever want to) without having to release Ant first.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org