From c3b4b5563d0b56e7bf370e12e7be2c649d37951a Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 6 May 2014 20:01:13 +0000 Subject: [PATCH] PR 56470 - merge messages in assertLogContains only when asked to git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/antunit/trunk@1592859 13f79535-47bb-0310-9956-ffa450edef68 --- docs/assertions.html | 14 +++++ .../org/apache/ant/antunit/LogContains.java | 19 +++++-- src/main/org/apache/ant/antunit/antlib.xml | 8 ++- src/tests/antunit/assertLogContains-test.xml | 52 +++++++++++++++++++ 4 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 src/tests/antunit/assertLogContains-test.xml diff --git a/docs/assertions.html b/docs/assertions.html index e56d04f..19db1b3 100644 --- a/docs/assertions.html +++ b/docs/assertions.html @@ -918,6 +918,13 @@ levels. One of "error", "warning", "info", "verbose", "debug". No + + mergeLines + Whether to merge messages into a single + line or split them into multiple lines. + No, defaults + to true +

assertLogDoesntContain

@@ -944,6 +951,13 @@ levels. One of "error", "warning", "info", "verbose", "debug". No + + mergeLines + Whether to merge messages into a single + line or split them into multiple lines. + No, defaults + to true +

assertResourceContains

diff --git a/src/main/org/apache/ant/antunit/LogContains.java b/src/main/org/apache/ant/antunit/LogContains.java index 36e0d76..b5531bd 100644 --- a/src/main/org/apache/ant/antunit/LogContains.java +++ b/src/main/org/apache/ant/antunit/LogContains.java @@ -37,6 +37,7 @@ public class LogContains extends ProjectComponent implements Condition { private String text; private int logLevel = Project.MSG_INFO; + private boolean mergeLines = true; /** * Test the log shall contain. @@ -52,6 +53,14 @@ public class LogContains extends ProjectComponent implements Condition { logLevel = echoLevel.getLevel(); } + /** + * Whether to merge messages into a single line or split them into + * multiple lines. + */ + public void setMergeLines(boolean b) { + mergeLines = b; + } + public boolean eval() { if (text == null) { throw new BuildException("the text attribute is required"); @@ -62,19 +71,19 @@ public class LogContains extends ProjectComponent implements Condition { String log; switch (logLevel) { case Project.MSG_ERR: - log = c.getErrLog(); + log = c.getErrLog(mergeLines); break; case Project.MSG_WARN: - log = c.getWarnLog(); + log = c.getWarnLog(mergeLines); break; case Project.MSG_INFO: - log = c.getInfoLog(); + log = c.getInfoLog(mergeLines); break; case Project.MSG_VERBOSE: - log = c.getVerboseLog(); + log = c.getVerboseLog(mergeLines); break; case Project.MSG_DEBUG: - log = c.getDebugLog(); + log = c.getDebugLog(mergeLines); break; default: diff --git a/src/main/org/apache/ant/antunit/antlib.xml b/src/main/org/apache/ant/antunit/antlib.xml index 53f27a9..4ed528b 100644 --- a/src/main/org/apache/ant/antunit/antlib.xml +++ b/src/main/org/apache/ant/antunit/antlib.xml @@ -350,11 +350,13 @@ under the License. + - + @@ -362,11 +364,13 @@ under the License. + - + diff --git a/src/tests/antunit/assertLogContains-test.xml b/src/tests/antunit/assertLogContains-test.xml new file mode 100644 index 0000000..6d84e4e --- /dev/null +++ b/src/tests/antunit/assertLogContains-test.xml @@ -0,0 +1,52 @@ + + + + + + + + 0 + 1 + + + + + + 0 + 1 + + + + + + 0 + 1 + + + +