ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1592859 - in /ant/antlibs/antunit/trunk: docs/assertions.html src/main/org/apache/ant/antunit/LogContains.java src/main/org/apache/ant/antunit/antlib.xml src/tests/antunit/assertLogContains-test.xml
Date Tue, 06 May 2014 20:01:14 GMT
Author: bodewig
Date: Tue May  6 20:01:13 2014
New Revision: 1592859

URL: http://svn.apache.org/r1592859
Log:
PR 56470 - merge messages in assertLogContains only when asked to

Added:
    ant/antlibs/antunit/trunk/src/tests/antunit/assertLogContains-test.xml   (with props)
Modified:
    ant/antlibs/antunit/trunk/docs/assertions.html
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml

Modified: ant/antlibs/antunit/trunk/docs/assertions.html
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/docs/assertions.html?rev=1592859&r1=1592858&r2=1592859&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/docs/assertions.html (original)
+++ ant/antlibs/antunit/trunk/docs/assertions.html Tue May  6 20:01:13 2014
@@ -918,6 +918,13 @@
           levels.  One of "error", "warning", "info", "verbose", "debug".</td>
           <td valign="top" align="center">No</td>
         </tr>
+        <tr>
+          <td valign="top">mergeLines</td>
+          <td valign="top">Whether to merge messages into a single
+            line or split them into multiple lines.</td>
+          <td valign="top" align="center">No, defaults
+            to <code>true</code></td>
+        </tr>
     </table>
 
     <h2><a name="assertLogDoesntContain">assertLogDoesntContain</a></h2>
@@ -944,6 +951,13 @@
           levels.  One of "error", "warning", "info", "verbose", "debug".</td>
           <td valign="top" align="center">No</td>
         </tr>
+        <tr>
+          <td valign="top">mergeLines</td>
+          <td valign="top">Whether to merge messages into a single
+            line or split them into multiple lines.</td>
+          <td valign="top" align="center">No, defaults
+            to <code>true</code></td>
+        </tr>
     </table>
 
     <h2><a name="assertResourceContains">assertResourceContains</a></h2>

Modified: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java?rev=1592859&r1=1592858&r2=1592859&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java (original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogContains.java Tue May  6
20:01:13 2014
@@ -37,6 +37,7 @@ public class LogContains extends Project
 
     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 Project
         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 Project
             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:

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?rev=1592859&r1=1592858&r2=1592859&view=diff
==============================================================================
--- 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 Tue May  6 20:01:13
2014
@@ -350,11 +350,13 @@ under the License.
   <macrodef name="assertLogContains" backtrace="false">
     <attribute name="text"/>
     <attribute name="level" default="info"/>
+    <attribute name="mergeLines" default="true"/>
     <attribute name="message"
       default="Expected log to contain '@{text}' at level @{level}"/>
     <sequential>
       <au:fail message="@{message}">
-        <au:logcontains text="@{text}" level="@{level}"/>
+        <au:logcontains text="@{text}" level="@{level}"
+                        mergeLines="@{mergeLines}"/>
       </au:fail>
     </sequential>
   </macrodef>
@@ -362,11 +364,13 @@ under the License.
   <macrodef name="assertLogDoesntContain" backtrace="false">
     <attribute name="text"/>
     <attribute name="level" default="info"/>
+    <attribute name="mergeLines" default="true"/>
     <attribute name="message"
       default="Unexpected log '@{text}' at level @{level}"/>
     <sequential>
       <au:assertFalse message="@{message}">
-        <au:logcontains text="@{text}" level="@{level}"/>
+        <au:logcontains text="@{text}" level="@{level}"
+                        mergeLines="@{mergeLines}"/>
       </au:assertFalse>
     </sequential>
   </macrodef>

Added: ant/antlibs/antunit/trunk/src/tests/antunit/assertLogContains-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/tests/antunit/assertLogContains-test.xml?rev=1592859&view=auto
==============================================================================
--- ant/antlibs/antunit/trunk/src/tests/antunit/assertLogContains-test.xml (added)
+++ ant/antlibs/antunit/trunk/src/tests/antunit/assertLogContains-test.xml Tue May  6 20:01:13
2014
@@ -0,0 +1,52 @@
+<?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
+
+      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.
+-->
+<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit">
+
+  <import file="antunit-base.xml"/>
+
+  <target name="testWithoutMerge">
+    <echo>0</echo>
+    <echo>1</echo>
+    <au:assertLogContains
+        mergeLines="false"
+        text="0${line.separator}1${line.separator}"/>
+    <au:assertLogDoesntContain
+        mergeLines="false"
+        text="01"/>
+  </target>
+
+  <target name="testWithExplicitMerge">
+    <echo>0</echo>
+    <echo>1</echo>
+    <au:assertLogDoesntContain
+        mergeLines="true"
+        text="0${line.separator}1${line.separator}"/>
+    <au:assertLogContains
+        mergeLines="true"
+        text="01"/>
+  </target>
+
+  <target name="testWithImplicitMerge">
+    <echo>0</echo>
+    <echo>1</echo>
+    <au:assertLogDoesntContain
+        text="0${line.separator}1${line.separator}"/>
+    <au:assertLogContains
+        text="01"/>
+  </target>
+</project>

Propchange: ant/antlibs/antunit/trunk/src/tests/antunit/assertLogContains-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message