Browse Source

Add a test that fails if we allow a logger to recursively log messages

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@669453 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 17 years ago
parent
commit
a05aca8a79
1 changed files with 30 additions and 0 deletions
  1. +30
    -0
      src/tests/junit/org/apache/tools/ant/ProjectTest.java

+ 30
- 0
src/tests/junit/org/apache/tools/ant/ProjectTest.java View File

@@ -245,6 +245,36 @@ public class ProjectTest extends TestCase {
bft.expectLog("once", "once from buildfile");
}

public void testOutputDuringMessageLoggedIsSwallowed()
throws InterruptedException {
final String FOO = "foo", BAR = "bar";
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(final BuildEvent actual) {
assertEquals(FOO, actual.getMessage());
// each of the following lines would cause an
// infinite loop if the message wasn't swallowed
System.err.println(BAR);
System.out.println(BAR);
p.log(BAR, Project.MSG_INFO);
}
});
final boolean[] done = new boolean[] {false};
Thread t = new Thread() {
public void run() {
p.log(FOO, Project.MSG_INFO);
done[0] = true;
}
};
t.start();
t.join(2000);
assertTrue("Expected logging thread to finish successfully", done[0]);
}

private class DummyTaskPrivate extends Task {
public DummyTaskPrivate() {}


Loading…
Cancel
Save