diff --git a/docs/antunit.html b/docs/antunit.html index 5c115df..5d23447 100644 --- a/docs/antunit.html +++ b/docs/antunit.html @@ -1,3 +1,21 @@ + @@ -44,19 +62,22 @@
 /*
- * 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 @@ public class LogCapturer {
 
     

Parameters specified as nested elements

-

fileset - or a child type

+

any file system resource collection

Specifies the build files to run as tests. At least one - fileset is required.

+ resource is required.

any implementation of AntUnitListener

@@ -149,7 +170,7 @@ public class LogCapturer {
     <au:antunit>
-      <fileset dir="antunit" includes="base.xml"/>
+      <file file="antunit/base.xml"/>
       <au:plainlistener/>
     </au:antunit>
 
@@ -168,8 +189,5 @@ public class LogCapturer { [au:antunit] Target: test2 took 0 sec [au:antunit] Target: test1 took 0 sec
- -
-

Copyright © 2005 The Apache Software Foundation. All rights Reserved.

\ No newline at end of file diff --git a/src/etc/testcases/antunit.xml b/src/etc/testcases/antunit.xml index f7e4f54..5beed2d 100644 --- a/src/etc/testcases/antunit.xml +++ b/src/etc/testcases/antunit.xml @@ -27,11 +27,30 @@ under the License. - + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/org/apache/ant/antunit/AntUnit.java b/src/main/org/apache/ant/antunit/AntUnit.java index 9c0e703..fd5d117 100644 --- a/src/main/org/apache/ant/antunit/AntUnit.java +++ b/src/main/org/apache/ant/antunit/AntUnit.java @@ -36,6 +36,7 @@ import org.apache.tools.ant.Target; 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 @@ public class AntUnit extends Task { /** * 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 @@ public class AntUnit extends Task { /** * 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 class AntUnit extends Task { } 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 @@ public class AntUnit extends Task { } /** - * 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 @@ public class AntUnit extends Task { * 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()); diff --git a/src/testcases/org/apache/ant/antunit/AntUnitTest.java b/src/testcases/org/apache/ant/antunit/AntUnitTest.java index 33cdedf..45acb09 100644 --- a/src/testcases/org/apache/ant/antunit/AntUnitTest.java +++ b/src/testcases/org/apache/ant/antunit/AntUnitTest.java @@ -62,4 +62,22 @@ public class AntUnitTest extends BuildFileTest { && 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"); + } + }