Author: peterreilly Date: Thu Sep 28 15:12:58 2006 New Revision: 451040 URL: http://svn.apache.org/viewvc?view=rev&rev=451040 Log: add assertMatches assertion
Modified: ant/antlibs/antunit/trunk/contributors.xml ant/antlibs/antunit/trunk/docs/assertions.html ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/ExpectFailureTest.java Modified: ant/antlibs/antunit/trunk/contributors.xml URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/contributors.xml?view=diff&rev=451040&r1=451039&r2=451040 ============================================================================== --- ant/antlibs/antunit/trunk/contributors.xml (original) +++ ant/antlibs/antunit/trunk/contributors.xml Thu Sep 28 15:12:58 2006 @@ -19,15 +19,23 @@ <last>Jackson</last> </name> <name> + <first>Matt</first> + <last>Benson</last> + </name> + <name> + <first>Paul</first> + <last>King</last> + </name> + <name> + <first>Peter</first> + <last>Reilly</last> + </name> + <name> <first>Stefan</first> <last>Bodewig</last> </name> <name> <first>Steve</first> <last>Loughran</last> - </name> - <name> - <first>Matt</first> - <last>Benson</last> </name> </contributors> Modified: ant/antlibs/antunit/trunk/docs/assertions.html URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/docs/assertions.html?view=diff&rev=451040&r1=451039&r2=451040 ============================================================================== --- ant/antlibs/antunit/trunk/docs/assertions.html (original) +++ ant/antlibs/antunit/trunk/docs/assertions.html Thu Sep 28 15:12:58 2006 @@ -464,6 +464,64 @@ <assertReferenceIsType refid="classpath" type="path"/> </pre> + <h2><a name="assertMatches">assertMatches</a></h2> + + <p>Asserts that a string matches a given regular expression.</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">string</td> + <td valign="top">The string to test.</td> + <td valign="top" align="center">Yes</td> + </tr> + <tr> + <td valign="top">pattern</td> + <td valign="top">The pattern to test the string against.</td> + <td valign="top" align="center">Yes</td> + </tr> + <tr> + <td valign="top">casesensitive</td> + <td valign="top"> + Perform a case sensitive match. + Default is true. + </td> + <td align="center">No.</td> + </tr> + <tr> + <td valign="top">multiline</td> + <td valign="top"> + Perform a multi line match. + Default is false. + </td> + <td align="center">No.</td> + </tr> + <tr> + <td valign="top">singleline</td> + <td valign="top"> + 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. + </td> + <td align="center">No.</td> + </tr> + </table> + + <h3>Examples</h3> + + <p>Make the build fail if the property abc does not contain + "abc" regardless of case: + </p> + <pre> + <assertMatches string="${abc}" pattern="abc" + casesensitive="false"/></pre> + <h2><a name="assertLogContains">assertLogContains</a></h2> <p>Asserts that the build log contains a given message.</p> Modified: ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml?view=diff&rev=451040&r1=451039&r2=451040 ============================================================================== --- ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml (original) +++ ant/antlibs/antunit/trunk/src/etc/testcases/assert.xml Thu Sep 28 15:12:58 2006 @@ -184,4 +184,10 @@ <path id="foo5"/> <au:assertReferenceIsType refid="foo5" type="fileset"/> </target> + + <target name="assertMatches"> + <au:assertMatches string="this is AbC" + pattern="abc" + casesensitive="false"/> + </target> </project> Modified: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml?view=diff&rev=451040&r1=451039&r2=451040 ============================================================================== --- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml (original) +++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml Thu Sep 28 15:12:58 2006 @@ -224,4 +224,22 @@ </sequential> </macrodef> + <macrodef name="assertMatches" backtrace="false"> + <attribute name="string"/> + <attribute name="pattern"/> + <attribute name="casesensitive" default="false"/> + <attribute name="singleline" default="false"/> + <attribute name="multiline" default="false"/> + <attribute name="message" + default="Expected '@{string}' to match pattern '@{pattern}'"/> + <sequential> + <au:assertTrue message="@{message}"> + <matches string="@{string}" pattern="@{pattern}" + casesensitive="@{casesensitive}" + singleline="@{singleline}" + multiline="@{multiline}"/> + </au:assertTrue> + </sequential> + </macrodef> + </antlib> Modified: ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java?view=diff&rev=451040&r1=451039&r2=451040 ============================================================================== --- ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java (original) +++ ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/AssertTest.java Thu Sep 28 15:12:58 2006 @@ -138,6 +138,10 @@ "Expected reference 'foo5' to be a 'fileset'"); } + public void testMatches() { + executeTarget("assertMatches"); + } + private void testPass(String target) { executeTarget(target); } @@ -153,8 +157,16 @@ } 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 } } Modified: ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/ExpectFailureTest.java URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/ExpectFailureTest.java?view=diff&rev=451040&r1=451039&r2=451040 ============================================================================== --- ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/ExpectFailureTest.java (original) +++ ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/ExpectFailureTest.java Thu Sep 28 15:12:58 2006 @@ -61,7 +61,18 @@ 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); + } + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]