diff --git a/WHATSNEW b/WHATSNEW index 4a672c63f..6d2bbb176 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -847,6 +847,10 @@ Other changes: . Bugzilla Report 24359. + * It is now possible to suppress the "FAILED" lines sent to Ant's + logging system via 's new logFailedTests attribute. + Bugzilla Report 35073. + Changes from Ant 1.7.0 TO Ant 1.7.1 ============================================= diff --git a/docs/manual/OptionalTasks/junit.html b/docs/manual/OptionalTasks/junit.html index 1b39d5358..bb1181f32 100644 --- a/docs/manual/OptionalTasks/junit.html +++ b/docs/manual/OptionalTasks/junit.html @@ -228,6 +228,16 @@ elements).

since Ant 1.7 No + + logfailedtests + When Ant executes multiple tests and doesn't stop + on errors or failures it will log a "FAILED" message for each + failing test to its logging system. If you set this option to + false, the message will not be logged and you have to rely on the + formatter output to find the failing tests. + since Ant 1.8.0 + No +

By using the errorproperty and failureproperty diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java index cee68e384..971aef027 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/Constants.java @@ -35,4 +35,5 @@ public class Constants { static final String LOGTESTLISTENEREVENTS = "logtestlistenerevents="; static final String TESTSFILE = "testsfile="; static final String TERMINATED_SUCCESSFULLY = "terminated successfully"; + static final String LOG_FAILED_TESTS="logfailedtests="; } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java index 46f13ac2a..c76aa6430 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java @@ -155,6 +155,8 @@ public class JUnitTask extends Task { // Do we send output to the formatters ? private boolean outputToFormatters = true; + private boolean logFailedTests = true; + private File tmpDir; private AntClassLoader classLoader = null; private Permissions perm = null; @@ -596,6 +598,16 @@ public class JUnitTask extends Task { this.outputToFormatters = outputToFormatters; } + /** + * If true, write a single "FAILED" line for failed tests to Ant's + * log system. + * + * @since Ant 1.8.0 + */ + public void setLogFailedTests(boolean logFailedTests) { + this.logFailedTests = logFailedTests; + } + /** * Assertions to enable in this program (if fork=true) * @since Ant 1.6 @@ -949,6 +961,8 @@ public class JUnitTask extends Task { + String.valueOf(showOutput)); cmd.createArgument().setValue(Constants.OUTPUT_TO_FORMATTERS + String.valueOf(outputToFormatters)); + cmd.createArgument().setValue(Constants.LOG_FAILED_TESTS + + String.valueOf(logFailedTests)); cmd.createArgument().setValue( Constants.LOGTESTLISTENEREVENTS + "true"); // #31885 @@ -1865,9 +1879,12 @@ public class JUnitTask extends Task { + (result.timedOut ? " (timeout)" : "") + (result.crashed ? " (crashed)" : ""), getLocation()); } else { - log(name + " FAILED" - + (result.timedOut ? " (timeout)" : "") - + (result.crashed ? " (crashed)" : ""), Project.MSG_ERR); + if (logFailedTests) { + log(name + " FAILED" + + (result.timedOut ? " (timeout)" : "") + + (result.crashed ? " (crashed)" : ""), + Project.MSG_ERR); + } if (errorOccurredHere && test.getErrorProperty() != null) { getProject().setNewProperty(test.getErrorProperty(), "true"); } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java index a53beaf58..d483d13d2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java @@ -680,6 +680,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR Properties props = new Properties(); boolean showOut = false; boolean outputToFormat = true; + boolean logFailedTests = true; boolean logTestListenerEvents = false; @@ -723,6 +724,9 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR } else if (args[i].startsWith(Constants.OUTPUT_TO_FORMATTERS)) { outputToFormat = Project.toBoolean( args[i].substring(Constants.OUTPUT_TO_FORMATTERS.length())); + } else if (args[i].startsWith(Constants.LOG_FAILED_TESTS)) { + logFailedTests = Project.toBoolean( + args[i].substring(Constants.LOG_FAILED_TESTS.length())); } } @@ -764,8 +768,10 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR if (code > returnCode) { returnCode = code; } - System.out.println("TEST " + t.getName() - + " FAILED"); + if (logFailedTests) { + System.out.println("TEST " + t.getName() + + " FAILED"); + } } } }