ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r645829 - in /ant/antlibs/antunit/trunk: docs/ src/etc/testcases/listener/ src/main/org/apache/ant/antunit/listener/ src/tests/junit/org/apache/ant/antunit/listener/
Date Tue, 08 Apr 2008 10:30:49 GMT
Author: bodewig
Date: Tue Apr  8 03:30:44 2008
New Revision: 645829

URL: http://svn.apache.org/viewvc?rev=645829&view=rev
Log:
Add logging of messages to plainlistener, based on code submitted by David Jackman

Added:
    ant/antlibs/antunit/trunk/src/etc/testcases/listener/
    ant/antlibs/antunit/trunk/src/etc/testcases/listener/plainlistener.xml   (with props)
    ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/
    ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/PlainListenerTest.java
  (with props)
Modified:
    ant/antlibs/antunit/trunk/docs/plainlistener.html
    ant/antlibs/antunit/trunk/docs/xmllistener.html
    ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/PlainAntUnitListener.java

Modified: ant/antlibs/antunit/trunk/docs/plainlistener.html
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/docs/plainlistener.html?rev=645829&r1=645828&r2=645829&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/docs/plainlistener.html (original)
+++ ant/antlibs/antunit/trunk/docs/plainlistener.html Tue Apr  8 03:30:44 2008
@@ -51,7 +51,14 @@
             basedir.</td>
         <td align="center">No.</td>
       </tr>
+      <tr>
+        <td valign="top">logLevel</td>
+        <td valign="top">Log level for messages from the tests to
+        include in the report.  Must be one of: none, error, warn,
+        warning, info, verbose, and debug. Messages at the given level
+        or below will be included.</td>
+        <td align="center">No. Default is 'none'.</td>
+      </tr>
     </table>
-
   </body>
 </html>

Modified: ant/antlibs/antunit/trunk/docs/xmllistener.html
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/docs/xmllistener.html?rev=645829&r1=645828&r2=645829&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/docs/xmllistener.html (original)
+++ ant/antlibs/antunit/trunk/docs/xmllistener.html Tue Apr  8 03:30:44 2008
@@ -51,6 +51,14 @@
             to.  Defaults to the project's basedir.</td>
         <td align="center">No.</td>
       </tr>
+      <tr>
+        <td valign="top">logLevel</td>
+        <td valign="top">Log level for messages from the tests to
+        include in the report.  Must be one of: none, error, warn,
+        warning, info, verbose, and debug. Messages at the given level
+        or below will be included.</td>
+        <td align="center">No. Default is 'none'.</td>
+      </tr>
     </table>
 
     <h3>Examples</h3>

Added: ant/antlibs/antunit/trunk/src/etc/testcases/listener/plainlistener.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/listener/plainlistener.xml?rev=645829&view=auto
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/listener/plainlistener.xml (added)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/listener/plainlistener.xml Tue Apr  8 03:30:44
2008
@@ -0,0 +1,104 @@
+<?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 name="plainlistener-test"
+      default="all"
+         xmlns:au="antlib:org.apache.ant.antunit">
+
+
+  <target name="showdefault">
+    <au:antunit failOnError="false">
+      <file file="${ant.file}" />
+      <au:plainlistener />
+    </au:antunit>
+  </target>
+  
+  <target name="showerror">
+    <au:antunit failOnError="false">
+      <file file="${ant.file}" />
+      <au:plainlistener logLevel="error" />
+    </au:antunit>
+  </target>
+  
+  <target name="showwarning">
+    <au:antunit failOnError="false">
+      <file file="${ant.file}" />
+      <au:plainlistener logLevel="warning" />
+    </au:antunit>
+  </target>
+  
+  <target name="showinfo">
+    <au:antunit failOnError="false">
+      <file file="${ant.file}" />
+      <au:plainlistener logLevel="info" />
+    </au:antunit>
+  </target>
+  
+  <target name="showverbose">
+    <au:antunit failOnError="false">
+      <file file="${ant.file}" />
+      <au:plainlistener logLevel="verbose" />
+    </au:antunit>
+  </target>
+  
+  <target name="showdebug">
+    <au:antunit failOnError="false">
+      <file file="${ant.file}" />
+      <au:plainlistener logLevel="debug" />
+    </au:antunit>
+  </target>
+  
+  <target name="shownone">
+    <au:antunit failOnError="false">
+      <file file="${ant.file}" />
+      <au:plainlistener logLevel="none" />
+    </au:antunit>
+  </target>
+  
+
+  <target name="suiteSetUp">
+    <echo>suiteSetUp</echo>
+  </target>
+  
+  <target name="suiteTearDown">
+    <echo>suiteTearDown</echo>
+  </target>
+  
+  <target name="setUp">
+    <echo>setUp</echo>
+  </target>
+  
+  <target name="tearDown">
+    <echo>tearDown</echo>
+  </target>
+  
+  <target name="testEcho">
+    <echo level="debug">debugmessage</echo>
+    <echo level="verbose">verbosemessage</echo>
+    <echo level="info">infomessage</echo>
+    <echo level="warning">warningmessage</echo>
+    <echo level="error">errormessage</echo>
+  </target>
+  
+  <target name="test2">
+    <echo>test2</echo>
+  </target>
+         
+</project>

Propchange: ant/antlibs/antunit/trunk/src/etc/testcases/listener/plainlistener.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/antlibs/antunit/trunk/src/etc/testcases/listener/plainlistener.xml
------------------------------------------------------------------------------
    svn:executable = *

Modified: ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/PlainAntUnitListener.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/PlainAntUnitListener.java?rev=645829&r1=645828&r2=645829&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/PlainAntUnitListener.java
(original)
+++ ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/PlainAntUnitListener.java
Tue Apr  8 03:30:44 2008
@@ -27,6 +27,7 @@
 
 import org.apache.ant.antunit.AssertionFailedException;
 
+import org.apache.tools.ant.BuildEvent;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Location;
 import org.apache.tools.ant.Project;
@@ -45,6 +46,12 @@
      * Convenience layer on top of {@link #inner inner}.
      */
     private PrintWriter wri;
+    /**
+     * Collects log messages.
+     */
+    private StringBuffer log = new StringBuffer();
+
+    private static final String NEW_LINE = System.getProperty("line.separator");
 
     public PlainAntUnitListener() {
         super(new BaseAntUnitListener.SendLogTo(SendLogTo.ANT_LOG), "txt");
@@ -62,10 +69,9 @@
         inner = new StringWriter();
         wri = new PrintWriter(inner);
         out = getOut(buildFile);
-        String newLine = System.getProperty("line.separator");
         StringBuffer sb = new StringBuffer("Build File: ");
         sb.append(buildFile);
-        sb.append(newLine);
+        sb.append(NEW_LINE);
         try {
             out.write(sb.toString().getBytes());
             out.flush();
@@ -76,7 +82,6 @@
 
     public void endTestSuite(Project testProject, String buildFile) {
         long runTime = System.currentTimeMillis() - start;
-        String newLine = System.getProperty("line.separator");
         StringBuffer sb = new StringBuffer("Tests run: ");
         sb.append(runCount);
         sb.append(", Failures: ");
@@ -86,7 +91,16 @@
         sb.append(", Time elapsed: ");
         sb.append(nf.format(runTime/ 1000.0));
         sb.append(" sec");
-        sb.append(newLine);
+        sb.append(NEW_LINE);
+
+        if (log.length() > 0) {
+            sb.append("------------- Log Output       ---------------");
+            sb.append(NEW_LINE);
+            sb.append(log.toString());
+            log.setLength(0);
+            sb.append("------------- ---------------- ---------------");
+            sb.append(NEW_LINE);
+        }
 
         if (out != null) {
             try {
@@ -133,6 +147,11 @@
         }
         wri.println("\tMessage: " + t.getMessage());
         wri.print("\t");
+    }
+
+    protected void messageLogged(BuildEvent event) {
+        log.append(event.getMessage());
+        log.append(NEW_LINE);
     }
 
 }

Added: ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/PlainListenerTest.java
URL: http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/PlainListenerTest.java?rev=645829&view=auto
==============================================================================
--- ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/PlainListenerTest.java
(added)
+++ ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/PlainListenerTest.java
Tue Apr  8 03:30:44 2008
@@ -0,0 +1,148 @@
+/*
+ * 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.
+ *
+ */
+
+package org.apache.ant.antunit.listener;
+
+import org.apache.tools.ant.BuildFileTest;
+
+/**
+ * Tests the plain listener.
+ */
+public class PlainListenerTest extends BuildFileTest {
+    protected void setUp() throws Exception {
+        configureProject("src/etc/testcases/listener/plainlistener.xml");
+    }
+
+    public void testStdoutPlacement() {
+        executeTarget("showinfo");
+        String log = getLog();
+        int indexElapsed = log.indexOf("Time elapsed");
+        int indexTarget = log.indexOf("Target");
+        int index = log.indexOf("------------- Log Output       ---------------");
+        assertTrue("Standard output message not present", index > -1);
+        assertTrue("Standard output message not located after summary.", index > indexElapsed);
+        assertTrue("Standard output message not located before test details.", index <
indexTarget);
+        int indexTest1 = log.indexOf("infomessage", index);
+        int indexTest2 = log.indexOf("test2", index);
+        assertTrue("infomessage", indexTest1 > -1);
+        assertTrue("test2", indexTest2 > -1);
+        index = log.indexOf("------------- ---------------- ---------------", Math.max(indexTest1,
indexTest2));
+        assertTrue("End of standard output message not present.", index > -1);
+        assertTrue("End of standard output message not located before test details.", index
< indexTarget);
+    }
+    
+    public void testShowDefault() {
+        executeTarget("showdefault");
+        String log = getLog();
+        assertTrue("Should not have shown error message", -1 == log.indexOf("errormessage"));
+        assertTrue("Should not have shown warning message", -1 == log.indexOf("warningmessage"));
+        assertTrue("Should not have shown info message", -1 == log.indexOf("infomessage"));
+        assertTrue("Should not have shown verbose message", -1 == log.indexOf("verbosemessage"));
+        assertTrue("Should not have shown debug message", -1 == log.indexOf("debugmessage"));
+    }
+    
+    public void testShowError() {
+        executeTarget("showerror");
+        String log = getLog();
+        assertTrue("Should have shown error message", -1 != log.indexOf("errormessage"));
+        assertTrue("Should not have shown warning message", -1 == log.indexOf("warningmessage"));
+        assertTrue("Should not have shown info message", -1 == log.indexOf("infomessage"));
+        assertTrue("Should not have shown verbose message", -1 == log.indexOf("verbosemessage"));
+        assertTrue("Should not have shown debug message", -1 == log.indexOf("debugmessage"));
+    }
+    
+    public void testShowWarning() {
+        executeTarget("showwarning");
+        String log = getLog();
+        assertTrue("Should have shown error message", -1 != log.indexOf("errormessage"));
+        assertTrue("Should have shown warning message", -1 != log.indexOf("warningmessage"));
+        assertTrue("Should not have shown info message", -1 == log.indexOf("infomessage"));
+        assertTrue("Should not have shown verbose message", -1 == log.indexOf("verbosemessage"));
+        assertTrue("Should not have shown debug message", -1 == log.indexOf("debugmessage"));
+    }
+    
+    public void testShowInfo() {
+        executeTarget("showinfo");
+        String log = getLog();
+        assertTrue("Should have shown error message", -1 != log.indexOf("errormessage"));
+        assertTrue("Should have shown warning message", -1 != log.indexOf("warningmessage"));
+        assertTrue("Should have shown info message", -1 != log.indexOf("infomessage"));
+        assertTrue("Should not have shown verbose message", -1 == log.indexOf("verbosemessage"));
+        assertTrue("Should not have shown debug message", -1 == log.indexOf("debugmessage"));
+    }
+    
+    public void testShowVerbose() {
+        executeTarget("showverbose");
+        String log = getLog();
+        assertTrue("Should have shown error message", -1 != log.indexOf("errormessage"));
+        assertTrue("Should have shown warning message", -1 != log.indexOf("warningmessage"));
+        assertTrue("Should have shown info message", -1 != log.indexOf("infomessage"));
+        assertTrue("Should have shown verbose message", -1 != log.indexOf("verbosemessage"));
+        assertTrue("Should not have shown debug message", -1 == log.indexOf("debugmessage"));
+    }
+    
+    public void testShowDebug() {
+        executeTarget("showdebug");
+        String log = getLog();
+        assertTrue("Should have shown error message", -1 != log.indexOf("errormessage"));
+        assertTrue("Should have shown warning message", -1 != log.indexOf("warningmessage"));
+        assertTrue("Should have shown info message", -1 != log.indexOf("infomessage"));
+        assertTrue("Should have shown verbose message", -1 != log.indexOf("verbosemessage"));
+        assertTrue("Should have shown debug message", -1 != log.indexOf("debugmessage"));
+    }
+
+    public void testShowNone() {
+        executeTarget("shownone");
+        String log = getLog();
+        assertTrue("Should not have shown error message", -1 == log.indexOf("errormessage"));
+        assertTrue("Should not have shown warning message", -1 == log.indexOf("warningmessage"));
+        assertTrue("Should not have shown info message", -1 == log.indexOf("infomessage"));
+        assertTrue("Should not have shown verbose message", -1 == log.indexOf("verbosemessage"));
+        assertTrue("Should not have shown debug message", -1 == log.indexOf("debugmessage"));
+    }
+
+    public void testSetUpTearDown() {
+        executeTarget("showinfo");
+        String log = getLog();
+        int index = log.indexOf("setUp");
+        assertTrue("First setUp not present", index > -1);
+        index = log.indexOf("setUp", index);
+        assertTrue("Second setUp not present", index > -1);
+        index = log.indexOf("tearDown");
+        assertTrue("First tearDown not present", index > -1);
+        index = log.indexOf("tearDown", index);
+        assertTrue("Second tearDown not present", index > -1);
+    }
+    
+    /*
+    public void testSuiteSetUpTearDown() {
+        executeTarget("showinfo");
+        String log = getLog();
+        int index = log.indexOf("suiteSetUp");
+        assertTrue("suiteSetUp not present", index > -1);
+        index = log.indexOf("suiteSetUp", index + 1);
+        assertTrue("suiteSetUp present more than once", index == -1);
+        index = log.indexOf("suiteTearDown");
+        assertTrue("suiteTearDown not present", index > -1);
+        index = log.indexOf("suiteTearDown", index + 1);
+        assertTrue("suiteTearDown present more than once", index == -1);
+    }
+    */
+}
\ No newline at end of file

Propchange: ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/PlainListenerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/PlainListenerTest.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message