You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-commits@maven.apache.org by df...@apache.org on 2008/01/25 23:23:50 UTC
svn commit: r615379 - in /maven/surefire/trunk:
surefire-booter/src/main/java/org/apache/maven/surefire/booter/
surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/
surefire-integration-tests/src/test/java/org/apache/maven/surefire/it...
Author: dfabulich
Date: Fri Jan 25 14:23:48 2008
New Revision: 615379
URL: http://svn.apache.org/viewvc?rev=615379&view=rev
Log:
[SUREFIRE-432] Surefire swallows redirected test output if uncaught exceptions occur in forked SurefireBooter
Submitted by: Benjamin Bentmann
Reviewed by: Dan Fabulich
Added:
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgExecuteErrorTest.java
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/pom.xml
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/src/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/src/test/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/src/test/java/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/src/test/java/it/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/src/test/java/it/BasicTest.java
Modified:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/ForkingStreamConsumer.java
Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java?rev=615379&r1=615378&r2=615379&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java (original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java Fri Jan 25 14:23:48 2008
@@ -641,7 +641,7 @@
}
- StreamConsumer out = getForkingStreamConsumer( showHeading, showFooter, redirectTestOutputToFile );
+ ForkingStreamConsumer out = getForkingStreamConsumer( showHeading, showFooter, redirectTestOutputToFile );
StreamConsumer err;
@@ -670,6 +670,19 @@
throw new SurefireBooterForkException( "Error while executing forked tests.", e );
}
+ if ( redirectTestOutputToFile )
+ {
+ // ensure the FileOutputConsumerProxy flushes/closes the output file
+ try
+ {
+ out.getOutputConsumer().testSetCompleted();
+ }
+ catch ( Exception e )
+ {
+ // the FileOutputConsumerProxy might throw an IllegalStateException but that's not of interest now
+ }
+ }
+
if ( surefireProperties != null && surefireProperties.exists() )
{
FileInputStream inStream = null;
@@ -1004,7 +1017,7 @@
this.childDelegation = childDelegation;
}
- private StreamConsumer getForkingStreamConsumer( boolean showHeading, boolean showFooter,
+ private ForkingStreamConsumer getForkingStreamConsumer( boolean showHeading, boolean showFooter,
boolean redirectTestOutputToFile )
{
OutputConsumer outputConsumer = new StandardOutputConsumer();
Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/ForkingStreamConsumer.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/ForkingStreamConsumer.java?rev=615379&r1=615378&r2=615379&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/ForkingStreamConsumer.java (original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/output/ForkingStreamConsumer.java Fri Jan 25 14:23:48 2008
@@ -74,4 +74,13 @@
outputConsumer.consumeOutputLine( line );
}
}
+
+ /**
+ * Get the underlying output consumer.
+ */
+ public OutputConsumer getOutputConsumer()
+ {
+ return this.outputConsumer;
+ }
+
}
Added: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgExecuteErrorTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgExecuteErrorTest.java?rev=615379&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgExecuteErrorTest.java (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgExecuteErrorTest.java Fri Jan 25 14:23:48 2008
@@ -0,0 +1,29 @@
+package org.apache.maven.surefire.its;
+
+
+import junit.framework.TestCase;
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+import java.io.File;
+
+/**
+ * Test for checking that the output from a forked suite is properly captured even if the suite encounters a severe error.
+ *
+ * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
+ *
+ */
+public class TestNgExecuteErrorTest
+ extends TestCase
+{
+ public void testExecuteError()
+ throws Exception
+ {
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/testng-execute-error" );
+
+ Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+ verifier.executeGoal( "test" );
+ verifier.resetStreams();
+ assertTrue( new File( testDir, "target/surefire-reports/TestSuite-output.txt" ).length() > 0 );
+ }
+}
Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/pom.xml?rev=615379&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/pom.xml (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/pom.xml Fri Jan 25 14:23:48 2008
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.surefire</groupId>
+ <artifactId>testng-execute-error</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>Test proper output from forked execution in case of uncatched error during suite run</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>once</forkMode>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>5.7</version>
+ <scope>test</scope>
+ <classifier>jdk15</classifier>
+ </dependency>
+ </dependencies>
+
+</project>
Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/src/test/java/it/BasicTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/src/test/java/it/BasicTest.java?rev=615379&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/src/test/java/it/BasicTest.java (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/testng-execute-error/src/test/java/it/BasicTest.java Fri Jan 25 14:23:48 2008
@@ -0,0 +1,17 @@
+package it;
+
+import static org.testng.Assert.*;
+
+import org.testng.annotations.*;
+
+/*
+ * Intentionally misconfigured (cycle) to cause an error before the suite is actually run.
+ */
+@Test(groups = { "test" }, dependsOnGroups = { "test" })
+public class BasicTest {
+
+ public void testTrue() {
+ assertTrue(true);
+ }
+
+}