Compare commits

..

1 Commits

Author SHA1 Message Date
Stefan Bodewig c7b36f11b9 prepare RC1 of AntUnit 1.4.1 2021-07-03 12:47:52 +02:00
33 changed files with 410 additions and 1317 deletions

View File

@ -1,14 +0,0 @@
github:
rulesets:
- name: "Default Branch Protection"
type: branch
branches:
includes:
- "~DEFAULT_BRANCH"
- "release/*"
- "rel/*"
excludes: []
bypass_teams:
- root
restrict_deletion: true
restrict_force_push: true

1
.gitignore vendored
View File

@ -3,4 +3,3 @@
/ivy/
/lib/
/target/
distribution

203
LICENSE
View File

@ -1,203 +0,0 @@
/*
* Apache License
* Version 2.0, January 2004
* http://www.apache.org/licenses/
*
* TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
*
* 1. Definitions.
*
* "License" shall mean the terms and conditions for use, reproduction,
* and distribution as defined by Sections 1 through 9 of this document.
*
* "Licensor" shall mean the copyright owner or entity authorized by
* the copyright owner that is granting the License.
*
* "Legal Entity" shall mean the union of the acting entity and all
* other entities that control, are controlled by, or are under common
* control with that entity. For the purposes of this definition,
* "control" means (i) the power, direct or indirect, to cause the
* direction or management of such entity, whether by contract or
* otherwise, or (ii) ownership of fifty percent (50%) or more of the
* outstanding shares, or (iii) beneficial ownership of such entity.
*
* "You" (or "Your") shall mean an individual or Legal Entity
* exercising permissions granted by this License.
*
* "Source" form shall mean the preferred form for making modifications,
* including but not limited to software source code, documentation
* source, and configuration files.
*
* "Object" form shall mean any form resulting from mechanical
* transformation or translation of a Source form, including but
* not limited to compiled object code, generated documentation,
* and conversions to other media types.
*
* "Work" shall mean the work of authorship, whether in Source or
* Object form, made available under the License, as indicated by a
* copyright notice that is included in or attached to the work
* (an example is provided in the Appendix below).
*
* "Derivative Works" shall mean any work, whether in Source or Object
* form, that is based on (or derived from) the Work and for which the
* editorial revisions, annotations, elaborations, or other modifications
* represent, as a whole, an original work of authorship. For the purposes
* of this License, Derivative Works shall not include works that remain
* separable from, or merely link (or bind by name) to the interfaces of,
* the Work and Derivative Works thereof.
*
* "Contribution" shall mean any work of authorship, including
* the original version of the Work and any modifications or additions
* to that Work or Derivative Works thereof, that is intentionally
* submitted to Licensor for inclusion in the Work by the copyright owner
* or by an individual or Legal Entity authorized to submit on behalf of
* the copyright owner. For the purposes of this definition, "submitted"
* means any form of electronic, verbal, or written communication sent
* to the Licensor or its representatives, including but not limited to
* communication on electronic mailing lists, source code control systems,
* and issue tracking systems that are managed by, or on behalf of, the
* Licensor for the purpose of discussing and improving the Work, but
* excluding communication that is conspicuously marked or otherwise
* designated in writing by the copyright owner as "Not a Contribution."
*
* "Contributor" shall mean Licensor and any individual or Legal Entity
* on behalf of whom a Contribution has been received by Licensor and
* subsequently incorporated within the Work.
*
* 2. Grant of Copyright License. Subject to the terms and conditions of
* this License, each Contributor hereby grants to You a perpetual,
* worldwide, non-exclusive, no-charge, royalty-free, irrevocable
* copyright license to reproduce, prepare Derivative Works of,
* publicly display, publicly perform, sublicense, and distribute the
* Work and such Derivative Works in Source or Object form.
*
* 3. Grant of Patent License. Subject to the terms and conditions of
* this License, each Contributor hereby grants to You a perpetual,
* worldwide, non-exclusive, no-charge, royalty-free, irrevocable
* (except as stated in this section) patent license to make, have made,
* use, offer to sell, sell, import, and otherwise transfer the Work,
* where such license applies only to those patent claims licensable
* by such Contributor that are necessarily infringed by their
* Contribution(s) alone or by combination of their Contribution(s)
* with the Work to which such Contribution(s) was submitted. If You
* institute patent litigation against any entity (including a
* cross-claim or counterclaim in a lawsuit) alleging that the Work
* or a Contribution incorporated within the Work constitutes direct
* or contributory patent infringement, then any patent licenses
* granted to You under this License for that Work shall terminate
* as of the date such litigation is filed.
*
* 4. Redistribution. You may reproduce and distribute copies of the
* Work or Derivative Works thereof in any medium, with or without
* modifications, and in Source or Object form, provided that You
* meet the following conditions:
*
* (a) You must give any other recipients of the Work or
* Derivative Works a copy of this License; and
*
* (b) You must cause any modified files to carry prominent notices
* stating that You changed the files; and
*
* (c) You must retain, in the Source form of any Derivative Works
* that You distribute, all copyright, patent, trademark, and
* attribution notices from the Source form of the Work,
* excluding those notices that do not pertain to any part of
* the Derivative Works; and
*
* (d) If the Work includes a "NOTICE" text file as part of its
* distribution, then any Derivative Works that You distribute must
* include a readable copy of the attribution notices contained
* within such NOTICE file, excluding those notices that do not
* pertain to any part of the Derivative Works, in at least one
* of the following places: within a NOTICE text file distributed
* as part of the Derivative Works; within the Source form or
* documentation, if provided along with the Derivative Works; or,
* within a display generated by the Derivative Works, if and
* wherever such third-party notices normally appear. The contents
* of the NOTICE file are for informational purposes only and
* do not modify the License. You may add Your own attribution
* notices within Derivative Works that You distribute, alongside
* or as an addendum to the NOTICE text from the Work, provided
* that such additional attribution notices cannot be construed
* as modifying the License.
*
* You may add Your own copyright statement to Your modifications and
* may provide additional or different license terms and conditions
* for use, reproduction, or distribution of Your modifications, or
* for any such Derivative Works as a whole, provided Your use,
* reproduction, and distribution of the Work otherwise complies with
* the conditions stated in this License.
*
* 5. Submission of Contributions. Unless You explicitly state otherwise,
* any Contribution intentionally submitted for inclusion in the Work
* by You to the Licensor shall be under the terms and conditions of
* this License, without any additional terms or conditions.
* Notwithstanding the above, nothing herein shall supersede or modify
* the terms of any separate license agreement you may have executed
* with Licensor regarding such Contributions.
*
* 6. Trademarks. This License does not grant permission to use the trade
* names, trademarks, service marks, or product names of the Licensor,
* except as required for reasonable and customary use in describing the
* origin of the Work and reproducing the content of the NOTICE file.
*
* 7. Disclaimer of Warranty. Unless required by applicable law or
* agreed to in writing, Licensor provides the Work (and each
* Contributor provides its Contributions) on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied, including, without limitation, any warranties or conditions
* of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
* PARTICULAR PURPOSE. You are solely responsible for determining the
* appropriateness of using or redistributing the Work and assume any
* risks associated with Your exercise of permissions under this License.
*
* 8. Limitation of Liability. In no event and under no legal theory,
* whether in tort (including negligence), contract, or otherwise,
* unless required by applicable law (such as deliberate and grossly
* negligent acts) or agreed to in writing, shall any Contributor be
* liable to You for damages, including any direct, indirect, special,
* incidental, or consequential damages of any character arising as a
* result of this License or out of the use or inability to use the
* Work (including but not limited to damages for loss of goodwill,
* work stoppage, computer failure or malfunction, or any and all
* other commercial damages or losses), even if such Contributor
* has been advised of the possibility of such damages.
*
* 9. Accepting Warranty or Additional Liability. While redistributing
* the Work or Derivative Works thereof, You may choose to offer,
* and charge a fee for, acceptance of support, warranty, indemnity,
* or other liability obligations and/or rights consistent with this
* License. However, in accepting such obligations, You may act only
* on Your own behalf and on Your sole responsibility, not on behalf
* of any other Contributor, and only if You agree to indemnify,
* defend, and hold each Contributor harmless for any liability
* incurred by, or claims asserted against, such Contributor by reason
* of your accepting any such warranty or additional liability.
*
* END OF TERMS AND CONDITIONS
*
* APPENDIX: How to apply the Apache License to your work.
*
* To apply the Apache License to your work, attach the following
* boilerplate notice, with the fields enclosed by brackets "[]"
* replaced with your own identifying information. (Don't include
* the brackets!) The text should be enclosed in the appropriate
* comment syntax for the file format. We also recommend that a
* file or class name and description of purpose be included on the
* same "printed page" as the copyright notice for easier
* identification within third-party archives.
*
* Copyright [yyyy] [name of copyright owner]
*
* 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.
*/

2
NOTICE
View File

@ -1,5 +1,5 @@
Apache AntUnit
Copyright 2005-2018,2021-2022,2026 The Apache Software Foundation
Copyright 2005-2018,2021 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (https://www.apache.org/).

View File

@ -22,24 +22,11 @@ under the License.
<!-- easy way to override properties -->
<property file="build.properties"/>
<!-- we don't want the build to look for a packaged AntUnit -->
<target name="setup-for-antunit-tests" depends="setup,determine-test-types,resolve"
unless="skip-antunit">
<typedef uri="antlib:org.apache.ant.antunit"
resource="org/apache/ant/antunit/antlib.xml">
<classpath>
<path refid="classpath.test"/>
<pathelement location="${build.classes}"/>
<pathelement location="${antlib.location}"/>
</classpath>
</typedef>
</target>
<!-- don't fork junit; regexp classes not available -->
<property name="junit.fork" value="false" />
<target name="ready-for-bin-dist" depends="create-antlib-sbom,common.ready-for-bin-dist"/>
<target name="after-src-dist" depends="src-sboms"/>
<target name="after-bin-dist" depends="bin-sboms"/>
<property name="javac.test-source" value="1.5"/>
<property name="javac.test-target" value="1.5"/>
<import file="common/build.xml"/>
<import file="cyclonedx.xml"/>
</project>

View File

@ -37,25 +37,7 @@
<title>Apache AntUnit</title>
</properties>
<release version="1.5.1" date="unreleased">
</release>
<release version="1.5.0" date="2026-07-19">
<action type="add">
Allow the AntUnit task to use a different classloader when
running the test by means of a nested classpath or a
classpathrefid attribute.
Only works properly with Ant 1.10.13 or later.
</action>
<action type="add">
Add new assertNotEquals, assertPropertyNotSet,
assertPropertyNotEquals, assertPropertyDoesntContain and
assertReferenceIsNotSet assertions.
</action>
</release>
<release version="1.4.1" date="2021-07-07">
<release version="1.4.1" date="unreleased">
<action type="fix" issue="65315">
We didn't follow our own best practice and hard-coded the
AntUnit URI inside the Antlib descriptor instead of using

2
common

@ -1 +1 @@
Subproject commit 08aa3efdbec177de04e5a9d7f9a5ca787d612a4e
Subproject commit a715465514e3aaa5e6e06a91345c0292c3642539

View File

@ -1,255 +0,0 @@
<?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
https://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="cyclonedx" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="define-cyclonedx-components"
depends="define-core-ant-components"
if="can.use.cyclonedx">
<cdx:externalreferenceset
id="antlib-ext-refs"
xmlns:cdx="antlib:org.apache.ant.cyclonedx">
<externalReference
type="VCS"
url="https://gitbox.apache.org/repos/asf/ant-antlibs-antunit.git"/>
<externalReference
type="ISSUE_TRACKER"
url="https://bz.apache.org/bugzilla/buglist.cgi?component=AntUnit&amp;product=Ant"/>
</cdx:externalreferenceset>
</target>
<target name="create-antlib-sbom"
depends="define-cyclonedx-components,antlib"
if="can.use.cyclonedx">
<uptodate property="antlib-sbom-ok"
targetfile="${build.lib}/${artifact.stub}.cdx.json">
<srcresources>
<file file="${jarname}"/>
<file file="ivy.xml"/>
<file file="cyclonedx.xml"/>
</srcresources>
</uptodate>
<cdx:componentbom
bomName="${artifact.stub}.cdx"
outputdirectory="${build.lib}"
format="all"
useComponentSupplier="true"
useComponentManufacturer="true"
unless:set="antlib-sbom-ok"
xmlns:unless="ant:unless"
xmlns:cdx="antlib:org.apache.ant.cyclonedx">
<component
name="${artifact.name}"
group="org.apache.ant"
version="${artifact.version}"
description="Apache AntUnit"
publisher="The Apache Software Foundation"
supplierIsManufacturer="true">
<file file="${jarname}"/>
<supplier refid="ant-pmc"/>
<license refid="apache-2"/>
<externalReferenceSet refid="ant-common-refs"/>
<externalReferenceSet refid="antlibs-common-ext-refs"/>
<externalReferenceSet refid="antlib-ext-refs"/>
<dependency componentRef="ant"/>
<dependency componentRef="junit"/>
</component>
<additionalComponent refid="ant"/>
<additionalComponent refid="ant-launcher"/>
<additionalComponent
id="junit"
name="junit"
group="junit"
version="4.13.2"
description="JUnit is a unit testing framework for Java, created by Erich Gamma and Kent Beck."
scope="optional"
publisher="JUnit">
<license licenseId="EPL-1.0">
<url url="http://www.eclipse.org/legal/epl-v10.html"/>
</license>
<externalReference
type="WEBSITE"
url="http://junit.org"/>
<dependency componentRef="hamcrest"/>
</additionalComponent>
<additionalComponent
id="hamcrest"
name="hamcrest-core"
group="org.hamcrest"
version="1.3"
description="Core API and libraries of hamcrest matcher framework."
scope="optional">
<license licenseId="BSD-3-Clause">
<url url="https://raw.githubusercontent.com/hamcrest/JavaHamcrest/master/LICENSE"/>
</license>
<externalReference
type="WEBSITE"
url="http://hamcrest.org/JavaHamcrest/"/>
</additionalComponent>
<license refid="apache-2"/>
</cdx:componentbom>
</target>
<target name="after-dist"
depends="define-cyclonedx-components"
if="can.use.cyclonedx">
<macrodef name="distributionbom" backtrace="false">
<attribute name="version"/>
<attribute name="archiveName"/>
<attribute name="archiveUrl"/>
<attribute name="archiveLocation" default=""/>
<attribute name="outputDirectory"/>
<attribute name="description"/>
<attribute name="publisher"/>
<attribute name="componentType" default="file"/>
<attribute name="format" default="all"/>
<attribute name="useComponentManufacturer" default="true"/>
<attribute name="useComponentSupplier" default="true"/>
<attribute name="supplierIsManufacturer" default="true"/>
<element name="archiveContent"/>
<element name="componentChildren" optional="true"/>
<element name="additionalBomContent" optional="true"/>
<sequential
xmlns:cdx="antlib:org.apache.ant.cyclonedx">
<cdx:componentbom
bomName="@{archiveName}.cdx"
outputdirectory="@{outputDirectory}"
format="@{format}"
useComponentManufacturer="@{useComponentManufacturer}"
useComponentSupplier="@{useComponentSupplier}">
<component
version="@{version}"
purl="@{archiveUrl}"
name="@{archiveUrl}"
description="@{description}"
publisher="@{publisher}"
type="@{componentType}"
supplierIsManufacturer="@{supplierIsManufacturer}">
<file file="@{archiveLocation}"
unless:blank="@{archiveLocation}" xmlns:unless="ant:unless"/>
<componentChildren/>
</component>
<pureFileComponents>
<archiveContent/>
</pureFileComponents>
<additionalBomContent/>
</cdx:componentbom>
</sequential>
</macrodef>
<macrodef name="create-tarball-bom">
<attribute name="distdir"/>
<attribute name="distbase"/>
<attribute name="subdir"/>
<attribute name="binsrc"/>
<attribute name="binarysource"/>
<attribute name="ext"/>
<element name="moreComponentChildren" implicit="true" optional="true"/>
<sequential>
<distributionbom
outputdirectory="@{distbase}"
version="${artifact.version}"
archiveName="${dist.name}-@{binsrc}.@{ext}"
archiveUrl="https://archive.apache.org/dist/ant/antlibs/antunit/@{subdir}/${dist.name}-@{binsrc}.@{ext}"
archiveLocation="@{distbase}/${dist.name}-@{binsrc}.@{ext}"
description="Apache AntUnit @{binarysource}"
publisher="The Apache Software Foundation"
xmlns:cdx="antlib:org.apache.ant.cyclonedx">
<componentChildren>
<supplier refid="ant-pmc"/>
<license refid="apache-2"/>
<externalReferenceSet refid="ant-common-refs"/>
<externalReferenceSet refid="antlibs-common-ext-refs"/>
<externalReferenceSet refid="antlib-ext-refs"/>
<moreComponentChildren/>
</componentChildren>
<archiveContent>
<fileset dir="@{distdir}/..">
<include name="${dist.name}/**"/>
</fileset>
</archiveContent>
<additionalBomContent>
<license refid="apache-2"/>
</additionalBomContent>
</distributionbom>
</sequential>
</macrodef>
<macrodef name="create-tarball-boms">
<attribute name="distdir"/>
<attribute name="distbase"/>
<attribute name="subdir"/>
<attribute name="binsrc"/>
<attribute name="binarysource"/>
<element name="componentChildren" implicit="true" optional="true"/>
<sequential>
<create-tarball-bom
distdir="@{distdir}"
distbase="@{distbase}"
subdir="@{subdir}"
binsrc="@{binsrc}"
binarysource="@{binarysource}"
ext="tar.gz">
<componentChildren/>
</create-tarball-bom>
<create-tarball-bom
distdir="@{distdir}"
distbase="@{distbase}"
subdir="@{subdir}"
binsrc="@{binsrc}"
binarysource="@{binarysource}"
ext="tar.bz2">
<componentChildren/>
</create-tarball-bom>
<create-tarball-bom
distdir="@{distdir}"
distbase="@{distbase}"
subdir="@{subdir}"
binsrc="@{binsrc}"
binarysource="@{binarysource}"
ext="zip">
<componentChildren/>
</create-tarball-bom>
</sequential>
</macrodef>
</target>
<target name="src-sboms" depends="after-dist" if="can.use.cyclonedx">
<create-tarball-boms
distdir="${src.dist.dir}"
distbase="${dist.base}"
subdir="source"
binsrc="src"
binarysource="Source Distribution"/>
</target>
<target name="bin-sboms" depends="after-dist" if="can.use.cyclonedx">
<create-tarball-boms
distdir="${bin.dist.dir}"
distbase="${dist.base}"
subdir="binaries"
binsrc="bin"
binarysource="Binary Distribution">
<component>
<sbomLink>
<file file="${bin.dist.dir}/${artifact.stub}.cdx.json"/>
</sbomLink>
<file file="${bin.dist.dir}/${artifact.stub}.jar"/>
</component>
</create-tarball-boms>
</target>
</project>

View File

@ -145,14 +145,6 @@ public class LogCapturer {
attribute is set to false.</td>
<td align="center">No.</td>
</tr>
<tr>
<td valign="top">classpathrefid</td>
<td valign="top">Specify the classpath to use when running the
tests - specified as a reference to an existing path.<br/>
<em>since AntUnit 1.5</em>
</td>
<td align="center">No.</td>
</tr>
</table>
<h3>Parameters specified as nested elements</h3>
@ -232,12 +224,6 @@ public class LogCapturer {
</pre>
</p>
<h4>classpath</h4>
<p>Nested path-like structure. Specifies the classpath to use
when running the tests. Requires Ant 1.10.13 or later to work
properly. <em>since AntUnit 1.5</em>.</p>
<h3>Examples</h3>
<p>This build file snippet (from src/etc/testcases/antunit/base.xml)</p>

View File

@ -89,54 +89,7 @@
<pre>
&lt;assertEquals message="foo is not bar" expected="bar"
actual="${foo}" casesensitive="false"/&gt;
</pre>
<h2><a name="assertNotEquals">assertNotEquals</a></h2>
<p>Asserts that its two arguments are not equal.</p>
<p><em>Since AntUnit 1.5</em></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">notExpected</td>
<td valign="top">First string to test.</td>
<td valign="top" align="center">Yes</td>
</tr>
<tr>
<td valign="top">actual</td>
<td valign="top">Second string to test.</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
'<em>notExpected</em>' to be '<em>actual</em>'".</td>
<td align="center">No.</td>
</tr>
<tr>
<td valign="top">casesensitive</td>
<td valign="top">Perform a case sensitive comparision.
Default is true.</td>
<td valign="top" align="center">No</td>
</tr>
</table>
<h3>Examples</h3>
<p>Make the build fail with the message "foo is bar" if the
property foo doesn't hold the value bar regardless of case:</p>
<pre>
&lt;assertNotEquals message="foo is bar" notExpected="bar"
actual="${foo}" casesensitive="false"/&gt;
actual="${foo}" casesensitive="false"/&gt;
</pre>
<h2><a name="assertPropertySet">assertPropertySet</a></h2>
@ -172,42 +125,6 @@
&lt;assertPropertySet name="foo"/&gt;
</pre>
<h2><a name="assertPropertyNotSet">assertPropertyNotSet</a></h2>
<p><em>Since AntUnit 1.5</em></p>
<p>Asserts that a property hasn't got a value.</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">name</td>
<td valign="top">Name of the property.</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 property
'<em>name</em>' to be set but was '<em>actual value</em>'".</td>
<td align="center">No.</td>
</tr>
</table>
<h3>Examples</h3>
<p>Make the build fail with the message "Didn't expect property
'foo' but was 'bar'" if the property foo is defined and has
value bar:</p>
<pre>
&lt;assertPropertyNotSet name="foo"/&gt;
</pre>
<h2><a name="assertPropertyEquals">assertPropertyEquals</a></h2>
<p>Asserts that a given property is set and holds a certain
@ -252,54 +169,7 @@
<pre>
&lt;assertPropertyEquals message="foo is not bar" value="bar"
name="foo" casesensitive="false"/&gt;
</pre>
<h2><a name="assertPropertyNotEquals">assertPropertyNotEquals</a></h2>
<p><em>Since AntUnit 1.5</em></p>
<p>Asserts that a given property is set but doesn't hold a certain
value.</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">name</td>
<td valign="top">Name of the property.</td>
<td valign="top" align="center">Yes</td>
</tr>
<tr>
<td valign="top">value</td>
<td valign="top">Not expected value.</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 property '<em>name</em>' to have value '<em>value</em>'".</td>
<td align="center">No.</td>
</tr>
<tr>
<td valign="top">casesensitive</td>
<td valign="top">Perform a case sensitive comparision.
Default is true.</td>
<td valign="top" align="center">No</td>
</tr>
</table>
<h3>Examples</h3>
<p>Make the build fail with the message "foo is bar" if the
property foo holds the value bar regardless of case:</p>
<pre>
&lt;assertPropertyNotEquals message="foo is bar" value="bar"
name="foo" casesensitive="false"/&gt;
name="foo" casesensitive="false"/&gt;
</pre>
<h2><a name="assertPropertyContains">assertPropertyContains</a></h2>
@ -349,55 +219,6 @@
name="foo" casesensitive="false"/&gt;
</pre>
<h2><a name="assertPropertyDoesntContain">assertPropertyDoesntContain</a></h2>
<p>Asserts that a given property is set and doesn't hold a certain
value as substring.</p>
<p><em>Since AntUnit 1.5</em></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">name</td>
<td valign="top">Name of the property.</td>
<td valign="top" align="center">Yes</td>
</tr>
<tr>
<td valign="top">value</td>
<td valign="top">Not expected substring value.</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 property
'<em>name</em>' to contain value '<em>value</em>' but was
'<em>value of property name</em>'".</td>
<td align="center">No.</td>
</tr>
<tr>
<td valign="top">casesensitive</td>
<td valign="top">Perform a case sensitive comparision.
Default is true.</td>
<td valign="top" align="center">No</td>
</tr>
</table>
<h3>Examples</h3>
<p>Make the build fail with the message "foo contains bar" if the
property foo contains the value bar regardless of case:</p>
<pre>
&lt;assertPropertyDoesntContain message="foo contains bar" value="bar"
name="foo" casesensitive="false"/&gt;
</pre>
<h2><a name="assertFileExists">assertFileExists</a></h2>
<p>Asserts that a given file exists.</p>
@ -786,7 +607,7 @@
<td align="center">No.</td>
</tr>
</table>
<h3>Example</h3>
<p>Make the build fail if the file build.xml and backups/build.xml
@ -824,7 +645,7 @@
<td align="center">No.</td>
</tr>
</table>
<h3>Example</h3>
<p>Make the build fail if the file build.xml and backups/build.xml
@ -867,41 +688,6 @@
&lt;assertReferenceSet name="foo"/&gt;
</pre>
<h2><a name="assertReferenceIsNotSet">assertReferenceIsNotSet</a></h2>
<p>Asserts that a reference hasn't got any value.</p>
<p><em>Since AntUnit 1.5</em></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">refid</td>
<td valign="top">Id of the reference.</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 reference
'<em>id</em>'".</td>
<td align="center">No.</td>
</tr>
</table>
<h3>Examples</h3>
<p>Make the build fail with the message "Didn't expect reference 'foo'"
if the reference foo is defined:</p>
<pre>
&lt;assertReferenceIsNotSet name="foo"/&gt;
</pre>
<h2><a name="assertReferenceIsType">assertReferenceIsType</a></h2>
<p>Asserts that a reference has a value of a given type.</p>

16
ivy.xml
View File

@ -34,9 +34,9 @@
</description>
</info>
<configurations>
<conf name="default" description="full antlib with all dependencies"/>
<conf name="provided" description="Ant must be present at runtime"/>
<conf name="test" description="dependencies used for JUnit tests of the antlib" transitive="false" visibility="private"/>
<conf name="default" description="full antlib with all dependencies"/>
<conf name="provided" description="Ant must be present at runtime"/>
<conf name="test" description="dependencies used for JUnit tests of the antlib" transitive="false" visibility="private"/>
</configurations>
<publications xmlns:e="urn:ant.apache.org:ivy-extras">
<artifact name="${artifact.name}" type="pom" ext="pom"/>
@ -55,14 +55,10 @@
e:classifier="ivy"/>
<artifact name="${artifact.name}" type="ivy.asc" ext="xml.asc"
e:classifier="ivy"/>
<artifact name="${artifact.name}" type="cyclonedx.xml" ext="cdx.xml"/>
<artifact name="${artifact.name}" type="cyclonedx.xml.asc" ext="cdx.xml.asc"/>
<artifact name="${artifact.name}" type="cyclonedx.json" ext="cdx.json"/>
<artifact name="${artifact.name}" type="cyclonedx.json.asc" ext="cdx.json.asc"/>
</publications>
<dependencies>
<dependency org="junit" name="junit" rev="4.13.2" conf="default"/>
<dependency org="org.apache.ant" name="ant" rev="1.10.13" conf="provided->default"/>
<dependency org="org.apache.ant" name="ant-testutil" rev="1.10.13" conf="test->default"/>
<dependency org="junit" name="junit" rev="4.12" conf="default"/>
<dependency org="org.apache.ant" name="ant" rev="1.8.1" conf="provided->default"/>
<dependency org="org.apache.ant" name="ant-testutil" rev="1.8.1" conf="test->default"/>
</dependencies>
</ivy-module>

View File

@ -75,7 +75,7 @@
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.13</version>
<version>1.8.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
@ -87,20 +87,20 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<version>4.12</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-launcher</artifactId>
<version>1.10.13</version>
<version>1.8.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-testutil</artifactId>
<version>1.10.13</version>
<version>1.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -77,22 +77,6 @@ under the License.
<au:assertEquals expected="bar" actual="BAR"/>
</target>
<target name="assertNotEqualsPass1">
<au:assertNotEquals notexpected="bar" actual="baz"/>
</target>
<target name="assertNotEqualsPass2">
<au:assertNotEquals notexpected="bar" actual="BAR"/>
</target>
<target name="assertNotEqualsFail">
<au:assertNotEquals notexpected="bar" actual="bar"/>
</target>
<target name="assertNotEqualsCaseFail">
<au:assertNotEquals notexpected="bar" actual="BAR" casesensitive="false"/>
</target>
<target name="assertPropertySetPass">
<property name="foo" value="bar"/>
<au:assertPropertySet name="foo"/>
@ -102,15 +86,6 @@ under the License.
<au:assertPropertySet name="foo"/>
</target>
<target name="assertPropertyNotSetPass">
<au:assertPropertyNotSet name="foo"/>
</target>
<target name="assertPropertyNotSetFail">
<property name="foo" value="bar"/>
<au:assertPropertyNotSet name="foo"/>
</target>
<target name="assertPropertyEqualsPass">
<property name="foo" value="bar"/>
<au:assertPropertyEquals name="foo" value="bar"/>
@ -135,30 +110,6 @@ under the License.
<au:assertPropertyEquals name="foo" value="BAR"/>
</target>
<target name="assertPropertyNotEqualsPass1">
<property name="foo" value="bar"/>
<au:assertPropertyNotEquals name="foo" value="baz"/>
</target>
<target name="assertPropertyNotEqualsPass2">
<property name="foo" value="bar"/>
<au:assertPropertyNotEquals name="foo" value="BAR"/>
</target>
<target name="assertPropertyNotEqualsFail1">
<au:assertPropertyNotEquals name="foo" value="bar"/>
</target>
<target name="assertPropertyNotEqualsFail2">
<property name="foo" value="bar"/>
<au:assertPropertyNotEquals name="foo" value="bar"/>
</target>
<target name="assertPropertyNotEqualsCaseFail">
<property name="foo" value="bar"/>
<au:assertPropertyNotEquals name="foo" value="BAR" casesensitive="false"/>
</target>
<target name="assertPropertyContains">
<property name="foo" value="bar"/>
<au:assertPropertyContains name="foo" value="ba"/>
@ -169,16 +120,6 @@ under the License.
<au:assertPropertyContains name="foo" value="foo"/>
</target>
<target name="assertPropertyDoesntContain">
<property name="foo" value="bar"/>
<au:assertPropertyDoesntContain name="foo" value="foo"/>
</target>
<target name="assertPropertyDoesntContainFail">
<property name="foo" value="bar"/>
<au:assertPropertyDoesntContain name="foo" value="ba"/>
</target>
<target name="assertFileExistsPass">
<au:assertFileExists file="assert.xml"/>
</target>
@ -264,15 +205,6 @@ under the License.
<au:assertReferenceSet refid="foo2"/>
</target>
<target name="assertReferenceIsNotSetPass">
<au:assertReferenceIsNotSet refid="foo3"/>
</target>
<target name="assertReferenceIsNotSetFail">
<path id="foo4"/>
<au:assertReferenceIsNotSet refid="foo4"/>
</target>
<target name="assertReferenceIsTypePass">
<path id="foo3"/>
<au:assertReferenceIsType refid="foo3" type="path"/>

View File

@ -27,11 +27,10 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
@ -42,9 +41,7 @@ import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Ant;
import org.apache.tools.ant.types.Mapper;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.PropertySet;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.types.resources.Union;
@ -110,24 +107,24 @@ public class AntUnit extends Task {
* The object responsible for the execution of the unit test.
* scriptRunner is invoked to executes the targets and keep the
* reference to the project. scriptRunner is defined only when the
* antunit script is running.
* antunit script is running.
*/
private AntUnitScriptRunner scriptRunner;
/**
* listeners.
*/
private ArrayList<AntUnitListener> listeners = new ArrayList<AntUnitListener>();
private ArrayList listeners = new ArrayList();
/**
* propertysets.
*/
private ArrayList<PropertySet> propertySets = new ArrayList<PropertySet>();
private ArrayList propertySets = new ArrayList();
/**
* Holds references to be inherited by the test project
*/
private ArrayList<ReferenceSet> referenceSets = new ArrayList<ReferenceSet>();
private ArrayList referenceSets = new ArrayList();
/**
* has a failure occured?
@ -149,10 +146,6 @@ public class AntUnit extends Task {
*/
private String errorProperty = null;
private Path classpath;
private AntClassLoader subprojectCoreLoader;
/**
* Add build files to run as tests.
* @param rc the ResourceCollection to add.
@ -217,28 +210,6 @@ public class AntUnit extends Task {
this.failOnError = failOnError;
}
/**
* Create the nested classpath element.
* @return {@link Path}
*/
public Path createClasspath() {
if (classpath != null) {
throw new BuildException("Can only set classpath once");
}
return classpath = new Path(getProject());
}
/**
* Set the test classpath as a reference to a {@link Path} defined elsewhere.
* @param classpathRefid
*/
public void setClasspathRefid(String classpathRefid) {
if (classpathRefid == null || classpathRefid.trim().length() == 0) {
throw new BuildException("Null/empty/blank @classpathrefid specified");
}
createClasspath().setRefid(new org.apache.tools.ant.types.Reference(getProject(), classpathRefid));
}
/**
* Execute the tests.
*/
@ -246,9 +217,6 @@ public class AntUnit extends Task {
if (buildFiles == null) {
throw new BuildException(ERROR_NO_TESTS);
}
if (classpath != null && classpath.size() > 0) {
subprojectCoreLoader = getProject().createClassLoader(classpath);
}
doResourceCollection(buildFiles);
if (failures > 0 || errors > 0) {
if (errorProperty != null) {
@ -273,15 +241,15 @@ public class AntUnit extends Task {
if (!rc.isFilesystemOnly()) {
throw new BuildException(ERROR_NON_FILES);
}
@SuppressWarnings("unchecked")
Iterable<Resource> iterable = (Iterable<Resource>) rc;
for (Resource resource : iterable) {
FileResource r = (FileResource) resource;
Iterator i = rc.iterator();
while (i.hasNext()) {
FileResource r = (FileResource) i.next();
if (r.isExists()) {
doFile(r.getFile());
} else {
log("Skipping " + r + " since it doesn't exist", Project.MSG_VERBOSE);
log("Skipping " + r + " since it doesn't exist",
Project.MSG_VERBOSE);
}
}
}
@ -298,19 +266,20 @@ public class AntUnit extends Task {
};
try {
scriptRunner = new AntUnitScriptRunner(prjFactory);
List<String> testTargets = scriptRunner.getTestTargets();
List testTargets = scriptRunner.getTestTartgets();
scriptRunner.runSuite(testTargets, notifier);
} finally {
scriptRunner=null;
}
}
/**
* Redirect output to new project instance.
* @param outputToHandle the output to handle.
*/
public void handleOutput(String outputToHandle) {
if (scriptRunner != null) {
if (scriptRunner!=null) {
scriptRunner.getCurrentProject().demuxOutput(outputToHandle, false);
} else {
super.handleOutput(outputToHandle);
@ -325,7 +294,7 @@ public class AntUnit extends Task {
*/
public int handleInput(byte[] buffer, int offset, int length)
throws IOException {
if (scriptRunner != null) {
if (scriptRunner!=null) {
return scriptRunner.getCurrentProject().demuxInput(buffer, offset, length);
}
return super.handleInput(buffer, offset, length);
@ -336,7 +305,7 @@ public class AntUnit extends Task {
* @param toFlush the output String to flush.
*/
public void handleFlush(String toFlush) {
if (scriptRunner != null) {
if (scriptRunner!=null) {
scriptRunner.getCurrentProject().demuxFlush(toFlush, false);
} else {
super.handleFlush(toFlush);
@ -348,7 +317,7 @@ public class AntUnit extends Task {
* @param errorOutputToHandle the error output to handle.
*/
public void handleErrorOutput(String errorOutputToHandle) {
if (scriptRunner != null) {
if (scriptRunner!=null) {
scriptRunner.getCurrentProject().demuxOutput(errorOutputToHandle, true);
} else {
super.handleErrorOutput(errorOutputToHandle);
@ -360,7 +329,7 @@ public class AntUnit extends Task {
* @param errorOutputToFlush the error output to flush.
*/
public void handleErrorFlush(String errorOutputToFlush) {
if (scriptRunner != null) {
if (scriptRunner!=null) {
scriptRunner.getCurrentProject().demuxFlush(errorOutputToFlush, true);
} else {
super.handleErrorFlush(errorOutputToFlush);
@ -373,23 +342,24 @@ public class AntUnit extends Task {
*/
private Project createProjectForFile(File f) {
Project p = new Project();
if (subprojectCoreLoader != null) {
p.setCoreLoader(subprojectCoreLoader);
}
p.setDefaultInputStream(getProject().getDefaultInputStream());
p.initProperties();
p.setInputHandler(getProject().getInputHandler());
getProject().initSubProject(p);
//pass through inherited properties
for (PropertySet set : propertySets) {
@SuppressWarnings({ "unchecked", "rawtypes" })
Map<String,Object> props = (Map) set.getProperties();
for (String key : props.keySet()) {
if (MagicNames.PROJECT_BASEDIR.equals(key) || MagicNames.ANT_FILE.equals(key)) {
for (Iterator outer = propertySets.iterator(); outer.hasNext(); ) {
PropertySet set = (PropertySet) outer.next();
Map props = set.getProperties();
for (Iterator keys = props.keySet().iterator();
keys.hasNext(); ) {
String key = keys.next().toString();
if (MagicNames.PROJECT_BASEDIR.equals(key)
|| MagicNames.ANT_FILE.equals(key)) {
continue;
}
Object value = props.get(key);
if (value instanceof String && p.getProperty(key) == null) {
if (value != null && value instanceof String
&& p.getProperty(key) == null) {
p.setNewProperty(key, (String) value);
}
}
@ -399,7 +369,8 @@ public class AntUnit extends Task {
//with significant modification from taskdefs.Ant in Ant core.
//unfortunately the only way we can share the code directly
//would be to extend Ant (which might not be a bad idea?)
for (ReferenceSet set : referenceSets) {
for (int i = 0; i < referenceSets.size(); ++i) {
ReferenceSet set = (ReferenceSet) referenceSets.get(i);
set.copyReferencesInto(p);
}
@ -419,8 +390,12 @@ public class AntUnit extends Task {
* @param p the Project to attach to.
*/
private void attachListeners(File buildFile, Project p) {
for (AntUnitListener al : listeners) {
p.addBuildListener(new BuildToAntUnitListener(buildFile.getAbsolutePath(), al));
Iterator it = listeners.iterator();
while (it.hasNext()) {
AntUnitListener al = (AntUnitListener) it.next();
p.addBuildListener(new BuildToAntUnitListener(buildFile
.getAbsolutePath(),
al));
al.setCurrentTestProject(p);
}
}
@ -430,7 +405,9 @@ public class AntUnit extends Task {
* @param targetName the name of the target.
*/
private void fireStartTest(String targetName) {
for (AntUnitListener al : listeners) {
Iterator it = listeners.iterator();
while (it.hasNext()) {
AntUnitListener al = (AntUnitListener) it.next();
al.startTest(targetName);
}
}
@ -442,7 +419,9 @@ public class AntUnit extends Task {
*/
private void fireFail(String targetName, AssertionFailedException ae) {
failures++;
for (AntUnitListener al : listeners) {
Iterator it = listeners.iterator();
while (it.hasNext()) {
AntUnitListener al = (AntUnitListener) it.next();
al.addFailure(targetName, ae);
}
}
@ -454,7 +433,9 @@ public class AntUnit extends Task {
*/
private void fireError(String targetName, Throwable t) {
errors++;
for (AntUnitListener al : listeners) {
Iterator it = listeners.iterator();
while (it.hasNext()) {
AntUnitListener al = (AntUnitListener) it.next();
al.addError(targetName, t);
}
}
@ -464,7 +445,9 @@ public class AntUnit extends Task {
* @param targetName the name of the current target.
*/
private void fireEndTest(String targetName) {
for (AntUnitListener al : listeners) {
Iterator it = listeners.iterator();
while (it.hasNext()) {
AntUnitListener al = (AntUnitListener) it.next();
al.endTest(targetName);
}
}
@ -478,7 +461,7 @@ public class AntUnit extends Task {
/**
* references inherited from parent project by antunit scripts
*/
private List<Reference> references = new ArrayList<Reference>();
private ArrayList references = new ArrayList();
/**
* maps source reference ID to target reference ID
*/
@ -488,16 +471,13 @@ public class AntUnit extends Task {
references.add(reference);
}
/**
* Create a nested mapper element.
* @return {@link Mapper}
*/
public Mapper createMapper() {
if (mapper == null) {
return mapper = new Mapper(getProject());
} else {
throw new BuildException("Only one mapper element is allowed"
+ " per referenceSet", getLocation());
}
throw new BuildException("Only one mapper element is allowed per referenceSet",
getLocation());
}
/**
@ -523,16 +503,19 @@ public class AntUnit extends Task {
* @param newProject the target project to copy references into
*/
public void copyReferencesInto(Project newProject) {
FileNameMapper mapper = this.mapper == null ? null : this.mapper.getImplementation();
Set<String> matches = new HashSet<String>();
@SuppressWarnings("unchecked")
Hashtable<String,Object> src = getProject().getReferences();
FileNameMapper mapper = this.mapper == null
? null : this.mapper.getImplementation();
HashSet matches = new HashSet();
Hashtable src = getProject().getReferences();
for (Iterator it = references.iterator(); it.hasNext(); ) {
Reference ref = (Reference) it.next();
for (Reference ref : references) {
matches.clear();
ref.addMatchingReferences(src, matches);
for (String refid : matches) {
for (Iterator ids = matches.iterator(); ids.hasNext(); ) {
String refid = (String) ids.next();
String toRefid = ref.getToRefid();
//transform the refid with the mapper if necessary
@ -573,12 +556,12 @@ public class AntUnit extends Task {
return;
}
Class<?> c = orig.getClass();
Class c = orig.getClass();
Object copy = orig;
try {
Method cloneM = c.getMethod("clone");
Method cloneM = c.getMethod("clone", new Class[0]);
if (cloneM != null) {
copy = cloneM.invoke(orig);
copy = cloneM.invoke(orig, new Object[0]);
log("Adding clone of reference " + oldKey,
Project.MSG_DEBUG);
}
@ -586,14 +569,15 @@ public class AntUnit extends Task {
// not Clonable
}
if (copy instanceof ProjectComponent) {
((ProjectComponent) copy).setProject(newProject);
} else {
try {
Method setProjectM =
c.getMethod("setProject", Project.class);
c.getMethod("setProject", new Class[] {Project.class});
if (setProjectM != null) {
setProjectM.invoke(copy, newProject);
setProjectM.invoke(copy, new Object[] {newProject});
}
} catch (NoSuchMethodException e) {
// ignore this if the class being referenced does not have
@ -606,6 +590,8 @@ public class AntUnit extends Task {
}
newProject.addReference(newKey, copy);
}
}
public static class Reference extends Ant.Reference {
@ -634,21 +620,22 @@ public class AntUnit extends Task {
* @param src table of references to check
* @param dest set of reference IDs matching this reference pattern
*/
public void addMatchingReferences(Hashtable<String, Object> src, Collection<String> dest) {
public void addMatchingReferences(Hashtable src, Collection dest) {
String id = getRefId();
if (id != null) {
if (src.containsKey(id)) {
dest.add(id);
}
} else if (matcher != null) {
for (String refid : src.keySet()) {
for (Iterator it = src.keySet().iterator(); it.hasNext(); ) {
String refid = (String)it.next();
if (matcher.matches(refid)) {
dest.add(refid);
}
}
} else {
throw new BuildException(
"either the refid or regex attribute is required for reference elements");
throw new BuildException("either the refid or regex attribute "
+ "is required for reference elements");
}
}
}
@ -671,8 +658,10 @@ public class AntUnit extends Task {
public void buildFinished(BuildEvent event) {
a.endTestSuite(event.getProject(), buildFile);
}
public void targetStarted(BuildEvent event) {}
public void targetFinished(BuildEvent event) {}
public void targetStarted(BuildEvent event) {
}
public void targetFinished(BuildEvent event) {
}
public void taskStarted(BuildEvent event) {}
public void taskFinished(BuildEvent event) {}
public void messageLogged(BuildEvent event) {}

View File

@ -21,7 +21,7 @@
package org.apache.ant.antunit;
/**
/**
* Provides methods that allow the AntUnitScriptRunner to notify the test progress.
* @since 1.2
*/
@ -31,26 +31,26 @@ public interface AntUnitExecutionNotifier {
* invokes start on all registered test listeners.
* @param targetName the name of the target.
*/
void fireStartTest(String targetName);
public void fireStartTest(String targetName);
/**
* invokes addFailure on all registered test listeners.
* @param targetName the name of the failed target.
* @param ae the associated AssertionFailedException.
*/
void fireFail(String targetName, AssertionFailedException ae);
public void fireFail(String targetName, AssertionFailedException ae);
/**
* invokes addError on all registered test listeners.
* @param targetName the name of the failed target.
* @param t the associated Throwable.
*/
void fireError(String targetName, Throwable t);
public void fireError(String targetName, Throwable t);
/**
* invokes endTest on all registered test listeners.
* @param targetName the name of the current target.
*/
void fireEndTest(String targetName);
public void fireEndTest(String targetName);
}

View File

@ -20,6 +20,7 @@
package org.apache.ant.antunit;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -27,16 +28,15 @@ import java.util.Vector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
/**
* Run antunit tests suites. This AntUnitScriptRunner is responsible for the
* management of the ant project and the correct invocation the target (taking
/**
* Run antunit tests suites. This AntUnitScriptRunner is responsible for the
* management of the ant project and the correct invocation the target (taking
* into account properly the [case]setUp and [case]tearDown targets).
* The user can however provide the order of the test targets and or can filter
* the list of test targets to execute.
* The user must also provide its ProjectFactory and an AntUnitExecutionNotifier.
* @since 1.2
* @since 1.2
*/
public class AntUnitScriptRunner {
@ -69,13 +69,13 @@ public class AntUnitScriptRunner {
* Object used to create projects in order to support test isolation.
*/
private final ProjectFactory prjFactory;
/**
* Indicates if the startSuite method has been invoked. Use to fail fast if the
* the caller forget to call the startSuite method
*/
private boolean isSuiteStarted;
/**
* Does that script have a setUp target (defined when scanning the script)
*/
@ -99,20 +99,20 @@ public class AntUnitScriptRunner {
/**
* List of target names
*/
private final List<String> testTargets = new LinkedList<String>();
private final List testTargets;
/**
/**
* The project currently used.
*/
private Project project = null;
/**
* Indicates if a target has already be executed using this project.
/**
* Indicates if a target has already be executed using this project.
* Value is undefined when project is null.
*/
private boolean projectIsDirty;
/**
* Create a new AntScriptRunner on the given environment.
* @param prjFactory A factory for the ant project that will contains the antunit test to execute.
@ -122,16 +122,17 @@ public class AntUnitScriptRunner {
public AntUnitScriptRunner(ProjectFactory prjFactory) throws BuildException {
this.prjFactory = prjFactory;
Project newProject = getCurrentProject();
@SuppressWarnings("unchecked")
Map<String, Target> targets = newProject.getTargets();
Map targets = newProject.getTargets();
hasSetUp = targets.containsKey(SETUP);
hasTearDown = targets.containsKey(TEARDOWN);
hasSuiteSetUp = targets.containsKey(SUITESETUP);
hasSuiteTearDown = targets.containsKey(SUITETEARDOWN);
for (String name : targets.keySet()) {
if (name.startsWith(TEST) && !TEST.equals(name)) {
getTestTargets().add(name);
testTargets = new LinkedList();
Iterator it = targets.keySet().iterator();
while (it.hasNext()) {
String name = (String) it.next();
if (name.startsWith(TEST) && !name.equals(TEST)) {
testTargets.add(name);
}
}
}
@ -159,7 +160,7 @@ public class AntUnitScriptRunner {
project = prjFactory.createProject();
}
//we already set isDirty to true in order to make sure we didn't reuse
//this project next time getCleanProject is called.
//this project next time getCleanProject is called.
projectIsDirty = true;
return project;
}
@ -167,16 +168,7 @@ public class AntUnitScriptRunner {
/**
* @return List&lt;String&gt; List of test targets of the script file
*/
@Deprecated
public List<String> getTestTartgets() {
return getTestTargets();
}
/**
* Get the (names of the) test targets to execute.
* @return {@link List} of {@link String}
*/
public List<String> getTestTargets() {
public List getTestTartgets() {
return testTargets;
}
@ -192,7 +184,7 @@ public class AntUnitScriptRunner {
* Executes the suiteSetUp target if presents and report any execution error.
* <p>A failure is reported to the notifier and by returning false.
* Note that if the method return false, you are not allowed to run targets.</p>
* @return false in case of execution failure. true in case of success.
* @return false in case of execution failure. true in case of success.
*/
private boolean startSuite(AntUnitExecutionNotifier notifier) {
getCurrentProject().fireBuildStarted();
@ -210,7 +202,7 @@ public class AntUnitScriptRunner {
return true;
}
/**
/**
* Run the specific test target, possibly between the setUp and tearDown targets if
* it exists. Exception or failures are reported to the notifier.
* @param name name of the test target to execute.
@ -222,13 +214,13 @@ public class AntUnitScriptRunner {
throw new AssertionError();
}
Project newProject = getCleanProject();
Vector<String> v = new Vector<String>();
Vector v = new Vector();
if (hasSetUp) {
v.add(SETUP);
}
v.add(name);
// create and register a logcapturer on the newProject
new LogCapturer(newProject);
LogCapturer lc = new LogCapturer(newProject);
try {
notifier.fireStartTest(name);
newProject.executeTargets(v);
@ -254,8 +246,8 @@ public class AntUnitScriptRunner {
/**
* Executes the suiteTearDown target if presents and report any execution error.
* @param caught Any internal exception triggered (and caught) by the caller indicating that
* the execution could not be invoked as expected.
* @param caught Any internal exception triggered (and caught) by the caller indicating that
* the execution could not be invoked as expected.
* @param notifier will receive execution notifications.
*/
private void endSuite(Throwable caught, AntUnitExecutionNotifier notifier) {
@ -274,14 +266,14 @@ public class AntUnitScriptRunner {
/**
* Try to see whether the BuildException e is an AssertionFailedException
* or is caused by an AssertionFailedException. If so, fire a failure for
* or is caused by an AssertionFailedException. If so, fire a failure for
* given targetName. Otherwise fire an error.
*/
private void fireFailOrError(String targetName, BuildException e,
private void fireFailOrError(String targetName, BuildException e,
AntUnitExecutionNotifier notifier) {
boolean failed = false;
Throwable t = e;
while (t instanceof BuildException) {
while (t != null && t instanceof BuildException) {
if (t instanceof AssertionFailedException) {
failed = true;
notifier.fireFail(targetName, (AssertionFailedException) t);
@ -301,13 +293,15 @@ public class AntUnitScriptRunner {
* @param suiteTargets An ordered list of test targets. It must be a sublist of getTestTargets
* @param notifier is notified on test progress
*/
public void runSuite(List<String> suiteTargets, AntUnitExecutionNotifier notifier) {
public void runSuite(List suiteTargets, AntUnitExecutionNotifier notifier) {
Throwable caught = null;
try {
if (!startSuite(notifier)) {
return;
}
for (String name : suiteTargets) {
Iterator iter = suiteTargets.iterator();
while (iter.hasNext()) {
String name = (String) iter.next();
runTarget(name, notifier);
}
} catch (Throwable e) {
@ -316,4 +310,5 @@ public class AntUnitScriptRunner {
endSuite(caught, notifier);
}
}
}

View File

@ -8,7 +8,7 @@
* with the License. You may obtain a copy of the License at
*
* https://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
@ -20,6 +20,7 @@
package org.apache.ant.antunit;
import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
import java.util.Collections;
@ -40,7 +41,7 @@ import org.apache.tools.ant.util.StringUtils;
public class LogCapturer implements BuildListener {
public static final String REFERENCE_ID = "ant.antunit.log";
private List<BuildEvent> events = Collections.synchronizedList(new LinkedList<BuildEvent>());
private List/*<BuildEvent>*/ events = Collections.synchronizedList(new LinkedList());
private Project p;
public LogCapturer(Project p) {
@ -183,14 +184,15 @@ public class LogCapturer implements BuildListener {
}
private String getLog(int minPriority, boolean mergeLines) {
StringBuilder sb = new StringBuilder();
for (BuildEvent buildEvent : new LinkedList<BuildEvent>(events)) {
append(sb, buildEvent, minPriority, mergeLines);
StringBuffer sb = new StringBuffer();
for (Iterator/*<BuildEvent>*/ it = new LinkedList(events).iterator();
it.hasNext(); ) {
append(sb, (BuildEvent) it.next(), minPriority, mergeLines);
}
return sb.toString();
}
private static void append(StringBuilder sb, BuildEvent event,
private static void append(StringBuffer sb, BuildEvent event,
int minPriority, boolean mergeLines) {
if (event.getPriority() <= minPriority) {
sb.append(event.getMessage());

View File

@ -88,22 +88,6 @@ under the License.
</sequential>
</macrodef>
<macrodef name="assertNotEquals" backtrace="false">
<attribute name="notExpected"/>
<attribute name="actual"/>
<attribute name="casesensitive" default="true"/>
<attribute name="message"
default="Didn't expect '@{notExpected}' to be '@{actual}'"/>
<sequential>
<au:fail message="@{message}">
<not>
<equals arg1="@{notExpected}" arg2="@{actual}"
casesensitive="@{casesensitive}"/>
</not>
</au:fail>
</sequential>
</macrodef>
<macrodef name="assertPropertySet" backtrace="false">
<attribute name="name"/>
<attribute name="message"
@ -115,19 +99,6 @@ under the License.
</sequential>
</macrodef>
<macrodef name="assertPropertyNotSet" backtrace="false">
<attribute name="name"/>
<attribute name="message"
default="Didn't expect property '@{name}' to be set but was '${@{name}}'"/>
<sequential>
<au:fail message="@{message}">
<not>
<isset property="@{name}"/>
</not>
</au:fail>
</sequential>
</macrodef>
<macrodef name="assertPropertyEquals" backtrace="false">
<attribute name="name"/>
<attribute name="value"/>
@ -141,19 +112,6 @@ under the License.
</sequential>
</macrodef>
<macrodef name="assertPropertyNotEquals" backtrace="false">
<attribute name="name"/>
<attribute name="value"/>
<attribute name="casesensitive" default="true"/>
<attribute name="message"
default="Didn't expect property '@{name}' to have value '@{value}'"/>
<sequential>
<au:assertPropertySet message="@{message}" name="@{name}"/>
<au:assertNotEquals message="@{message}" notexpected="@{value}"
actual="${@{name}}" casesensitive="@{casesensitive}"/>
</sequential>
</macrodef>
<macrodef name="assertPropertyContains" backtrace="false">
<attribute name="name"/>
<attribute name="value"/>
@ -168,24 +126,7 @@ under the License.
</au:fail>
</sequential>
</macrodef>
<macrodef name="assertPropertyDoesntContain" backtrace="false">
<attribute name="name"/>
<attribute name="value"/>
<attribute name="casesensitive" default="true"/>
<attribute name="message"
default="Didn't expect property '@{name}' to contain value '@{value}' but was '${@{name}}'"/>
<sequential>
<au:assertPropertySet message="@{message}" name="@{name}"/>
<au:fail message="@{message}">
<not>
<contains string="${@{name}}" substring="@{value}"
casesensitive="@{casesensitive}"/>
</not>
</au:fail>
</sequential>
</macrodef>
<macrodef name="assertFileExists" backtrace="false">
<attribute name="file"/>
<attribute name="message"
@ -235,11 +176,11 @@ under the License.
<attribute name="value"/>
<attribute name="casesensitive" default="true"/>
<attribute name="message"
default="Expected resource '@{resource}' to contain value '@{value}' but was '${@{resource}}'"/>
default="Expected resource '@{resource}' to contain value '@{value}' but was '${@{resource}}'"/>
<sequential>
<au:assertResourceExists resource="@{resource}"/>
<au:fail message="@{message}">
<resourcecontains resource="@{resource}" substring="@{value}"
<resourcecontains resource="@{resource}" substring="@{value}"
casesensitive="@{casesensitive}"/>
</au:fail>
</sequential>
@ -250,10 +191,10 @@ under the License.
<attribute name="value"/>
<attribute name="casesensitive" default="true"/>
<attribute name="message"
default="Didn't expect resource '@{resource}' to contain value '@{value}' but was '${@{resource}}'"/>
default="Didn't expect resource '@{resource}' to contain value '@{value}' but was '${@{resource}}'"/>
<sequential>
<au:assertFalse message="@{message}">
<resourcecontains resource="@{resource}" substring="@{value}"
<resourcecontains resource="@{resource}" substring="@{value}"
casesensitive="@{casesensitive}"/>
</au:assertFalse>
</sequential>
@ -310,11 +251,11 @@ under the License.
<attribute name="value"/>
<attribute name="casesensitive" default="true"/>
<attribute name="message"
default="Expected resource '@{refid}' to contain value '@{value}'"/>
default="Expected resource '@{refid}' to contain value '@{value}'"/>
<sequential>
<au:assertRefResourceExists refid="@{refid}"/>
<au:fail message="@{message}">
<resourcecontains refid="@{refid}" substring="@{value}"
<resourcecontains refid="@{refid}" substring="@{value}"
casesensitive="@{casesensitive}"/>
</au:fail>
</sequential>
@ -325,10 +266,10 @@ under the License.
<attribute name="value"/>
<attribute name="casesensitive" default="true"/>
<attribute name="message"
default="Didn't expect resource '@{refid}' to contain value '@{value}'"/>
default="Didn't expect resource '@{refid}' to contain value '@{value}'"/>
<sequential>
<au:assertFalse message="@{message}">
<resourcecontains refid="@{refid}" substring="@{value}"
<resourcecontains refid="@{refid}" substring="@{value}"
casesensitive="@{casesensitive}"/>
</au:assertFalse>
</sequential>
@ -393,19 +334,6 @@ under the License.
</sequential>
</macrodef>
<macrodef name="assertReferenceIsNotSet" backtrace="false">
<attribute name="refid"/>
<attribute name="message"
default="Didn't expect reference '@{refid}'"/>
<sequential>
<au:fail message="@{message}">
<not>
<isreference refid="@{refid}"/>
</not>
</au:fail>
</sequential>
</macrodef>
<macrodef name="assertReferenceIsType" backtrace="false">
<attribute name="refid"/>
<attribute name="type"/>
@ -457,7 +385,7 @@ under the License.
default="Expected '@{string}' to match pattern '@{pattern}'"/>
<sequential>
<au:fail message="@{message}">
<matches string="@{string}" pattern="@{pattern}"
<matches string="@{string}" pattern="@{pattern}"
casesensitive="@{casesensitive}"
singleline="@{singleline}"
multiline="@{multiline}"/>

View File

@ -23,6 +23,7 @@ package org.apache.ant.antunit.junit3;
import java.io.File;
import java.io.PrintStream;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import junit.framework.Test;
@ -56,16 +57,16 @@ public class AntUnitSuite extends TestSuite {
* File reference. Namely, if the File is a relative file, it will
* be resolve relatively to the execution directory (which might be
* different different from the project root directory).</p>
*
*
* @param scriptFile
* AntUnit script file
* @param rootClass
* The test class that creates this suite. This is used to give
* a name to the suite so that an IDE can reexecute this suite.
*/
public AntUnitSuite(File scriptFile, Class<?> rootClass) {
public AntUnitSuite(File scriptFile, Class rootClass) {
setName(rootClass.getName()); //This name allows eclipse to reexecute the test
final AntUnitScriptRunner createdScriptRunner;
AntUnitScriptRunner createdScriptRunner = null;
try {
MyProjectFactory prjFactory = new MyProjectFactory(scriptFile);
createdScriptRunner = new AntUnitScriptRunner(prjFactory);
@ -81,8 +82,11 @@ public class AntUnitSuite extends TestSuite {
initializationReportingTest = null;
stdout = new MultiProjectDemuxOutputStream(antScriptRunner, false);
stderr = new MultiProjectDemuxOutputStream(antScriptRunner, true);
for (String target : antScriptRunner.getTestTargets()) {
addTest(new AntUnitTestCase(this, scriptFile, target));
List testTargets = antScriptRunner.getTestTartgets();
for (Iterator it = testTargets.iterator(); it.hasNext();) {
String target = (String) it.next();
AntUnitTestCase tc = new AntUnitTestCase(this, scriptFile, target);
addTest(tc);
}
}
@ -96,28 +100,28 @@ public class AntUnitSuite extends TestSuite {
MyProjectFactory prjFactory = new MyProjectFactory(scriptFile);
antScriptRunner = new AntUnitScriptRunner(prjFactory);
//the exception is throwed, and it is up to the AntUnitTestCase to handle it.
initializationReportingTest = null;
initializationReportingTest = null;
stdout = new MultiProjectDemuxOutputStream(antScriptRunner, false);
stderr = new MultiProjectDemuxOutputStream(antScriptRunner, true);
setName(antScriptRunner.getName() + "[" + scriptFile + "]");
addTest(singleTc);
}
/**
* {@inheritDoc}
* <p>Run the full AntUnit suite.</p>
*/
public void run(TestResult testResult) {
if (initializationReportingTest != null) {
if (initializationReportingTest!=null) {
initializationReportingTest.run(testResult);
} else {
List<String> testTargets = antScriptRunner.getTestTargets();
List testTartgets = antScriptRunner.getTestTartgets();
JUnitNotificationAdapter notifier = new JUnitNotificationAdapter(
testResult, tests());
runInContainer(testTargets, notifier);
runInContainer(testTartgets, notifier);
}
}
/**
* {@inheritDoc}
* <p>Run a single test target of the AntUnit suite. suiteSetUp,
@ -128,7 +132,7 @@ public class AntUnitSuite extends TestSuite {
initializationReportingTest.run(result);
} else {
String targetName = ((AntUnitTestCase) test).getTarget();
List<String> singleTargetList = Collections.singletonList(targetName);
List singleTargetList = Collections.singletonList(targetName);
JUnitNotificationAdapter notifier = new JUnitNotificationAdapter(
result, tests());
runInContainer(singleTargetList, notifier);
@ -140,13 +144,13 @@ public class AntUnitSuite extends TestSuite {
* <p>When ant executes a project it redirect the input and the output. In this
* context we will only redirect output (unit test are not supposed to be
* interactive).</p>
*
*
* @param targetList
* The list of test target to execute
* @param notifier
* The AntUnit notifier that will receive execution notifications
*/
public void runInContainer(List<String> targetList, AntUnitExecutionNotifier notifier) {
public void runInContainer(List targetList, AntUnitExecutionNotifier notifier) {
PrintStream savedErr = System.err;
PrintStream savedOut = System.out;
try {
@ -172,7 +176,7 @@ public class AntUnitSuite extends TestSuite {
this.scriptFile = scriptFile;
}
public Project createProject() {
public Project createProject() {
ProjectHelper prjHelper = ProjectHelper.getProjectHelper();
Project prj = new Project();
DefaultLogger logger = new DefaultLogger();
@ -194,6 +198,8 @@ public class AntUnitSuite extends TestSuite {
}
public BuildException getAntInitialisationException() {
return hasAntInitError() ? initializationReportingTest.getAntScriptError() : null;
return hasAntInitError() ?
initializationReportingTest.getAntScriptError() :
null;
}
}

View File

@ -28,16 +28,16 @@ import junit.framework.TestCase;
import junit.framework.TestResult;
/**
* JUnit TestCase that executes a single AntUnit target.
* JUnit TestCase that will executes a single AntUnit target.
* <p>This class is not
* supposed to be used directly.</p>
* <p>It is public only because junit must access it as a public.</p>
*/
public class AntUnitTestCase extends TestCase {
// We have to extends TestCase, and not implements Test because otherwise
// JUnit4 will derive the Description composing the suite description from
// We have to extends TestCase, and not implements Test because otherwise
// JUnit4 will derive the Description composing the suite description from
// this className only (AntUnitTestCase), and not from the name.
// However, during execution it use the right Description (base on the
// However, during execution it use the right Description (base on the
// toString)
/**
@ -56,25 +56,25 @@ public class AntUnitTestCase extends TestCase {
* class has been created directly by the IDE from its name.
* In case of initialisation problem when the test is build from the suite,
* the problem is handled at the level of the suite (and this object is never
* created)
* created)
*/
private final BuildException initialisationException;
/**
* Prepare an AntUnitTestCase that will be executed alone.
* <p>This constructor
* is typically used by a junit 3 runner that will reexecute a specific
* <p>This constructor
* is typically used by a junit 3 runner that will reexecute a specific
* test.</p>
* <p>The execution of this test will be embed in a suiteSetUp and
* <p>The execution of this test will be embed in a suiteSetUp and
* suiteTearDown.</p>
* @param name The name of the AntUnitTestCase, normally obtained from a
* previous execution.
* @param name The name of the AntUnitTestCase, normally obtained from a
* previous execution.
*/
public AntUnitTestCase(String name) {
super(name);
BuildException catchedEx = null;
AntUnitSuite createdSuite = null;
TestCaseName nameParser = new TestCaseName(name);
TestCaseName nameParser = new TestCaseName(name);
try {
createdSuite = new AntUnitSuite(this, nameParser.getScript());
} catch (BuildException e) {
@ -92,8 +92,8 @@ public class AntUnitTestCase extends TestCase {
* suite that prepare the antScriptRunner and the JUnitExcutionPlatform. It
* is the responsibility of the suite to execute the suiteSetUp and the
* suiteTearDown.
*
* @param target test target
*
* @param target test target
* @param suite test suite
* @param scriptFile test file
*/
@ -113,7 +113,7 @@ public class AntUnitTestCase extends TestCase {
return target;
}
/**
/**
* Called by a Junit Runner that want to executes specifically
* this test target.
* <p>This implementation delegates the call to the suite.</p>
@ -139,7 +139,7 @@ public class AntUnitTestCase extends TestCase {
protected void runTest() throws BuildException {
throw initialisationException;
}
/**
* Handle the serialization and the parsing of the name of a TestCase. The
* name of the TestCase contains the filename of the script and the target,

View File

@ -36,9 +36,9 @@ import org.apache.ant.antunit.AssertionFailedException;
class JUnitNotificationAdapter implements AntUnitExecutionNotifier {
private final TestResult junitTestResult;
private Map<String, AntUnitTestCase> testByTarget = new HashMap<String, AntUnitTestCase>();
private Map testByTarget = new HashMap();
public JUnitNotificationAdapter(TestResult testResult, Enumeration<Test> tests) {
public JUnitNotificationAdapter(TestResult testResult, Enumeration tests) {
this.junitTestResult = testResult;
while(tests.hasMoreElements()) {
AntUnitTestCase test = (AntUnitTestCase) tests.nextElement();
@ -48,22 +48,22 @@ class JUnitNotificationAdapter implements AntUnitExecutionNotifier {
public void fireStartTest(String targetName) {
//TODO : if it is null, eclipse stop the unit test (add a unit test)
junitTestResult.startTest(testByTarget.get(targetName));
junitTestResult.startTest((Test) testByTarget.get(targetName));
}
public void fireEndTest(String targetName) {
junitTestResult.endTest(testByTarget.get(targetName));
junitTestResult.endTest((Test) testByTarget.get(targetName));
}
public void fireError(String targetName, Throwable t) {
junitTestResult.addError(testByTarget.get(targetName), t);
junitTestResult.addError((Test) testByTarget.get(targetName), t);
}
public void fireFail(String targetName, AssertionFailedException ae) {
//I don't see how to transform the AntUnit assertion exception into
//I don't see how to transform the AntUnit assertion exception into
//junit assertion exception (we would loose the stack trace).
//So failures will be reported as errors
junitTestResult.addError(testByTarget.get(targetName), ae);
junitTestResult.addError((Test) testByTarget.get(targetName), ae);
}
}

View File

@ -20,6 +20,7 @@
package org.apache.ant.antunit.junit4;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@ -32,8 +33,8 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import junit.framework.Test;
import junit.framework.TestCase;
import org.apache.ant.antunit.AntUnitExecutionNotifier;
@ -59,40 +60,43 @@ import org.junit.runner.notification.RunNotifier;
* around every test target). Also, more features are available when this runner
* is used (filtering &amp; sorting)
*/
@SuppressWarnings("deprecation")
public class AntUnitSuiteRunner extends Runner implements Filterable, Sortable {
private final AntUnitSuite junit3Suite;
private final Map<String, Description> targetDescriptions = new HashMap<String, Description>();
private final List<String> targetsOrder = new LinkedList<String>();
private AntUnitSuiteRunner(AntUnitSuite suite, Class<?> junitTestClass) throws InitializationError {
private final Map/*<String, Description>*/ targetDescriptions = new HashMap();
private final List/*<String>*/ targetsOrder = new LinkedList();
private AntUnitSuiteRunner(AntUnitSuite suite, Class junitTestClass) throws InitializationError {
junit3Suite = suite;
if (suite.hasAntInitError()) {
throw new InitializationError(suite.getAntInitialisationException());
}
for (Enumeration<Test> tests = suite.tests(); tests.hasMoreElements();) {
TestCase nextTc = (TestCase) tests.nextElement();
//TODO Handle the possibility for the user to define suite of AntUnit scripts
AntUnitTestCase tc = (AntUnitTestCase) nextTc;
Description tc_desc = Description.createTestDescription(junitTestClass, tc.getName());
targetDescriptions.put(tc.getTarget(), tc_desc);
targetsOrder.add(tc.getTarget());
throw new InitializationError(
new Throwable[] { suite.getAntInitialisationException() }
);
} else {
Enumeration tests = suite.tests();
while (tests.hasMoreElements()) {
TestCase nextTc = (TestCase) tests.nextElement();
//TODO Handle the possibility for the user to define suite of AntUnit scripts
AntUnitTestCase tc = (AntUnitTestCase) nextTc;
Description tc_desc = Description.createTestDescription(junitTestClass, tc.getName());
targetDescriptions.put(tc.getTarget(), tc_desc);
targetsOrder.add(tc.getTarget());
}
}
}
public AntUnitSuiteRunner(Class<?> testCaseClass) throws InitializationError {
public AntUnitSuiteRunner(Class testCaseClass) throws InitializationError {
this(getJUnit3AntSuite(testCaseClass), testCaseClass);
}
private static AntUnitSuite getJUnit3AntSuite(Class<?> testCaseClass)
private static AntUnitSuite getJUnit3AntSuite(Class testCaseClass)
throws InitializationError {
try {
Method suiteMethod = testCaseClass.getMethod("suite");
Method suiteMethod = testCaseClass.getMethod("suite", new Class[0]);
if (!Modifier.isStatic(suiteMethod.getModifiers())) {
throw new InitializationError("suite method must be static");
}
Object suite = suiteMethod.invoke(null);
Object suite = suiteMethod.invoke(null, new Object[0]);
if (suite == null) {
throw new InitializationError("suite method can not return null");
}
@ -101,11 +105,11 @@ public class AntUnitSuiteRunner extends Runner implements Filterable, Sortable {
}
return (AntUnitSuite) suite;
} catch (NoSuchMethodException e) {
throw new InitializationError(e);
throw new InitializationError(new Throwable[] { e });
} catch (IllegalAccessException e) {
throw new InitializationError(e);
throw new InitializationError(new Throwable[] { e });
} catch (InvocationTargetException e) {
throw new InitializationError(e);
throw new InitializationError(new Throwable[] { e });
}
}
@ -113,13 +117,11 @@ public class AntUnitSuiteRunner extends Runner implements Filterable, Sortable {
* Filterable implementation
*/
public void filter(Filter filter) throws NoTestsRemainException {
for (Iterator<Map.Entry<String, Description>> iter =
targetDescriptions.entrySet().iterator(); iter.hasNext();) {
Map.Entry<String, Description> mapEntry = iter.next();
if (!filter.shouldRun(mapEntry.getValue())) {
for (Iterator iter= targetDescriptions.entrySet().iterator(); iter.hasNext();) {
Map.Entry mapEntry = (Entry) iter.next();
if (!filter.shouldRun((Description) mapEntry.getValue()))
iter.remove();
targetsOrder.remove(mapEntry.getKey());
}
}
}
@ -127,23 +129,28 @@ public class AntUnitSuiteRunner extends Runner implements Filterable, Sortable {
* Sortable implementation
*/
public void sort(final Sorter sorter) {
Collections.sort(targetsOrder, new Comparator<String>() {
public int compare(String target1, String target2) {
Description d2 = targetDescriptions.get(target2);
Description d1 = targetDescriptions.get(target1);
Collections.sort(targetsOrder, new Comparator/*<String>*/() {
public int compare(Object target1, Object target2) {
Description d2 = (Description)targetDescriptions.get(target2);
Description d1 = (Description)targetDescriptions.get(target1);
return sorter.compare(d1, d2);
}
});
/*for (Runner each : fRunners)
sorter.apply(each);
*/
}
/**
* Runner implementation
*/
public Description getDescription() {
Description r = Description.createSuiteDescription(junit3Suite.getName());
Collection<Description> childDesc = targetDescriptions.values();
for (Description desc : childDesc) {
Description r = Description.createSuiteDescription(
junit3Suite.getName(), new Annotation[0]);
Collection childDesc = targetDescriptions.values();
for (Iterator iterator = childDesc.iterator(); iterator.hasNext();) {
Description desc = (Description) iterator.next();
r.addChild(desc);
}
return r;
@ -153,14 +160,14 @@ public class AntUnitSuiteRunner extends Runner implements Filterable, Sortable {
* Runner implementation
*/
public void run(final RunNotifier junitNotifier) {
List<String> targetList = new LinkedList<String>(targetDescriptions.keySet());
AntUnitExecutionNotifier antUnitNotifier = new AntUnitExecutionNotifier() {
LinkedList targetList = new LinkedList(targetDescriptions.keySet());
AntUnitExecutionNotifier antUnitNotifier = new AntUnitExecutionNotifier() {
public void fireStartTest(String targetName) {
junitNotifier.fireTestStarted(getDescription(targetName));
}
public void fireEndTest(String targetName) {
junitNotifier.fireTestFinished(getDescription(targetName));
junitNotifier.fireTestFinished(getDescription(targetName));
}
public void fireError(String targetName, Throwable t) {
Failure failure = new Failure(getDescription(targetName), t);
@ -169,12 +176,12 @@ public class AntUnitSuiteRunner extends Runner implements Filterable, Sortable {
public void fireFail(String targetName, AssertionFailedException ae) {
Failure failure = new Failure(getDescription(targetName), ae);
junitNotifier.fireTestFailure(failure);
}
}
private Description getDescription(String targetName) {
return targetDescriptions.get(targetName);
return (Description) targetDescriptions.get(targetName);
}
};
junit3Suite.runInContainer(targetList, antUnitNotifier);
}

View File

@ -8,7 +8,7 @@
* with the License. You may obtain a copy of the License at
*
* https://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
@ -37,31 +37,27 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.LogOutputStream;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.KeepAliveOutputStream;
import org.apache.tools.ant.util.TeeOutputStream;
/**
* A test listener for &lt;antunit&gt; modeled aftern the Plain JUnit
* test listener that is part of Ant.
*/
public abstract class BaseAntUnitListener implements AntUnitListener {
public abstract class BaseAntUnitListener
implements AntUnitListener {
protected BaseAntUnitListener(SendLogTo defaultReportTarget,
String extension) {
logTo = defaultReportTarget;
this.extension = extension;
logLevel = BaseAntUnitListener.AntUnitLogLevel.NONE;
}
/**
* Formatter for timings.
*/
protected static final NumberFormat nf = NumberFormat.getInstance();
/**
* Create a new {@link BaseAntUnitListener} instance.
* @param defaultReportTarget
* @param extension
*/
protected BaseAntUnitListener(SendLogTo defaultReportTarget, String extension) {
logTo = defaultReportTarget;
this.extension = extension;
logLevel = BaseAntUnitListener.AntUnitLogLevel.NONE;
}
/**
* Directory to write reports to.
*/
@ -122,7 +118,9 @@ public abstract class BaseAntUnitListener implements AntUnitListener {
}
protected final void close(OutputStream out) {
FileUtils.close(out);
if (out != System.out && out != System.err) {
FileUtils.close(out);
}
}
public void startTest(String target) {
@ -137,43 +135,36 @@ public abstract class BaseAntUnitListener implements AntUnitListener {
}
protected final OutputStream getOut(String buildFile) {
final String dest = logTo.getValue();
if (logTo.getIndex() < 0) {
throw new BuildException(String.format("Invalid @sendlogto value '%s'", dest));
}
OutputStream l;
if (SendLogTo.ANT_LOG.equals(dest) || SendLogTo.BOTH.equals(dest)) {
OutputStream l, f;
l = f = null;
if (logTo.getValue().equals(SendLogTo.ANT_LOG)
|| logTo.getValue().equals(SendLogTo.BOTH)) {
if (parentTask != null) {
l = new LogOutputStream(parentTask, Project.MSG_INFO);
} else {
l = new KeepAliveOutputStream(System.out);
l = System.out;
}
if (SendLogTo.ANT_LOG.equals(dest)) {
if (logTo.getValue().equals(SendLogTo.ANT_LOG)) {
return l;
}
} else {
l = null;
}
OutputStream f;
if (logTo.getValue().equals(SendLogTo.FILE)
|| logTo.getValue().equals(SendLogTo.BOTH)) {
String fileName = "TEST-" + normalize(buildFile) + "." + extension;
File file;
if (toDir != null) {
file = new File(toDir, fileName);
} else if (parentTask == null) {
file = new File(fileName);
} else {
file = parentTask.getProject().resolveFile(fileName);
}
try {
f = new FileOutputStream(file);
} catch (IOException e) {
throw new BuildException(e);
}
if (SendLogTo.FILE.equals(dest)) {
return f;
String fileName = "TEST-" + normalize(buildFile) + "." + extension;
File file = toDir == null
? (parentTask != null
? parentTask.getProject().resolveFile(fileName)
: new File(fileName))
: new File(toDir, fileName);
try {
f = new FileOutputStream(file);
} catch (IOException e) {
throw new BuildException(e);
}
if (logTo.getValue().equals(SendLogTo.FILE)) {
return f;
}
}
return new TeeOutputStream(l, f);
}
@ -186,13 +177,18 @@ public abstract class BaseAntUnitListener implements AntUnitListener {
* @return the normalized name
*/
protected final String normalize(String buildFile) {
File base = parentTask != null ? parentTask.getProject().getBaseDir()
File base = parentTask != null
? parentTask.getProject().getBaseDir()
: new File(System.getProperty("user.dir"));
buildFile = FileUtils.getFileUtils().removeLeadingPath(base, new File(buildFile));
if (buildFile.length() > 0 && buildFile.charAt(0) == File.separatorChar) {
buildFile = FileUtils.getFileUtils()
.removeLeadingPath(base, new File(buildFile));
if (buildFile.length() > 0
&& buildFile.charAt(0) == File.separatorChar) {
buildFile = buildFile.substring(1);
}
return buildFile.replace('.', '_').replace(':', '_').replace(File.separatorChar, '.');
return buildFile.replace('.', '_').replace(':', '_')
.replace(File.separatorChar, '.');
}
protected final Location getLocation(Throwable t) {

View File

@ -8,7 +8,7 @@
* with the License. You may obtain a copy of the License at
*
* https://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
@ -38,27 +38,27 @@ import org.apache.tools.ant.util.FileUtils;
* This AntUnitListener creates a new buildfile with a target for each
* failed test target in the AntUnit run. The generated target calls
* the failed target (with setUp and tearDown if present in the called
* project).
* project).
* This is intended for rerunning just failed tests.
*/
public class FailureAntUnitListener extends BaseAntUnitListener {
/** LineSeparator just for beautifying the output. */
private static final String BR = System.getProperty("line.separator");
private static final String BR = System.getProperty("line.separator");
/** A sorted list (without duplicates) of failed tests. */
private static SortedSet<TestInfos> failedTests = new TreeSet<TestInfos>();
private static SortedSet failedTests = new TreeSet();
/** Where to write the generated buildfile. */
private static File failureBuildfile;
/** The current running test project. Needed for addError()/addFailure(). */
private Project currentTestProject;
/** The current running build file. Needed for addError()/addFailure(). */
private String currentBuildFile;
/** No-arg constructor. */
public FailureAntUnitListener() {
super(new BaseAntUnitListener.SendLogTo(SendLogTo.ANT_LOG), "txt");
@ -73,23 +73,23 @@ public class FailureAntUnitListener extends BaseAntUnitListener {
currentTestProject = testProject;
currentBuildFile = buildFile;
}
public void addError(String target, Throwable ae) {
super.addError(target, ae);
failedTests.add(new TestInfos(currentTestProject, currentBuildFile, target, ae.getMessage()));
}
public void addFailure(String target, AssertionFailedException ae) {
super.addFailure(target, ae);
failedTests.add(new TestInfos(currentTestProject, currentBuildFile, target, ae.getMessage()));
}
}
/** not in use */
public void endTest(String target) {
public void endTest(String target) {
}
public void endTestSuite(Project testProject, String buildFile) {
StringBuilder sb = new StringBuilder();
StringBuffer sb = new StringBuffer();
// <project> and antunit-target for direct run
sb.append("<project default=\"antunit\" xmlns:au=\"antlib:org.apache.ant.antunit\">");
sb.append(BR);
@ -102,23 +102,23 @@ public class FailureAntUnitListener extends BaseAntUnitListener {
sb.append(" </target>").append(BR);
sb.append(BR);
sb.append(BR);
// one target for each failed test
int testNumber = 0;
NumberFormat f = NumberFormat.getIntegerInstance();
for (Iterator<TestInfos> it = failedTests.iterator(); it.hasNext();) {
for (Iterator it = failedTests.iterator(); it.hasNext();) {
sb.append(" <target name=\"test");
sb.append(f.format(testNumber++));
sb.append("\">").append(BR);
TestInfos testInfos = it.next();
TestInfos testInfos = (TestInfos) it.next();
sb.append(testInfos);
sb.append(" </target>").append(BR);
sb.append(BR);
}
// close the <project>
sb.append("</project>").append(BR);
// write the whole file
try {
FileOutputStream fos = new FileOutputStream(failureBuildfile);
@ -130,40 +130,41 @@ public class FailureAntUnitListener extends BaseAntUnitListener {
throw new BuildException(e);
}
}
/**
* Class for collecting needed information about failed tests.
*/
public class TestInfos implements Comparable<TestInfos> {
public class TestInfos implements Comparable {
/** Does the project has a setUp target? */
boolean projectHasSetup = false;
/** Does the project has a tearDown target? */
boolean projectHasTearDown = false;
/** The called target. */
String target;
/** The buildfile of the project. */
String buildfile;
/** The error message which was shown. */
String errorMessage;
public TestInfos(Project project, String buildfile, String target, String errorMessage) {
projectHasSetup = project.getTargets().containsKey("setUp");
projectHasTearDown = project.getTargets().containsKey("tearDown");
this.buildfile = buildfile;
this.target = target;
this.target = target;
this.errorMessage = errorMessage;
}
/**
* Creates an &lt;ant&gt; call according to the stored information.
/**
* Creates an &lt;ant&gt; call according to the stored information.
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuilder sb = new StringBuilder();
StringBuffer sb = new StringBuffer();
// make the reader of the buildfile happy
sb.append(" <!-- ");
sb.append(errorMessage);
@ -190,10 +191,15 @@ public class FailureAntUnitListener extends BaseAntUnitListener {
sb.append(" </ant>").append(BR);
return sb.toString();
}
// Needed, so that a SortedSet could sort this class into the list.
public int compareTo(TestInfos other) {
return this.toString().compareTo((other).toString());
public int compareTo(Object other) {
if (!(other instanceof TestInfos)) {
return -1;
} else {
TestInfos that = (TestInfos)other;
return this.toString().compareTo(that.toString());
}
}
}

View File

@ -8,7 +8,7 @@
* with the License. You may obtain a copy of the License at
*
* https://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
@ -37,7 +37,7 @@ import org.apache.tools.ant.Project;
* test listener that is part of Ant.
*/
public class PlainAntUnitListener extends BaseAntUnitListener {
private OutputStream out;
private OutputStream out = null;
/**
* Helper to store intermediate output.
*/
@ -69,7 +69,9 @@ public class PlainAntUnitListener extends BaseAntUnitListener {
inner = new StringWriter();
wri = new PrintWriter(inner);
out = getOut(buildFile);
StringBuilder sb = new StringBuilder("Build File: ").append(buildFile).append(NEW_LINE);
StringBuffer sb = new StringBuffer("Build File: ");
sb.append(buildFile);
sb.append(NEW_LINE);
try {
out.write(sb.toString().getBytes());
out.flush();
@ -80,7 +82,7 @@ public class PlainAntUnitListener extends BaseAntUnitListener {
public void endTestSuite(Project testProject, String buildFile) {
long runTime = System.currentTimeMillis() - start;
StringBuilder sb = new StringBuilder("Tests run: ");
StringBuffer sb = new StringBuffer("Tests run: ");
sb.append(runCount);
sb.append(", Failures: ");
sb.append(failureCount);

View File

@ -8,7 +8,7 @@
* with the License. You may obtain a copy of the License at
*
* https://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
@ -96,15 +96,14 @@ public class XMLAntUnitListener extends BaseAntUnitListener {
Element propertiesElement =
DOMUtils.createChildElement(root, XMLConstants.PROPERTIES);
@SuppressWarnings("unchecked")
Hashtable<String,Object> propertiesMap = testProject.getProperties();
for (final Iterator<Map.Entry<String, Object>> iterator = propertiesMap.entrySet().iterator();
Hashtable propertiesMap = testProject.getProperties();
for (final Iterator iterator = propertiesMap.entrySet().iterator();
iterator.hasNext();) {
final Map.Entry<String, Object> property = iterator.next();
final Map.Entry property = (Map.Entry) iterator.next();
Element e = DOMUtils.createChildElement(propertiesElement,
XMLConstants.PROPERTY);
e.setAttribute(XMLConstants.ATTR_NAME,
property.getKey());
property.getKey().toString());
e.setAttribute(XMLConstants.ATTR_VALUE,
property.getValue().toString());
}
@ -123,7 +122,7 @@ public class XMLAntUnitListener extends BaseAntUnitListener {
log.setLength(0);
domWri.write(e, wri, 1, INDENT);
}
e = DOMUtils.createChildElement(root, XMLConstants.ATTR_TESTS);
e = DOMUtils.createChildElement(root, XMLConstants.ATTR_TESTS);
DOMUtils.appendText(e, String.valueOf(runCount));
domWri.write(e, wri, 1, INDENT);
e = DOMUtils.createChildElement(root, XMLConstants.ATTR_FAILURES);

View File

@ -22,8 +22,8 @@ package org.apache.ant.antunit.listener;
/**
* <p> Interface groups XML constants.
* Interface that groups all constants used throughout the <code>XML</code>
* documents that are generated by the <code>XMLJUnitResultFormatter</code>
* Interface that groups all constants used throughout the <tt>XML</tt>
* documents that are generated by the <tt>XMLJUnitResultFormatter</tt>
* As of now the DTD is:
* <pre>
* &lt;----------------- @todo describe DTDs ----------------------&gt;

View File

@ -49,36 +49,15 @@ public class AssertTest extends BuildFileTest {
public void testEqualsCasePass() {
testPass("assertEqualsCasePass");
}
public void testNotEqualsPass1() {
testPass("assertNotEqualsPass1");
}
public void testNotEqualsPass2() {
testPass("assertNotEqualsPass2");
}
public void testPropertySetPass() {
testPass("assertPropertySetPass");
}
public void testPropertyNotSetPass() {
testPass("assertPropertyNotSetPass");
}
public void testPropertyEqualsPass() {
testPass("assertPropertyEqualsPass");
}
public void testPropertyEqualsCasePass() {
testPass("assertPropertyEqualsCasePass");
}
public void testPropertyNotEqualsPass1() {
testPass("assertPropertyNotEqualsPass1");
}
public void testPropertyNotEqualsPass2() {
testPass("assertPropertyNotEqualsPass2");
}
public void testPropertyContains() {
testPass("assertPropertyContains");
}
public void testPropertyDoesntContain() {
testPass("assertPropertyDoesntContain");
}
public void testFileExistsPass() {
testPass("assertFileExistsPass");
}
@ -106,9 +85,6 @@ public class AssertTest extends BuildFileTest {
public void testReferenceSetPass() {
testPass("assertReferenceSetPass");
}
public void testReferenceIsNotSetPass() {
testPass("assertReferenceIsNotSetPass");
}
public void testReferenceIsTypePass() {
testPass("assertReferenceIsTypePass");
}
@ -125,18 +101,9 @@ public class AssertTest extends BuildFileTest {
public void testEqualsFail2() {
testFail("assertEqualsFail2", "Expected 'bar' but was 'BAR'");
}
public void testNotEqualsFail() {
testFail("assertNotEqualsFail", "Didn't expect 'bar' to be 'bar'");
}
public void testNotEqualsCaseFail() {
testFail("assertNotEqualsCaseFail", "Didn't expect 'bar' to be 'BAR'");
}
public void testPropertySetFail() {
testFail("assertPropertySetFail", "Expected property 'foo'");
}
public void testPropertyNotSetFail() {
testFail("assertPropertyNotSetFail", "Didn't expect property 'foo' to be set but was 'bar'");
}
public void testPropertyEqualsFail1() {
testFail("assertPropertyEqualsFail1", "Expected property 'foo' to have value 'bar' but was '${foo}'");
}
@ -146,21 +113,12 @@ public class AssertTest extends BuildFileTest {
public void testPropertyEqualsFail3() {
testFail("assertPropertyEqualsFail3", "Expected property 'foo' to have value 'BAR' but was 'bar'");
}
public void testPropertyNotEqualsFail1() {
testFail("assertPropertyNotEqualsFail1", "Didn't expect property 'foo' to have value 'bar'");
}
public void testPropertyNotEqualsFail2() {
testFail("assertPropertyNotEqualsFail2", "Didn't expect property 'foo' to have value 'bar'");
}
public void testPropertyNotEqualsCaseFail() {
testFail("assertPropertyNotEqualsCaseFail", "Didn't expect property 'foo' to have value 'BAR'");
public void testPropertyContains() {
testPass("assertPropertyContains");
}
public void testPropertyContainsFail() {
testFail("assertPropertyContainsFail", "Expected property 'foo' to contain value 'foo' but was 'bar'");
}
public void testPropertyDoesntContainFail() {
testFail("assertPropertyDoesntContainFail", "Didn't expect property 'foo' to contain value 'ba' but was 'bar'");
}
public void testFileExistsFail() {
testFail("assertFileExistsFail",
"Expected file 'assert.txt' to exist");
@ -196,9 +154,6 @@ public class AssertTest extends BuildFileTest {
public void testReferenceSetFail() {
testFail("assertReferenceSetFail", "Expected reference 'foo2'");
}
public void testReferenceIsNotSetFail() {
testFail("assertReferenceIsNotSetFail", "Didn't expect reference 'foo4'");
}
public void testReferenceIsTypeFailNotSet() {
testFail("assertReferenceIsTypeFailNotSet",
"Expected reference 'foo4'");

View File

@ -8,7 +8,7 @@
* with the License. You may obtain a copy of the License at
*
* https://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
@ -42,8 +42,8 @@ public class LogCapturerTest extends TestCase {
Project p = new Project();
LogCapturer c = new LogCapturer(p);
String[] messages = new String[] { "err", "warn", "info", "verbose", "debug" };
String[] messages = new String[] {"err", "warn", "info", "verbose",
"debug"};
for (int i = 0; i < messages.length; i++) {
BuildEvent be = new BuildEvent(p);
be.setMessage(messages[i], i);
@ -66,7 +66,8 @@ public class LogCapturerTest extends TestCase {
c.messageLogged(be);
}
Assert.assertEquals(c.getErrLog(false),
"0" + StringUtils.LINE_SEP + "1" + StringUtils.LINE_SEP);
"0" + StringUtils.LINE_SEP
+ "1" + StringUtils.LINE_SEP);
}
public void testWithMerge() {

View File

@ -8,7 +8,7 @@
* with the License. You may obtain a copy of the License at
*
* https://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
@ -52,18 +52,23 @@ public class LogContentTest extends TestCase {
Project p = new Project();
LogCapturer c = new LogCapturer(p);
String[] msgs = new String[] { "err", "warn", "info", "verbose", "debug" };
String[] msgs = new String[] {"err", "warn", "info", "verbose",
"debug"};
for (int i = 0; i < msgs.length; i++) {
BuildEvent be = new BuildEvent(p);
be.setMessage(msgs[i], i);
c.messageLogged(be);
}
assertMessages(new LogContent(p, LogLevel.ERR), msgs, Project.MSG_ERR);
assertMessages(new LogContent(p, LogLevel.WARN), msgs, Project.MSG_WARN);
assertMessages(new LogContent(p, LogLevel.INFO), msgs, Project.MSG_INFO);
assertMessages(new LogContent(p, LogLevel.VERBOSE), msgs, Project.MSG_VERBOSE);
assertMessages(new LogContent(p, LogLevel.DEBUG), msgs, Project.MSG_DEBUG);
assertMessages(new LogContent(p, LogLevel.ERR), msgs,
Project.MSG_ERR);
assertMessages(new LogContent(p, LogLevel.WARN), msgs,
Project.MSG_WARN);
assertMessages(new LogContent(p, LogLevel.INFO), msgs,
Project.MSG_INFO);
assertMessages(new LogContent(p, LogLevel.VERBOSE), msgs,
Project.MSG_VERBOSE);
assertMessages(new LogContent(p, LogLevel.DEBUG), msgs,
Project.MSG_DEBUG);
}
public void testWithoutMerge() throws IOException {
@ -80,7 +85,9 @@ public class LogContentTest extends TestCase {
StringResource s = new StringResource();
ResourceUtils.copyResource(content, s);
Assert.assertEquals(s.getValue(), "0" + StringUtils.LINE_SEP + "1" + StringUtils.LINE_SEP);
Assert.assertEquals(s.getValue(),
"0" + StringUtils.LINE_SEP
+ "1" + StringUtils.LINE_SEP);
}
public void testWithExplicitMerge() throws IOException {
@ -125,11 +132,11 @@ public class LogContentTest extends TestCase {
String actual = s.getValue();
for (int i = 0; i <= upTo && i < messages.length; i++) {
Assert.assertTrue("checking for " + messages[i] + " in " + actual,
actual.indexOf(messages[i]) > -1);
actual.indexOf(messages[i]) > -1);
}
for (int i = upTo + 1; i < messages.length; i++) {
Assert.assertTrue("checking for " + messages[i] + " in " + actual,
actual.indexOf(messages[i]) == -1);
actual.indexOf(messages[i]) == -1);
}
}
}

View File

@ -30,10 +30,10 @@ import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.Project;
public class SetUpAndTearDownTest extends BuildFileTest {
public static class TestReportListener extends BaseAntUnitListener {
private OutputStream out;
private OutputStream out = null;
/**
* Helper to store intermediate output.
*/
@ -82,12 +82,12 @@ public class SetUpAndTearDownTest extends BuildFileTest {
super.addFailure(target, ae);
wri.println("failure:" + target + "(" + ae.getMessage() + ")");
}
public void addError(String target, Throwable ae) {
super.addError(target, ae);
wri.println("error:" + target + "(" + ae.getMessage() + ")");
}
public void messageLogged(int level, String message) {}
}
@ -124,7 +124,7 @@ public class SetUpAndTearDownTest extends BuildFileTest {
int index = log.indexOf("Tests run: 3, Failures: 3, Errors: 0,");
assertTrue("summary", index > -1);
}
public void testErrorSetup() {
executeTarget("testErrorSetup");
String log = getLog();
@ -138,7 +138,7 @@ public class SetUpAndTearDownTest extends BuildFileTest {
int index = log.indexOf("Tests run: 3, Failures: 3, Errors: 0,");
assertTrue("summary", index > -1);
}
public void testErrorTeardown() {
executeTarget("testErrorTeardown");
String log = getLog();
@ -180,7 +180,7 @@ public class SetUpAndTearDownTest extends BuildFileTest {
index = log.indexOf("error:suiteSetUp(Expected error)");
assertTrue("testname", index > -1);
}
public void testFailureSuiteTearDown() {
executeTarget("testFailureSuiteTearDown");
String log = getLog();
@ -189,7 +189,7 @@ public class SetUpAndTearDownTest extends BuildFileTest {
index = log.indexOf("failure:suiteTearDown(Expected failure)");
assertTrue("testname", index > -1);
}
public void testErrorSuiteTearDown() {
executeTarget("testErrorSuiteTearDown");
String log = getLog();

View File

@ -23,7 +23,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@ -42,8 +42,10 @@ public class AntUnitSuiteRunnerTest extends TestCase {
/**
* Validates the execution sequence.
*/
public void testRunFullSuite() throws FileNotFoundException, IOException, InitializationError {
AntUnitSuiteRunner runner = new AntUnitSuiteRunner(JUnit4AntUnitRunnable.class);
public void testRunFullSuite() throws FileNotFoundException, IOException,
InitializationError {
AntUnitSuiteRunner runner = new AntUnitSuiteRunner(
JUnit4AntUnitRunnable.class);
runner.run(new RunNotifier());
File outFile = new File("target/test_output/junit_out.xml");
@ -51,46 +53,47 @@ public class AntUnitSuiteRunnerTest extends TestCase {
String output = FileUtils.readFully(new FileReader(outFile));
String EXPECT1 = "suiteSetUp-setUp-test1-tearDown-setUp-test2-tearDown-suiteTearDown";
String EXPECT2 = "suiteSetUp-setUp-test2-tearDown-setUp-test1-tearDown-suiteTearDown";
assertTrue("unexted output : " + output, EXPECT1.equals(output) || EXPECT2.equals(output));
assertTrue("unexted output : " + output, EXPECT1.equals(output)
|| EXPECT2.equals(output));
}
/**
* When a test is executed, the description used in the notification must be
* equals to the description declared, otherwise the runner is confused (for
* example in eclipse you have all the tests listed twice, but reported only
* once as executed.
*
*
* @throws InitializationError
*/
public void testDescriptionsReportedInNotifier() throws InitializationError {
final AntUnitSuiteRunner runner = new AntUnitSuiteRunner(
JUnit4AntUnitRunnable.class);
final List<Description> tDescs = runner.getDescription().getChildren();
final ArrayList tDescs = runner.getDescription().getChildren();
RunNotifier notifierMock = new RunNotifier() {
Description curTest = null;
public void fireTestStarted(Description description) {
if (curTest != null) {
mockExecutionError +=
"Unexpected fireTestStarted(" + description.getDisplayName() + "\n";
mockExecutionError += "Unexpected fireTestStarted("
+ description.getDisplayName() + "\n";
}
if (!tDescs.contains(description)) {
mockExecutionError +=
"Unexpected fireTestStarted(" + description.getDisplayName() + ")\n";
mockExecutionError += "Unexpected fireTestStarted("
+ description.getDisplayName() + ")\n";
}
curTest = description;
}
public void fireTestFinished(Description description) {
if (curTest == null) {
mockExecutionError +=
"Unexpected fireTestFinished(" + description.getDisplayName() + "\n";
mockExecutionError += "Unexpected fireTestFinished("
+ description.getDisplayName() + "\n";
}
if (!curTest.equals(description)) {
mockExecutionError +=
"Unexpected fireTestFinished(" + description.getDisplayName() + "); expect "
mockExecutionError += "Unexpected fireTestFinished("
+ description.getDisplayName() + "); expect "
+ curTest.getDisplayName() + "\n";
}
curTest = null;
@ -167,7 +170,8 @@ public class AntUnitSuiteRunnerTest extends TestCase {
public static class JUnit4AntUnitRunnableWithNonStaticSuite {
public AntUnitSuite suite() {
File f = new File("src/etc/testcases/antunit/junit.xml");
return new AntUnitSuite(f, JUnit4AntUnitRunnableWithNonStaticSuite.class);
return new AntUnitSuite(f,
JUnit4AntUnitRunnableWithNonStaticSuite.class);
}
}
@ -176,22 +180,23 @@ public class AntUnitSuiteRunnerTest extends TestCase {
public static class JUnit4AntUnitRunnableWithInvalidSuiteReturnType {
public static TestSuite suite() {
return new TestSuite(
"We don't support returning generic TestSuite. The Runner can not handle that");
return new TestSuite("We don't support returning generic TestSuite." +
" The Runner can not handle that");
}
}
public static class JUnit4AntUnitRunnableWithInvalidSuiteReturningNull {
public static TestSuite suite() {
return null;
}
}
public static class JUnit4AntUnitRunnableRefferencingIncorrectFile {
public static AntUnitSuite suite() {
File f = new File("build_script_not_found.xml");
return new AntUnitSuite(f, JUnit4AntUnitRunnableWithNonStaticSuite.class);
return new AntUnitSuite(f,
JUnit4AntUnitRunnableWithNonStaticSuite.class);
}
}

View File

@ -12,5 +12,4 @@
# 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.
artifact.version=1.5.1alpha
ant.core.version=1.10.13
artifact.version=1.4.1