add assertMatches assertion
git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/antunit/trunk@451040 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
34314ee4f7
commit
a3bc6e04fe
|
|
@ -18,6 +18,18 @@
|
|||
<first>Kevin</first>
|
||||
<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>
|
||||
|
|
@ -26,8 +38,4 @@
|
|||
<first>Steve</first>
|
||||
<last>Loughran</last>
|
||||
</name>
|
||||
<name>
|
||||
<first>Matt</first>
|
||||
<last>Benson</last>
|
||||
</name>
|
||||
</contributors>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -184,4 +184,10 @@ under the License.
|
|||
<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>
|
||||
|
|
|
|||
|
|
@ -224,4 +224,22 @@ under the License.
|
|||
</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>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue