Author: bodewig
Date: Mon Jul 24 21:36:58 2006
New Revision: 425273
URL: http://svn.apache.org/viewvc?rev=425273&view=rev
Log:
fine tune resource collection support
Modified:
ant/antlibs/antunit/trunk/docs/antunit.html
ant/antlibs/antunit/trunk/src/etc/testcases/antunit.xml
ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java
ant/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AntUnitTest.java
Modified: ant/antlibs/antunit/trunk/docs/antunit.html
URL:
http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/docs/antunit.html?rev=425273&r1=425272&r2=425273&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/docs/antunit.html (original)
+++ ant/antlibs/antunit/trunk/docs/antunit.html Mon Jul 24 21:36:58 2006
@@ -1,3 +1,21 @@
+<!--
+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.
+-->
<html>
<head>
<meta http-equiv="Content-Language" content="en-us"></meta>
@@ -44,19 +62,22 @@
<pre>
/*
- * Copyright 2005 The Apache Software Foundation
+ * 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
*
- * Licensed 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.
+ * 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.
*
*/
@@ -97,10 +118,10 @@
<h3>Parameters specified as nested elements</h3>
- <h4>fileset - or a child type</h4>
+ <h4>any file system resource collection</h4>
<p>Specifies the build files to run as tests. At least one
- fileset is required.</p>
+ resource is required.</p>
<h4>any implementation of AntUnitListener</h4>
@@ -149,7 +170,7 @@
<pre>
<au:antunit>
- <fileset dir="antunit" includes="base.xml"/>
+ <file file="antunit/base.xml"/>
<au:plainlistener/>
</au:antunit>
</pre>
@@ -168,8 +189,5 @@
[au:antunit] Target: test2 took 0 sec
[au:antunit] Target: test1 took 0 sec
</pre>
-
- <hr/>
- <p align="center">Copyright © 2005 The Apache Software Foundation.
All rights Reserved.</p>
</body>
</html>
Modified: ant/antlibs/antunit/trunk/src/etc/testcases/antunit.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/antunit.xml?rev=425273&r1=425272&r2=425273&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/antunit.xml (original)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/antunit.xml Mon Jul 24 21:36:58
2006
@@ -27,8 +27,27 @@
<target name="antunit-basetest">
<au:antunit>
- <fileset dir="antunit" includes="base.xml"/>
+ <file file="antunit/base.xml"/>
<au:plainlistener/>
+ </au:antunit>
+ </target>
+
+ <target name="noTests">
+ <au:antunit/>
+ </target>
+
+ <target name="nonFile">
+ <au:antunit>
+ <url url="http://ant.apache.org/"/>
+ </au:antunit>
+ </target>
+
+ <target name="nonExistingFile">
+ <au:antunit failOnError="false">
+ <filelist dir="antunit">
+ <file name="base.xml"/>
+ <file name="I don't exist.xml"/>
+ </filelist>
</au:antunit>
</target>
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=425273&r1=425272&r2=425273&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 Mon
Jul 24 21:36:58 2006
@@ -36,6 +36,7 @@
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.LogOutputStream;
import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.types.resources.Union;
import org.apache.tools.ant.types.resources.FileResource;
/**
@@ -65,7 +66,7 @@
/**
* The build files to process.
*/
- private ArrayList filesets = new ArrayList();
+ private Union buildFiles = new Union();
/**
* project instance for the build file currently under test.
@@ -98,14 +99,20 @@
/**
* Message if no tests have been specified.
*/
- public static final String ERROR_NO_FILESET =
- "You must specify at least one nested fileset.";
+ public static final String ERROR_NO_TESTS =
+ "You must specify build files to test.";
+
+ /**
+ * Message if non-File resources have been specified.
+ */
+ public static final String ERROR_NON_FILES =
+ "Only file system resources are supported.";
/**
* adds build files to run as tests.
*/
public void add(ResourceCollection rc) {
- filesets.add(rc);
+ buildFiles.add(rc);
}
/**
@@ -123,13 +130,10 @@
}
public void execute() {
- if (filesets.size() == 0) {
- throw new BuildException(ERROR_NO_FILESET);
- }
- Iterator iter = filesets.iterator();
- while (iter.hasNext()) {
- doFileSet((ResourceCollection) iter.next());
+ if (buildFiles.size() == 0) {
+ throw new BuildException(ERROR_NO_TESTS);
}
+ doResourceCollection(buildFiles);
if (failOnError && (failures > 0 || errors > 0)) {
throw new BuildException(ERROR_TESTS_FAILED
+ failures + " failure" + (failures != 1 ? "s" : "")
@@ -139,12 +143,22 @@
}
/**
- * Processes a fileset.
+ * Processes a ResourceCollection.
*/
- private void doFileSet(ResourceCollection rc) {
+ private void doResourceCollection(ResourceCollection rc) {
+ if (!rc.isFilesystemOnly()) {
+ throw new BuildException(ERROR_NON_FILES);
+ }
+
Iterator i = rc.iterator();
while(i.hasNext()) {
- doFile(((FileResource)i.next()).getFile());
+ FileResource r = (FileResource) i.next();
+ if (r.isExists()) {
+ doFile(r.getFile());
+ } else {
+ log("Skipping " + r + " since it doesn't exist",
+ Project.MSG_VERBOSE);
+ }
}
}
@@ -152,6 +166,8 @@
* Processes a single build file.
*/
private void doFile(File f) {
+ log("Running tests in build file " + f, Project.MSG_DEBUG);
+
// setup project instance
newProject = new Project();
newProject.setDefaultInputStream(getProject().getDefaultInputStream());
Modified:
ant/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AntUnitTest.java
URL:
http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AntUnitTest.java?rev=425273&r1=425272&r2=425273&view=diff
==============================================================================
---
ant/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AntUnitTest.java
(original)
+++
ant/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AntUnitTest.java
Mon Jul 24 21:36:58 2006
@@ -62,4 +62,22 @@
&& log.indexOf("test4 fails", index2) > -1);
assertTrue("Only one failure", log.indexOf("FAILED", index2 + 1) ==
-1);
}
+
+ public void testNoTests() {
+ expectSpecificBuildException("noTests", "No tests have been specified",
+ AntUnit.ERROR_NO_TESTS);
+ }
+
+ public void testNonFile() {
+ expectSpecificBuildException("nonFile",
+ "URL has been specified",
+ AntUnit.ERROR_NON_FILES);
+ }
+
+ public void testNonExistingFile() {
+ executeTarget("nonExistingFile");
+ assertDebuglogContaining(java.io.File.separator
+ + "I don't exist.xml since it doesn't exist");
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]