ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject DO NOT REPLY [Bug 45411] New: JUnit prints portions of internal logging junk
Date Wed, 16 Jul 2008 19:15:24 GMT

           Summary: JUnit prints portions of internal logging junk
           Product: Ant
           Version: 1.7.1
          Platform: Macintosh
        OS/Version: Mac OS X 10.4
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Optional Tasks

I'm getting junk output from the JUnit task when there are test failures.  It
seems that the internal logging facility assumes all logged output will be a
single line, but doesn't guarantee that this is the case.

I'm using Ant 1.7.0 (the standard distribution for Mac OS X), and (I believe)
JUnit 3.8.1.

$ -> ant -version
Apache Ant version 1.7.0 compiled on February 29 2008

Here's some example output:

    [junit] messed up)
    [junit] crashed)
    [junit] Test SimpleTest FAILED

Those first two [junit] lines should not appear.

To reproduce, here's the target source:

  <target name="simple-test">
    <junit fork="yes">
        <pathelement location="classes/test" />
      <test name="SimpleTest" />

And here is the SimpleTest class's source:

public class SimpleTest extends junit.framework.TestCase {
  public void testFoo() { assertTrue("testFoo \nmessed up", false); }
  public void testBar() { assertTrue("testBar \ndidn't work", true); }
  public void testFee() { assertTrue("testFee \ncrashed", false); }
  public void testFie() { assertTrue("testFie \nbroke", true); }

I can avoid the junk output by turning off forking or removing the "\n"
characters from the assertion failure messages.

My workaround (because I need forking and multi-line failures) is to use
reflection to turn off logging:

    private void turnOffLogging(TestResult result) {
      try {
        java.lang.reflect.Field listenersF =
        for (Object listener : (Iterable<?>) listenersF.get(result)) {
          Object antRunner = listener; // by default, the listener is the
          try {
            java.lang.reflect.Field antRunnerF =
            antRunner = antRunnerF.get(listener);
          catch (Throwable t) { /* not an anonymous class */ }
          try {
            java.lang.reflect.Field logFlagF =
            logFlagF.setBoolean(antRunner, false);
          catch (Throwable t) { /* not an Ant test runner */ }
      catch (Throwable t) { /* not a standard JUnit TestResult */ }

Configure bugmail:
------- You are receiving this mail because: -------
You are the assignee for the bug.

View raw message