Permalink
Browse files

Fixes GH-79: Output emitted twice by text formatter for suite-level e…

…rrors.
  • Loading branch information...
1 parent c9f2494 commit e0740851924aeadaeabe43badae7d50cdb1234e4 @dweiss dweiss committed Apr 15, 2012
View
10 junit4-ant/src/main/java/com/carrotsearch/ant/tasks/junit4/listeners/TextReport.java
@@ -339,10 +339,12 @@ private void format(AggregatedResultEvent result, TestStatus status, int timeMil
}
if (showOutputStream || showErrorStream) {
- CharSequence out = decodeStreamEvents(slave, result.getEventStream());
- if (out.length() > 0) {
- line.append(out);
- line.append("\n");
+ if (!(result instanceof AggregatedSuiteResultEvent)) {
+ CharSequence out = decodeStreamEvents(slave, result.getEventStream());
+ if (out.length() > 0) {
+ line.append(out);
+ line.append("\n");
+ }
}
}
View
39 junit4-ant/src/test/java/com/carrotsearch/ant/tasks/junit4/TestTextReport.java
@@ -0,0 +1,39 @@
+package com.carrotsearch.ant.tasks.junit4;
+
+
+import java.io.File;
+import java.net.URL;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+import com.carrotsearch.ant.tasks.junit4.tests.FailInAfterClass;
+
+
+public class TestTextReport extends AntBuildFileTestBase {
+
+ @Before
+ public void setUp() throws Exception {
+ URL resource = getClass().getClassLoader().getResource("junit4.xml");
+ super.setupProject(new File(resource.getFile()));
+ }
+
+ @Test
+ public void suiteerror() {
+ super.executeTarget("suiteerror");
+
+ String output = super.getLog();
+ int count = 0;
+ for (int i = 0; i < output.length();) {
+ int index = output.indexOf(FailInAfterClass.MESSAGE, i);
+ if (index < 0) {
+ break;
+ }
+ count++;
+ i = index + 1;
+ }
+
+ Assert.assertEquals(1, count);
+ }
+}
View
17 junit4-ant/src/test/java/com/carrotsearch/ant/tasks/junit4/tests/FailInAfterClass.java
@@ -0,0 +1,17 @@
+package com.carrotsearch.ant.tasks.junit4.tests;
+
+import org.junit.AfterClass;
+import org.junit.Test;
+
+public class FailInAfterClass {
+ public final static String MESSAGE = "This is @AfterClass output.";
+
+ @Test
+ public void dummy() {}
+
+ @AfterClass
+ public static void afterClass() {
+ System.out.println(MESSAGE);
+ throw new RuntimeException();
+ }
+}
View
28 junit4-ant/src/test/resources/junit4.xml
@@ -608,5 +608,31 @@
</fileset>
</batchtest>
</junit4.preconf>
- </target>
+ </target>
+
+ <target name="suiteerror">
+ <junit4:junit4 haltonfailure="false">
+ <classpath refid="tests.classpath" />
+
+ <listeners>
+ <junit4:report-text
+ showThrowable="true"
+ showStackTraces="true"
+ showOutputStream="true"
+ showErrorStream="true"
+
+ showStatusOk="false"
+ showStatusError="true"
+ showStatusFailure="true"
+ showStatusIgnored="true"
+
+ showSuiteSummary="true"
+ />
+ </listeners>
+
+ <fileset dir="${basedir}">
+ <include name="**/FailInAfterClass.class" />
+ </fileset>
+ </junit4:junit4>
+ </target>
</project>

0 comments on commit e074085

Please sign in to comment.