git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@987139 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -46,6 +46,12 @@ Changes that could break older environments: | |||||
| store their information are now excluded by the defaultexcludes. | store their information are now excluded by the defaultexcludes. | ||||
| Bugzilla Report 49624. | 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: | Fixed bugs: | ||||
| ----------- | ----------- | ||||
| @@ -235,6 +235,19 @@ elements</a>).</p> | |||||
| <em>since Ant 1.8.0</em></td> | <em>since Ant 1.8.0</em></td> | ||||
| <td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
| </tr> | </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> | </table> | ||||
| <p>By using the <code>errorproperty</code> and <code>failureproperty</code> | <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> | <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> | <h3>Examples</h3> | ||||
| <pre> | <pre> | ||||
| @@ -104,7 +104,9 @@ | |||||
| <target name="captureToSummary"> | <target name="captureToSummary"> | ||||
| <property name="fork" value="true"/> | <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"/> | <test name="org.apache.tools.ant.taskdefs.optional.junit.Printer"/> | ||||
| <classpath refid="test"/> | <classpath refid="test"/> | ||||
| </junit> | </junit> | ||||
| @@ -165,6 +165,7 @@ public class JUnitTask extends Task { | |||||
| private ForkMode forkMode = new ForkMode("perTest"); | private ForkMode forkMode = new ForkMode("perTest"); | ||||
| private boolean splitJunit = false; | private boolean splitJunit = false; | ||||
| private boolean enableTestListenerEvents = false; | |||||
| private JUnitTaskMirror delegate; | private JUnitTaskMirror delegate; | ||||
| private ClassLoader mirrorLoader; | private ClassLoader mirrorLoader; | ||||
| @@ -186,6 +187,12 @@ public class JUnitTask extends Task { | |||||
| public static final String TESTLISTENER_PREFIX = | public static final String TESTLISTENER_PREFIX = | ||||
| "junit.framework.TestListener: "; | "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(); | private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | ||||
| /** | /** | ||||
| @@ -672,6 +679,32 @@ public class JUnitTask extends Task { | |||||
| this.tmpDir = tmpDir; | this.tmpDir = tmpDir; | ||||
| } | } | ||||
| /** | |||||
| * 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 | * Adds the jars or directories containing Ant, this task and | ||||
| * JUnit to the classpath - this should make the forked JVM work | * JUnit to the classpath - this should make the forked JVM work | ||||
| @@ -953,8 +986,9 @@ public class JUnitTask extends Task { | |||||
| cmd.createArgument().setValue(Constants.LOG_FAILED_TESTS | cmd.createArgument().setValue(Constants.LOG_FAILED_TESTS | ||||
| + String.valueOf(logFailedTests)); | + 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); | StringBuffer formatterArg = new StringBuffer(STRING_BUFFER_SIZE); | ||||
| final FormatterElement[] feArray = mergeFormatters(test); | 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 | * 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 | * @param output output coming from System.out | ||||
| * @since Ant 1.5 | * @since Ant 1.5 | ||||
| @@ -1360,7 +1394,8 @@ public class JUnitTask extends Task { | |||||
| runner = delegate.newJUnitTestRunner(test, test.getMethods(), test.getHaltonerror(), | runner = delegate.newJUnitTestRunner(test, test.getMethods(), test.getHaltonerror(), | ||||
| test.getFiltertrace(), | test.getFiltertrace(), | ||||
| test.getHaltonfailure(), false, | test.getHaltonfailure(), false, | ||||
| true, classLoader); | |||||
| getEnableTestListenerEvents(), | |||||
| classLoader); | |||||
| if (summary) { | if (summary) { | ||||
| JUnitTaskMirror.SummaryJUnitResultFormatterMirror f = | JUnitTaskMirror.SummaryJUnitResultFormatterMirror f = | ||||
| @@ -45,18 +45,21 @@ public class JUnitTestListenerTest extends BuildFileTest { | |||||
| } | } | ||||
| public void testFullLogOutput() { | public void testFullLogOutput() { | ||||
| getProject().setProperty("enableEvents", "true"); | |||||
| executeTarget(PASS_TEST_TARGET); | executeTarget(PASS_TEST_TARGET); | ||||
| assertTrue("expecting full log to have BuildListener events", | assertTrue("expecting full log to have BuildListener events", | ||||
| hasBuildListenerEvents(getFullLog())); | hasBuildListenerEvents(getFullLog())); | ||||
| } | } | ||||
| public void testNoLogOutput() { | public void testNoLogOutput() { | ||||
| getProject().setProperty("enableEvents", "true"); | |||||
| executeTarget(PASS_TEST_TARGET); | executeTarget(PASS_TEST_TARGET); | ||||
| assertFalse("expecting log to not have BuildListener events", | assertFalse("expecting log to not have BuildListener events", | ||||
| hasBuildListenerEvents(getLog())); | hasBuildListenerEvents(getLog())); | ||||
| } | } | ||||
| public void testTestCountFired() { | public void testTestCountFired() { | ||||
| getProject().setProperty("enableEvents", "true"); | |||||
| executeTarget(PASS_TEST_TARGET); | executeTarget(PASS_TEST_TARGET); | ||||
| assertTrue("expecting test count message", | assertTrue("expecting test count message", | ||||
| hasEventMessage(JUnitTask.TESTLISTENER_PREFIX + | hasEventMessage(JUnitTask.TESTLISTENER_PREFIX + | ||||
| @@ -64,6 +67,7 @@ public class JUnitTestListenerTest extends BuildFileTest { | |||||
| } | } | ||||
| public void testStartTestFired() { | public void testStartTestFired() { | ||||
| getProject().setProperty("enableEvents", "true"); | |||||
| executeTarget(PASS_TEST_TARGET); | executeTarget(PASS_TEST_TARGET); | ||||
| assertTrue("expecting test started message", | assertTrue("expecting test started message", | ||||
| hasEventMessage(JUnitTask.TESTLISTENER_PREFIX + | hasEventMessage(JUnitTask.TESTLISTENER_PREFIX + | ||||
| @@ -71,12 +75,34 @@ public class JUnitTestListenerTest extends BuildFileTest { | |||||
| } | } | ||||
| public void testEndTestFired() { | public void testEndTestFired() { | ||||
| getProject().setProperty("enableEvents", "true"); | |||||
| executeTarget(PASS_TEST_TARGET); | executeTarget(PASS_TEST_TARGET); | ||||
| assertTrue("expecting test ended message", | assertTrue("expecting test ended message", | ||||
| hasEventMessage(JUnitTask.TESTLISTENER_PREFIX + | hasEventMessage(JUnitTask.TESTLISTENER_PREFIX + | ||||
| "endTest(" + PASS_TEST + ")")); | "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) { | private boolean hasBuildListenerEvents(String log) { | ||||
| return log.indexOf(JUnitTask.TESTLISTENER_PREFIX) >= 0; | return log.indexOf(JUnitTask.TESTLISTENER_PREFIX) >= 0; | ||||
| } | } | ||||