Author: bodewig
Date: Fri May 2 16:40:26 2014
New Revision: 1591967
URL: http://svn.apache.org/r1591967
Log:
PR 43582 add a new AntUnitListener that immediately forwards all log output
Added:
ant/antlibs/antunit/trunk/docs/logforwarder.html
- copied, changed from r1591570,
ant/antlibs/antunit/trunk/docs/plainlistener.html
ant/antlibs/antunit/trunk/src/etc/testcases/listener/logforwarder.xml
- copied, changed from r1591570,
ant/antlibs/antunit/trunk/src/etc/testcases/listener/plainlistener.xml
ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/LogForwarder.java
(with props)
ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/LogForwarderTest.java
- copied, changed from r1591570,
ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/PlainListenerTest.java
Modified:
ant/antlibs/antunit/trunk/changes.xml
ant/antlibs/antunit/trunk/docs/antunit.html
ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/antlib.xml
Modified: ant/antlibs/antunit/trunk/changes.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/changes.xml?rev=1591967&r1=1591966&r2=1591967&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/changes.xml (original)
+++ ant/antlibs/antunit/trunk/changes.xml Fri May 2 16:40:26 2014
@@ -46,6 +46,11 @@
assertions work for non-filesystem resources unlike their
existing cousins of AntUnit 1.2.
</action>
+ <action type="add" issue="43582">
+ A new AntUnitListener named "logforwarder" can be attached to
+ forward any log output from the project under test to the
+ project running the AntUnit task immediately.
+ </action>
</release>
<release version="1.2" date="2011-08-16">
Modified: ant/antlibs/antunit/trunk/docs/antunit.html
URL:
http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/docs/antunit.html?rev=1591967&r1=1591966&r2=1591967&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/docs/antunit.html (original)
+++ ant/antlibs/antunit/trunk/docs/antunit.html Fri May 2 16:40:26 2014
@@ -158,12 +158,18 @@ public class LogCapturer {
<p>Creates a test listener that gets attached to the task.</p>
- <p>Two listeners are part of this antlib <a
- href="plainlistener.html"><plainlistener/></a> which
- creates reports similar to the "plain" <formatter> of the
- <junit> task and <a
- href="xmllistener.html"><xmllistener/></a> which is similar
- to the "xml" <formatter>.</p>
+ <p>Some listeners are part of this antlib:</p>
+
+ <ul>
+ <li><a href="plainlistener.html"><plainlistener/></a>
+ creates reports similar to the "plain" <formatter> of the
+ <junit> task.</li>
+ <li><a href="xmllistener.html"><xmllistener/></a> is similar
+ to the "xml" <formatter>.</li>
+ <li><a href="logforwarder.html"><logforwarder/></a>
+ forwards log output from the project under test to the project
+ executing the antunit task.</li>
+ </ul>
<h4>propertyset</h4>
Copied: ant/antlibs/antunit/trunk/docs/logforwarder.html (from r1591570,
ant/antlibs/antunit/trunk/docs/plainlistener.html)
URL:
http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/docs/logforwarder.html?p2=ant/antlibs/antunit/trunk/docs/logforwarder.html&p1=ant/antlibs/antunit/trunk/docs/plainlistener.html&r1=1591570&r2=1591967&rev=1591967&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/docs/plainlistener.html (original)
+++ ant/antlibs/antunit/trunk/docs/logforwarder.html Fri May 2 16:40:26 2014
@@ -20,45 +20,20 @@ under the License.
<head>
<meta http-equiv="Content-Language" content="en-us"></meta>
<link rel="stylesheet" type="text/css" href="style.css">
- <title>PlainListener AntUnit Listener</title>
+ <title>LogForwarder AntUnit Listener</title>
</head>
<body>
- <h2><a name="plainlistener">Plain AntUnit Listener</a></h2>
+ <h2><a name="logforwarder">LogForwarder</a></h2>
<h3>Description</h3>
- <p>Writes reports similar to the "plain" JUnit formatter.</p>
+ <p>Forwards any log output from the project under test to the
+ project running the AntUnit task immediately. This is different
+ from - for example - the plain listener which buffers the
+ log output and emits it after the test has finished.</p>
- <h3>Parameters</h3>
- <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">sendLogTo</td>
- <td valign="top">Where the output will be written to. Valid
- values are "ant" for Ant's logging system, "file" for a
- file and "both" for either of both. Defaults to "ant".</td>
- <td align="center">No.</td>
- </tr>
- <tr>
- <td valign="top">toDir</td>
- <td valign="top">Directory where testreports will be written
- to if writing to a file. 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>
+ <p>This listener can be used to debug failing tests more easily or
+ monitor tests in real time.</p>
</body>
</html>
Copied: ant/antlibs/antunit/trunk/src/etc/testcases/listener/logforwarder.xml
(from r1591570,
ant/antlibs/antunit/trunk/src/etc/testcases/listener/plainlistener.xml)
URL:
http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/etc/testcases/listener/logforwarder.xml?p2=ant/antlibs/antunit/trunk/src/etc/testcases/listener/logforwarder.xml&p1=ant/antlibs/antunit/trunk/src/etc/testcases/listener/plainlistener.xml&r1=1591570&r2=1591967&rev=1591967&view=diff
==============================================================================
--- ant/antlibs/antunit/trunk/src/etc/testcases/listener/plainlistener.xml
(original)
+++ ant/antlibs/antunit/trunk/src/etc/testcases/listener/logforwarder.xml Fri
May 2 16:40:26 2014
@@ -18,77 +18,16 @@ specific language governing permissions
under the License.
-->
-<project name="plainlistener-test"
- default="all"
+<project name="logforwarder-test" default="forward"
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">
+ <target name="forward">
<au:antunit failOnError="false">
<file file="${ant.file}" />
- <au:plainlistener logLevel="info" />
+ <au:logforwarder />
</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>
@@ -96,9 +35,5 @@ under the License.
<echo level="warning">warningmessage</echo>
<echo level="error">errormessage</echo>
</target>
-
- <target name="test2">
- <echo>test2</echo>
- </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?rev=1591967&r1=1591966&r2=1591967&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 Fri
May 2 16:40:26 2014
@@ -36,6 +36,9 @@ under the License.
<typedef name="failurelistener"
classname="org.apache.ant.antunit.listener.FailureAntUnitListener"/>
+ <typedef name="logforwarder"
+ classname="org.apache.ant.antunit.listener.LogForwarder"/>
+
<typedef name="logcapturer"
classname="org.apache.ant.antunit.LogCapturer"/>
Added:
ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/LogForwarder.java
URL:
http://svn.apache.org/viewvc/ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/LogForwarder.java?rev=1591967&view=auto
==============================================================================
---
ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/LogForwarder.java
(added)
+++
ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/LogForwarder.java
Fri May 2 16:40:26 2014
@@ -0,0 +1,64 @@
+/*
+ * 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.ant.antunit.AntUnitListener;
+import org.apache.ant.antunit.AssertionFailedException;
+
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.Project;
+
+/**
+ * A test listener for <antunit> who's whole purpose is to
+ * forward log output from the project under test to the project
+ * executing the <antunit> task.
+ */
+public class LogForwarder implements AntUnitListener {
+
+ private Task parentTask;
+
+ public void setParentTask(Task t) {
+ parentTask = t;
+ }
+
+ public void setCurrentTestProject(Project p) {
+ p.addBuildListener(new BuildListener() {
+ public void buildStarted(BuildEvent event) {}
+ public void buildFinished(BuildEvent event) {}
+ public void targetStarted(BuildEvent event) {}
+ public void targetFinished(BuildEvent event) {}
+ public void taskStarted(BuildEvent event) {}
+ public void taskFinished(BuildEvent event) {}
+ public void messageLogged(BuildEvent event) {
+ parentTask.log(event.getMessage(), event.getPriority());
+ }
+ });
+ }
+
+ public void startTestSuite(Project testProject, String buildFile) {}
+ public void endTestSuite(Project testProject, String buildFile) {}
+ public void startTest(String target) {}
+ public void endTest(String target) {}
+ public void addFailure(String target, AssertionFailedException ae) {}
+ public void addError(String target, Throwable ae) {}
+}
Propchange:
ant/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/listener/LogForwarder.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied:
ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/LogForwarderTest.java
(from r1591570,
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/LogForwarderTest.java?p2=ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/LogForwarderTest.java&p1=ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/PlainListenerTest.java&r1=1591570&r2=1591967&rev=1591967&view=diff
==============================================================================
---
ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/PlainListenerTest.java
(original)
+++
ant/antlibs/antunit/trunk/src/tests/junit/org/apache/ant/antunit/listener/LogForwarderTest.java
Fri May 2 16:40:26 2014
@@ -23,124 +23,21 @@ package org.apache.ant.antunit.listener;
import org.apache.tools.ant.BuildFileTest;
/**
- * Tests the plain listener.
+ * Tests the log forwarder.
*/
-public class PlainListenerTest extends BuildFileTest {
+public class LogForwarderTest extends BuildFileTest {
protected void setUp() throws Exception {
- configureProject("src/etc/testcases/listener/plainlistener.xml");
+ configureProject("src/etc/testcases/listener/logforwarder.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 testForward() {
+ executeTarget("forward");
+ assertLogContaining("infomessage");
+ assertLogContaining("warningmessage");
+ assertLogContaining("errormessage");
+ assertLogNotContaining("debugmessage");
+ assertLogNotContaining("verbosemessage");
+ assertDebuglogContaining("debugmessage");
+ assertDebuglogContaining("verbosemessage");
}
-
- 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
+}