From a3bc6e04fe26a8c84ac9dc8ca611d9f24950cdeb Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Thu, 28 Sep 2006 22:12:58 +0000 Subject: [PATCH] add assertMatches assertion git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/antunit/trunk@451040 13f79535-47bb-0310-9956-ffa450edef68 --- contributors.xml | 16 +++-- docs/assertions.html | 58 +++++++++++++++++++ src/etc/testcases/assert.xml | 6 ++ src/main/org/apache/ant/antunit/antlib.xml | 18 ++++++ .../org/apache/ant/antunit/AssertTest.java | 16 ++++- .../apache/ant/antunit/ExpectFailureTest.java | 15 ++++- 6 files changed, 121 insertions(+), 8 deletions(-) diff --git a/contributors.xml b/contributors.xml index 2d6c632..8256daa 100644 --- a/contributors.xml +++ b/contributors.xml @@ -18,6 +18,18 @@ Kevin Jackson + + Matt + Benson + + + Paul + King + + + Peter + Reilly + Stefan Bodewig @@ -26,8 +38,4 @@ Steve Loughran - - Matt - Benson - diff --git a/docs/assertions.html b/docs/assertions.html index e90d8b4..455661c 100644 --- a/docs/assertions.html +++ b/docs/assertions.html @@ -464,6 +464,64 @@ <assertReferenceIsType refid="classpath" type="path"/> +

assertMatches

+ +

Asserts that a string matches a given regular expression.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescriptionRequired
stringThe string to test.Yes
patternThe pattern to test the string against.Yes
casesensitive + Perform a case sensitive match. + Default is true. + No.
multiline + Perform a multi line match. + Default is false. + No.
singleline + This allows '.' to match new lines. + SingleLine is not to be confused with multiline, + SingleLine is a perl + regex term, it corresponds to dotall in java regex. + Default is false. + No.
+ +

Examples

+ +

Make the build fail if the property abc does not contain + "abc" regardless of case: +

+
+      <assertMatches string="${abc}" pattern="abc" 
+                     casesensitive="false"/>
+

assertLogContains

Asserts that the build log contains a given message.

diff --git a/src/etc/testcases/assert.xml b/src/etc/testcases/assert.xml index 214f0b6..1755f62 100644 --- a/src/etc/testcases/assert.xml +++ b/src/etc/testcases/assert.xml @@ -184,4 +184,10 @@ under the License. + + + + diff --git a/src/main/org/apache/ant/antunit/antlib.xml b/src/main/org/apache/ant/antunit/antlib.xml index 35516ee..fff8277 100644 --- a/src/main/org/apache/ant/antunit/antlib.xml +++ b/src/main/org/apache/ant/antunit/antlib.xml @@ -224,4 +224,22 @@ under the License. + + + + + + + + + + + + + + diff --git a/src/tests/junit/org/apache/ant/antunit/AssertTest.java b/src/tests/junit/org/apache/ant/antunit/AssertTest.java index 94af651..5a2f786 100644 --- a/src/tests/junit/org/apache/ant/antunit/AssertTest.java +++ b/src/tests/junit/org/apache/ant/antunit/AssertTest.java @@ -138,6 +138,10 @@ public class AssertTest extends BuildFileTest { "Expected reference 'foo5' to be a 'fileset'"); } + public void testMatches() { + executeTarget("assertMatches"); + } + private void testPass(String target) { executeTarget(target); } @@ -153,8 +157,16 @@ public class AssertTest extends BuildFileTest { } catch (AssertionFailedException e) { assertEquals(message, e.getMessage()); } catch (Throwable t) { - fail("Unexpected exception of type " + t.getClass() - + ", message '" + t.getMessage() + "'"); + if (t.getClass().getName().equals( + AssertionFailedException.class.getName())) { + // Some classloader issue! + assertEquals(message, t.getMessage()); + } else { + fail("Unexpected exception of type " + t.getClass() + + ", message '" + t.getMessage() + "'" + + "\nexpected exception of type " + + AssertionFailedException.class); + } } // end of try-catch } } diff --git a/src/tests/junit/org/apache/ant/antunit/ExpectFailureTest.java b/src/tests/junit/org/apache/ant/antunit/ExpectFailureTest.java index ce0ae0e..8467448 100644 --- a/src/tests/junit/org/apache/ant/antunit/ExpectFailureTest.java +++ b/src/tests/junit/org/apache/ant/antunit/ExpectFailureTest.java @@ -61,7 +61,18 @@ public class ExpectFailureTest extends BuildFileTest { executeTarget(target); fail("Expected an exception"); } catch (AssertionFailedException e) { - assertEquals(message, e.getMessage()); - } + assertEquals(message, e.getMessage()); + } catch (Throwable t) { + if (t.getClass().getName().equals( + AssertionFailedException.class.getName())) { + // Some classloader issue! + assertEquals(message, t.getMessage()); + } else { + fail("Unexpected exception of type " + t.getClass() + + ", message '" + t.getMessage() + "'" + + "\nexpected exception of type " + + AssertionFailedException.class); + } + } } }