You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2010/08/19 14:21:04 UTC
svn commit: r987139 - in /ant/core/trunk: ./ docs/manual/Tasks/
src/etc/testcases/taskdefs/optional/
src/main/org/apache/tools/ant/taskdefs/optional/junit/
src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/
Author: bodewig
Date: Thu Aug 19 12:21:03 2010
New Revision: 987139
URL: http://svn.apache.org/viewvc?rev=987139&view=rev
Log:
allow test listener events to be enabled by an attribute or a magic property - disable them by default
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/docs/manual/Tasks/junit.html
ant/core/trunk/src/etc/testcases/taskdefs/optional/junit.xml
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java
Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=987139&r1=987138&r2=987139&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Aug 19 12:21:03 2010
@@ -46,6 +46,12 @@ Changes that could break older environme
store their information are now excluded by the defaultexcludes.
Bugzilla Report 49624.
+ * The <junit> task no longer generates TestListener events - which
+ have been introduced in ant 1.7.0 - by default. The task has a new
+ attribute enableTestListenerEvents and a new "magic" property
+ ant.junit.enabletestlistenerevents has been added that can be used
+ to reinstate the old behavior.
+
Fixed bugs:
-----------
Modified: ant/core/trunk/docs/manual/Tasks/junit.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/Tasks/junit.html?rev=987139&r1=987138&r2=987139&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/Tasks/junit.html (original)
+++ ant/core/trunk/docs/manual/Tasks/junit.html Thu Aug 19 12:21:03 2010
@@ -235,6 +235,19 @@ elements</a>).</p>
<em>since Ant 1.8.0</em></td>
<td align="center" valign="top">No</td>
</tr>
+ <tr>
+ <td valign="top">enableTestListenerEvents</td>
+ <td valign="top">Whether Ant should send fine grained information
+ about the running tests to Ant's logging system at the verbose
+ level. Such events may be used by custom test listeners to show
+ the progress of tests.<br/>
+ Defaults to <code>false</code>.<br/>
+ Can be overridden by a <a href="#enabletestlistenerevents">magic
+ property</a>.<br/>
+ <em>since Ant 1.8.2</em> - <strong>Ant 1.7.0 to 1.8.1 behave as
+ if this attribute was true by default.</strong></td>
+ <td align="center" valign="top">No</td>
+ </tr>
</table>
<p>By using the <code>errorproperty</code> and <code>failureproperty</code>
@@ -635,6 +648,20 @@ supported.</p>
<p>to your <code>junit</code> task.</p>
+<h3><a name="enabletestlistenerevents"><code>ant.junit.enabletestlistenerevents</a>
+ magic property</h3>
+
+<p><em>Since Ant 1.8.2</em> the <code>enableTestListenerEvents</code>
+ attribute of the task controls whether fine grained logging messages
+ will be sent to the task's verbose log. In addition to this
+ attribute Ant will consult the
+ property <code>ant.junit.enabletestlistenerevents</code> and the
+ value of the property overrides the setting of the attribute.</p>
+
+<p>This property exists so that containers running Ant that depend on
+ the additional logging events can ensure they will be generated even
+ if the build file disables them.</p>
+
<h3>Examples</h3>
<pre>
Modified: ant/core/trunk/src/etc/testcases/taskdefs/optional/junit.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/optional/junit.xml?rev=987139&r1=987138&r2=987139&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/optional/junit.xml (original)
+++ ant/core/trunk/src/etc/testcases/taskdefs/optional/junit.xml Thu Aug 19 12:21:03 2010
@@ -104,7 +104,9 @@
<target name="captureToSummary">
<property name="fork" value="true"/>
- <junit fork="${fork}" printSummary="withOutAndErr">
+ <property name="enableEvents" value="false"/>
+ <junit fork="${fork}" printSummary="withOutAndErr"
+ enableTestListenerEvents="${enableEvents}">
<test name="org.apache.tools.ant.taskdefs.optional.junit.Printer"/>
<classpath refid="test"/>
</junit>
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java?rev=987139&r1=987138&r2=987139&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java Thu Aug 19 12:21:03 2010
@@ -165,6 +165,7 @@ public class JUnitTask extends Task {
private ForkMode forkMode = new ForkMode("perTest");
private boolean splitJunit = false;
+ private boolean enableTestListenerEvents = false;
private JUnitTaskMirror delegate;
private ClassLoader mirrorLoader;
@@ -186,6 +187,12 @@ public class JUnitTask extends Task {
public static final String TESTLISTENER_PREFIX =
"junit.framework.TestListener: ";
+ /**
+ * Name of magic property that enables test listener events.
+ */
+ public static final String ENABLE_TESTLISTENER_EVENTS =
+ "ant.junit.enabletestlistenerevents";
+
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
/**
@@ -673,6 +680,32 @@ public class JUnitTask extends Task {
}
/**
+ * Whether test listener events shall be generated.
+ *
+ * <p>Defaults to false.</p>
+ *
+ * <p>This value will be overridden by the magic property
+ * ant.junit.enabletestlistenerevents if it has been set.</p>
+ *
+ * @since Ant 1.8.2
+ */
+ public void setEnableTestListenerEvents(boolean b) {
+ enableTestListenerEvents = b;
+ }
+
+ /**
+ * Whether test listener events shall be generated.
+ * @since Ant 1.8.2
+ */
+ public boolean getEnableTestListenerEvents() {
+ String e = getProject().getProperty(ENABLE_TESTLISTENER_EVENTS);
+ if (e != null) {
+ return Project.toBoolean(e);
+ }
+ return enableTestListenerEvents;
+ }
+
+ /**
* Adds the jars or directories containing Ant, this task and
* JUnit to the classpath - this should make the forked JVM work
* without having to specify them directly.
@@ -953,8 +986,9 @@ public class JUnitTask extends Task {
cmd.createArgument().setValue(Constants.LOG_FAILED_TESTS
+ String.valueOf(logFailedTests));
- cmd.createArgument().setValue(
- Constants.LOGTESTLISTENEREVENTS + "true"); // #31885
+ // #31885
+ cmd.createArgument().setValue(Constants.LOGTESTLISTENEREVENTS
+ + String.valueOf(getEnableTestListenerEvents()));
StringBuffer formatterArg = new StringBuffer(STRING_BUFFER_SIZE);
final FormatterElement[] feArray = mergeFormatters(test);
@@ -1209,7 +1243,7 @@ public class JUnitTask extends Task {
/**
* Pass output sent to System.out to the TestRunner so it can
- * collect ot for the formatters.
+ * collect it for the formatters.
*
* @param output output coming from System.out
* @since Ant 1.5
@@ -1360,7 +1394,8 @@ public class JUnitTask extends Task {
runner = delegate.newJUnitTestRunner(test, test.getMethods(), test.getHaltonerror(),
test.getFiltertrace(),
test.getHaltonfailure(), false,
- true, classLoader);
+ getEnableTestListenerEvents(),
+ classLoader);
if (summary) {
JUnitTaskMirror.SummaryJUnitResultFormatterMirror f =
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java?rev=987139&r1=987138&r2=987139&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java Thu Aug 19 12:21:03 2010
@@ -45,18 +45,21 @@ public class JUnitTestListenerTest exten
}
public void testFullLogOutput() {
+ getProject().setProperty("enableEvents", "true");
executeTarget(PASS_TEST_TARGET);
assertTrue("expecting full log to have BuildListener events",
hasBuildListenerEvents(getFullLog()));
}
public void testNoLogOutput() {
+ getProject().setProperty("enableEvents", "true");
executeTarget(PASS_TEST_TARGET);
assertFalse("expecting log to not have BuildListener events",
hasBuildListenerEvents(getLog()));
}
public void testTestCountFired() {
+ getProject().setProperty("enableEvents", "true");
executeTarget(PASS_TEST_TARGET);
assertTrue("expecting test count message",
hasEventMessage(JUnitTask.TESTLISTENER_PREFIX +
@@ -64,6 +67,7 @@ public class JUnitTestListenerTest exten
}
public void testStartTestFired() {
+ getProject().setProperty("enableEvents", "true");
executeTarget(PASS_TEST_TARGET);
assertTrue("expecting test started message",
hasEventMessage(JUnitTask.TESTLISTENER_PREFIX +
@@ -71,12 +75,34 @@ public class JUnitTestListenerTest exten
}
public void testEndTestFired() {
+ getProject().setProperty("enableEvents", "true");
executeTarget(PASS_TEST_TARGET);
assertTrue("expecting test ended message",
hasEventMessage(JUnitTask.TESTLISTENER_PREFIX +
"endTest(" + PASS_TEST + ")"));
}
+ public void testNoFullLogOutputByDefault() {
+ executeTarget(PASS_TEST_TARGET);
+ assertFalse("expecting full log to not have BuildListener events",
+ hasBuildListenerEvents(getFullLog()));
+ }
+
+ public void testFullLogOutputMagicProperty() {
+ getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "true");
+ executeTarget(PASS_TEST_TARGET);
+ assertTrue("expecting full log to have BuildListener events",
+ hasBuildListenerEvents(getFullLog()));
+ }
+
+ public void testNoFullLogOutputMagicPropertyWins() {
+ getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "false");
+ getProject().setProperty("enableEvents", "true");
+ executeTarget(PASS_TEST_TARGET);
+ assertFalse("expecting full log to not have BuildListener events",
+ hasBuildListenerEvents(getFullLog()));
+ }
+
private boolean hasBuildListenerEvents(String log) {
return log.indexOf(JUnitTask.TESTLISTENER_PREFIX) >= 0;
}