[SUREFIRE-910] Improved provider error handling for failing providers Fixed with IT
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/cd00d144 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/cd00d144 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/cd00d144 Branch: refs/heads/master Commit: cd00d144a3abb0c4839106d383c0a6851f863da5 Parents: ea8bbbf Author: Kristian Rosenvold <krosenv...@apache.org> Authored: Sat Dec 8 20:50:25 2012 +0100 Committer: Kristian Rosenvold <kristian.rosenv...@gmail.com> Committed: Sun Dec 9 10:57:15 2012 +0100 ---------------------------------------------------------------------- .../plugin/surefire/AbstractSurefireMojo.java | 11 +++- .../plugin/surefire/InPluginVMSurefireStarter.java | 15 ++++- .../plugin/surefire/booterclient/ForkStarter.java | 23 +++++-- .../surefire/booterclient/output/ForkClient.java | 14 ++++ .../plugin/surefire/util/DirectoryScanner.java | 3 +- .../maven/surefire/booter/ForkingRunListener.java | 24 +++++-- .../surefire/providerapi/SurefireProvider.java | 3 +- .../maven/surefire/util/ReflectionUtils.java | 19 +++++- .../apache/maven/surefire/suite/RunResultTest.java | 2 +- .../apache/maven/surefire/booter/ForkedBooter.java | 30 ++++++++- .../maven/surefire/booter/ProviderFactory.java | 17 ++---- .../surefire/its/CheckTestNgExecuteErrorIT.java | 17 +++--- .../fixture/SurefireJUnit4IntegrationTestCase.java | 17 +++++ .../its/jiras/Surefire141PluggableProvidersIT.java | 44 ++++++++++++- .../maven/surefire/testprovider/TestProvider.java | 32 +++++++++- .../surefire-931-provider-failure/pom.xml | 48 +++++++++++++++ .../main/java/com/mycompany/testfailed/App.java | 13 ++++ .../java/com/mycompany/testfailed/AppTest.java | 18 ++++++ surefire-setup-integration-tests/pom.xml | 2 +- 19 files changed, 299 insertions(+), 53 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java index 979cfa4..9636017 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java @@ -76,6 +76,7 @@ import org.apache.maven.surefire.testset.DirectoryScannerParameters; import org.apache.maven.surefire.testset.RunOrderParameters; import org.apache.maven.surefire.testset.TestArtifactInfo; import org.apache.maven.surefire.testset.TestRequest; +import org.apache.maven.surefire.testset.TestSetFailedException; import org.apache.maven.surefire.util.DefaultScanResult; import org.apache.maven.surefire.util.NestedCheckedException; import org.apache.maven.surefire.util.NestedRuntimeException; @@ -694,6 +695,13 @@ public abstract class AbstractSurefireMojo firstForkException = e; } } + catch ( TestSetFailedException e ) + { + if ( firstForkException == null ) + { + firstForkException = e; + } + } } if ( firstForkException != null ) @@ -745,7 +753,8 @@ public abstract class AbstractSurefireMojo } private RunResult executeProvider( ProviderInfo provider, DefaultScanResult scanResult ) - throws MojoExecutionException, MojoFailureException, SurefireExecutionException, SurefireBooterForkException + throws MojoExecutionException, MojoFailureException, SurefireExecutionException, SurefireBooterForkException, + TestSetFailedException { SurefireProperties effectiveProperties = setupProperties(); ClassLoaderConfiguration classLoaderConfiguration = getClassLoaderConfiguration( isForking() ); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java index 1018917..6a1a394 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java @@ -19,12 +19,14 @@ package org.apache.maven.plugin.surefire; * under the License. */ +import java.lang.reflect.InvocationTargetException; import java.util.Properties; import org.apache.maven.surefire.booter.ProviderConfiguration; import org.apache.maven.surefire.booter.ProviderFactory; import org.apache.maven.surefire.booter.StartupConfiguration; import org.apache.maven.surefire.booter.SurefireExecutionException; import org.apache.maven.surefire.suite.RunResult; +import org.apache.maven.surefire.testset.TestSetFailedException; import org.apache.maven.surefire.util.DefaultScanResult; /** @@ -58,7 +60,7 @@ public class InPluginVMSurefireStarter } public RunResult runSuitesInProcess( DefaultScanResult scanResult ) - throws SurefireExecutionException + throws SurefireExecutionException, TestSetFailedException { // The test classloader must be constructed first to avoid issues with commons-logging until we properly // separate the TestNG classloader @@ -76,8 +78,15 @@ public class InPluginVMSurefireStarter final Object factory = surefireReflector.createReportingReporterFactory( startupReportConfiguration ); - return ProviderFactory.invokeProvider( null, testsClassLoader, surefireClassLoader, factory, - providerConfiguration, false, startupConfiguration, true ); + try + { + return ProviderFactory.invokeProvider( null, testsClassLoader, surefireClassLoader, factory, + providerConfiguration, false, startupConfiguration, true ); + } + catch ( InvocationTargetException e ) + { + throw new SurefireExecutionException( "Exception in provider", e.getTargetException() ); + } } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java index ae2b446..bcd1931 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java @@ -59,6 +59,7 @@ import org.apache.maven.surefire.booter.SurefireBooterForkException; import org.apache.maven.surefire.booter.SurefireExecutionException; import org.apache.maven.surefire.booter.SystemPropertyManager; import org.apache.maven.surefire.providerapi.SurefireProvider; +import org.apache.maven.surefire.report.StackTraceWriter; import org.apache.maven.surefire.suite.RunResult; import org.apache.maven.surefire.util.DefaultScanResult; @@ -424,14 +425,24 @@ public class ForkStarter { runResult = fileReporterFactory.getGlobalRunStatistics().getRunResult(); } - if ( !runResult.isTimeout() && !forkClient.isSaidGoodBye() ) + if ( !runResult.isTimeout() ) { - //noinspection ThrowFromFinallyBlock - throw new RuntimeException( - "The forked VM terminated without saying properly goodbye. VM crash or System.exit called ?" + - "\nCommand was" + cli.toString() ); - } + StackTraceWriter errorInFork = forkClient.getErrorInFork(); + if ( errorInFork != null ) + { + //noinspection ThrowFromFinallyBlock + throw new RuntimeException( + "There was an error in the forked process\n" + errorInFork.writeTraceToString() ); + } + if ( !forkClient.isSaidGoodBye() ) + { + //noinspection ThrowFromFinallyBlock + throw new RuntimeException( + "The forked VM terminated without saying properly goodbye. VM crash or System.exit called ?" + + "\nCommand was" + cli.toString() ); + } + } forkClient.close( runResult.isTimeout() ); } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java index 8b67139..13fe457 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java @@ -62,6 +62,8 @@ public class ForkClient private volatile boolean saidGoodBye = false; + private volatile StackTraceWriter errorInFork = null; + public ForkClient( DefaultReporterFactory providerReporterFactory, Properties testVmSystemProperties ) { this( providerReporterFactory, testVmSystemProperties, null ); @@ -151,6 +153,9 @@ public class ForkClient testProvidingInputStream.provideNewTest(); } break; + case ForkingRunListener.BOOTERCODE_ERROR: + errorInFork = deserializeStackStraceWriter( new StringTokenizer( remaining, "," ) ); + break; case ForkingRunListener.BOOTERCODE_BYE: saidGoodBye = true; break; @@ -274,4 +279,13 @@ public class ForkClient return saidGoodBye; } + public StackTraceWriter getErrorInFork() + { + return errorInFork; + } + + public boolean isErrorInFork() + { + return errorInFork != null; + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java index b9080f9..73fcaf1 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java @@ -65,7 +65,8 @@ public class DirectoryScanner List<String> result = new ArrayList<String>(); if ( basedir.exists() ) { - org.apache.maven.shared.utils.io.DirectoryScanner scanner = new org.apache.maven.shared.utils.io.DirectoryScanner(); + org.apache.maven.shared.utils.io.DirectoryScanner scanner = + new org.apache.maven.shared.utils.io.DirectoryScanner(); scanner.setBasedir( basedir ); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java index c468ccb..0af3e59 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java @@ -77,6 +77,8 @@ public class ForkingRunListener public static final byte BOOTERCODE_NEXT_TEST = (byte) 'N'; + public static final byte BOOTERCODE_ERROR = (byte) 'X'; + public static final byte BOOTERCODE_BYE = (byte) 'Z'; private final PrintStream target; @@ -244,17 +246,21 @@ public class ForkingRunListener StringBuffer stringBuffer = new StringBuffer(); append( stringBuffer, operationCode ).comma( stringBuffer ); append( stringBuffer, Integer.toHexString( testSetChannelId.intValue() ) ).comma( stringBuffer ); - nullableEncoding( stringBuffer, reportEntry.getSourceName() ).comma( stringBuffer ); - nullableEncoding( stringBuffer, reportEntry.getName() ).comma( stringBuffer ); - nullableEncoding( stringBuffer, reportEntry.getGroup() ).comma( stringBuffer ); - nullableEncoding( stringBuffer, reportEntry.getMessage() ).comma( stringBuffer ); + nullableEncoding( stringBuffer, reportEntry.getSourceName() ); + comma( stringBuffer ); + nullableEncoding( stringBuffer, reportEntry.getName() ); + comma( stringBuffer ); + nullableEncoding( stringBuffer, reportEntry.getGroup() ); + comma( stringBuffer ); + nullableEncoding( stringBuffer, reportEntry.getMessage() ); + comma( stringBuffer ); nullableEncoding( stringBuffer, reportEntry.getElapsed() ); encode( stringBuffer, reportEntry.getStackTraceWriter() ); stringBuffer.append( "\n" ); return stringBuffer.toString(); } - private void comma( StringBuffer stringBuffer ) + private static void comma( StringBuffer stringBuffer ) { stringBuffer.append( "," ); } @@ -289,7 +295,7 @@ public class ForkingRunListener } - private ForkingRunListener nullableEncoding( StringBuffer stringBuffer, String source ) + private static void nullableEncoding( StringBuffer stringBuffer, String source ) { if ( source == null || source.length() == 0 ) { @@ -299,11 +305,15 @@ public class ForkingRunListener { StringUtils.escapeJavaStyleString( stringBuffer, source ); } - return this; } private void encode( StringBuffer stringBuffer, StackTraceWriter stackTraceWriter ) { + encode( stringBuffer, stackTraceWriter, trimStackTraces ); + } + + public static void encode( StringBuffer stringBuffer, StackTraceWriter stackTraceWriter, boolean trimStackTraces ) + { if ( stackTraceWriter != null ) { comma( stringBuffer ); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/SurefireProvider.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/SurefireProvider.java b/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/SurefireProvider.java index 4f13148..bdc543c 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/SurefireProvider.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/SurefireProvider.java @@ -19,6 +19,7 @@ package org.apache.maven.surefire.providerapi; * under the License. */ +import java.lang.reflect.InvocationTargetException; import java.util.Iterator; import org.apache.maven.surefire.report.ReporterException; import org.apache.maven.surefire.suite.RunResult; @@ -67,7 +68,7 @@ public interface SurefireProvider */ RunResult invoke( Object forkTestSet ) - throws TestSetFailedException, ReporterException; + throws TestSetFailedException, ReporterException, InvocationTargetException; /** * Makes an attempt at cancelling the current run, giving the provider a chance to notify http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java b/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java index 9b0738c..bc7364a 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java @@ -131,7 +131,7 @@ public class ReflectionUtils } catch ( InvocationTargetException e ) { - throw new SurefireReflectionException( e ); + throw new SurefireReflectionException( e.getTargetException() ); } catch ( InstantiationException e ) { @@ -155,7 +155,7 @@ public class ReflectionUtils } catch ( InvocationTargetException e ) { - throw new SurefireReflectionException( e ); + throw new SurefireReflectionException( e.getTargetException() ); } catch ( InstantiationException e ) { @@ -194,6 +194,21 @@ public class ReflectionUtils } catch ( InvocationTargetException e ) { + throw new SurefireReflectionException( e.getTargetException() ); + } + + } + + public static Object invokeMethodWithArray2( Object target, Method method, Object[] args ) + throws InvocationTargetException + + { + try + { + return method.invoke( target, args ); + } + catch ( IllegalAccessException e ) + { throw new SurefireReflectionException( e ); } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-api/src/test/java/org/apache/maven/surefire/suite/RunResultTest.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/suite/RunResultTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/suite/RunResultTest.java index d1ab89a..ec99c64 100644 --- a/surefire-api/src/test/java/org/apache/maven/surefire/suite/RunResultTest.java +++ b/surefire-api/src/test/java/org/apache/maven/surefire/suite/RunResultTest.java @@ -25,7 +25,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringWriter; -import org.apache.maven.shared.utils.StringUtils; import org.apache.maven.shared.utils.xml.PrettyPrintXMLWriter; import org.apache.maven.shared.utils.xml.Xpp3DomWriter; @@ -96,6 +95,7 @@ public class RunResultTest summary.delete(); } + private void writeReadCheck( RunResult simpleAggregate ) throws FileNotFoundException { http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java ---------------------------------------------------------------------- diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java index f96ec87..72e6d53 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java @@ -23,7 +23,10 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.PrintStream; +import java.lang.reflect.InvocationTargetException; +import org.apache.maven.surefire.report.PojoStackTraceWriter; import org.apache.maven.surefire.suite.RunResult; +import org.apache.maven.surefire.testset.TestSetFailedException; import org.apache.maven.surefire.util.LazyTestsToRun; /** @@ -86,9 +89,30 @@ public class ForkedBooter testSet = null; } - runSuitesInProcess( testSet, testClassLoader, startupConfiguration, providerConfiguration, originalOut ); + try + { + runSuitesInProcess( testSet, testClassLoader, startupConfiguration, providerConfiguration, + originalOut ); + } + catch ( InvocationTargetException t ) + { + + PojoStackTraceWriter stackTraceWriter = + new PojoStackTraceWriter( "test subystem", "no method", t.getTargetException() ); + StringBuffer stringBuffer = new StringBuffer(); + ForkingRunListener.encode( stringBuffer, stackTraceWriter, false ); + originalOut.println( ( (char) ForkingRunListener.BOOTERCODE_ERROR ) + ",0," + stringBuffer.toString() ); + } + catch ( Throwable t ) + { + + PojoStackTraceWriter stackTraceWriter = new PojoStackTraceWriter( "test subystem", "no method", t ); + StringBuffer stringBuffer = new StringBuffer(); + ForkingRunListener.encode( stringBuffer, stackTraceWriter, false ); + originalOut.println( ( (char) ForkingRunListener.BOOTERCODE_ERROR ) + ",0," + stringBuffer.toString() ); + } // Say bye. - originalOut.println( "Z,0,BYE!" ); + originalOut.println( ( (char) ForkingRunListener.BOOTERCODE_BYE ) + ",0,BYE!" ); originalOut.flush(); // noinspection CallToSystemExit exit( 0 ); @@ -116,7 +140,7 @@ public class ForkedBooter StartupConfiguration startupConfiguration, ProviderConfiguration providerConfiguration, PrintStream originalSystemOut ) - throws SurefireExecutionException + throws SurefireExecutionException, TestSetFailedException, InvocationTargetException { final ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration(); ClassLoader surefireClassLoader = classpathConfiguration.createSurefireClassLoader( testsClassLoader ); http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java ---------------------------------------------------------------------- diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java index 95b705c..abef1c6 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java @@ -20,13 +20,13 @@ package org.apache.maven.surefire.booter; */ import java.io.PrintStream; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Iterator; import org.apache.maven.surefire.providerapi.SurefireProvider; import org.apache.maven.surefire.report.ReporterException; import org.apache.maven.surefire.suite.RunResult; import org.apache.maven.surefire.testset.TestSetFailedException; -import org.apache.maven.surefire.util.NestedRuntimeException; import org.apache.maven.surefire.util.ReflectionUtils; @@ -69,6 +69,7 @@ public class ProviderFactory ClassLoader surefireClassLoader, Object factory, ProviderConfiguration providerConfiguration, boolean insideFork, StartupConfiguration startupConfiguration1, boolean restoreStreams ) + throws TestSetFailedException, InvocationTargetException { final PrintStream orgSystemOut = System.out; final PrintStream orgSystemErr = System.err; @@ -84,14 +85,6 @@ public class ProviderFactory { return provider.invoke( testSet ); } - catch ( TestSetFailedException e ) - { - throw new NestedRuntimeException( e ); - } - catch ( ReporterException e ) - { - throw new NestedRuntimeException( e ); - } finally { if ( restoreStreams && System.getSecurityManager() == null ) @@ -154,7 +147,7 @@ public class ProviderFactory } public RunResult invoke( Object forkTestSet ) - throws TestSetFailedException, ReporterException + throws TestSetFailedException, ReporterException, InvocationTargetException { ClassLoader current = swapClassLoader( testsClassLoader ); try @@ -162,8 +155,8 @@ public class ProviderFactory final Method invoke = ReflectionUtils.getMethod( providerInOtherClassLoader.getClass(), "invoke", invokeParamaters ); - final Object result = ReflectionUtils.invokeMethodWithArray( providerInOtherClassLoader, invoke, - new Object[]{ forkTestSet } ); + final Object result = ReflectionUtils.invokeMethodWithArray2( providerInOtherClassLoader, invoke, + new Object[]{ forkTestSet } ); return (RunResult) surefireReflector.convertIfRunResult( result ); } finally http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgExecuteErrorIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgExecuteErrorIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgExecuteErrorIT.java index d01c628..659110d 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgExecuteErrorIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgExecuteErrorIT.java @@ -19,8 +19,10 @@ package org.apache.maven.surefire.its; * under the License. */ -import org.apache.maven.surefire.its.fixture.SurefireIntegrationTestCase; -import org.apache.maven.surefire.its.fixture.TestFile; +import org.apache.maven.surefire.its.fixture.OutputValidator; +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.junit.Test; + /** * Test for checking that the output from a forked suite is properly captured even if the suite encounters a severe error. @@ -29,14 +31,13 @@ import org.apache.maven.surefire.its.fixture.TestFile; * @author <a href="mailto:krosenv...@apache.org">Kristian Rosenvold</a> */ public class CheckTestNgExecuteErrorIT - extends SurefireIntegrationTestCase + extends SurefireJUnit4IntegrationTestCase { - public void testExecuteError() + @Test + public void executionError() throws Exception { - TestFile surefireReportsFile = - unpack( "/testng-execute-error" ).executeTestWithFailure().getSurefireReportsFile( - "it.BasicTest-output.txt" ); - surefireReportsFile.assertContainsText( "at org.apache.maven.surefire.testng.TestNGExecutor.run" ); + OutputValidator outputValidator = unpack( "/testng-execute-error" ).executeTestWithFailure(); + outputValidator.verifyTextInLog( "at org.apache.maven.surefire.testng.TestNGExecutor.run" ); } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireJUnit4IntegrationTestCase.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireJUnit4IntegrationTestCase.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireJUnit4IntegrationTestCase.java index 9bb8317..06bea62 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireJUnit4IntegrationTestCase.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireJUnit4IntegrationTestCase.java @@ -54,4 +54,21 @@ public abstract class SurefireJUnit4IntegrationTestCase throw new SurefireVerifierException( e ); } } + + public static SurefireLauncher unpack( Class testClass, String sourceName, String suffix ) + { + try + { + return new SurefireLauncher( testClass, sourceName, suffix ); + } + catch ( VerificationException e ) + { + throw new SurefireVerifierException( e ); + } + catch ( IOException e ) + { + throw new SurefireVerifierException( e ); + } + } + } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire141PluggableProvidersIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire141PluggableProvidersIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire141PluggableProvidersIT.java index af3f9f7..1cdfe56 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire141PluggableProvidersIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire141PluggableProvidersIT.java @@ -19,8 +19,13 @@ package org.apache.maven.surefire.its.jiras; * under the License. */ +import org.apache.maven.it.VerificationException; import org.apache.maven.surefire.its.fixture.OutputValidator; import org.apache.maven.surefire.its.fixture.SurefireIntegrationTestCase; +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; + +import org.junit.BeforeClass; +import org.junit.Test; /** * SUREFIRE-613 Asserts proper test counts when running in parallel @@ -28,15 +33,46 @@ import org.apache.maven.surefire.its.fixture.SurefireIntegrationTestCase; * @author Kristian Rosenvold */ public class Surefire141PluggableProvidersIT - extends SurefireIntegrationTestCase + extends SurefireJUnit4IntegrationTestCase { - public void testParallelBuildResultCount() - throws Exception + @BeforeClass + public static void installProvider() + throws VerificationException { - OutputValidator outputValidator = unpack( "surefire-141-pluggableproviders-provider", "prov" ).executeInstall(); + unpack( Surefire141PluggableProvidersIT.class, "surefire-141-pluggableproviders-provider", "prov" ).executeInstall(); + } + @Test + public void pluggableProviderPresent() + throws Exception + { unpack( "surefire-141-pluggableproviders" ).setEOption().executeTest().verifyTextInLog( "Using configured provider org.apache.maven.surefire.testprovider.TestProvider" ).verifyTextInLog( "Using configured provider org.apache.maven.surefire.junit.JUnit3Provider" ).verifyErrorFreeLog(); } + + @Test + public void invokeRuntimeException() + throws Exception + { + unpack( "surefire-141-pluggableproviders" ).addD( "invokeCrash", "runtimeException" ).executeTestWithFailure().verifyTextInLog( + "Let's fail with a runtimeException" ); + } + + @Test + public void invokeReporterException() + throws Exception + { + unpack( "surefire-141-pluggableproviders" ).addD( "invokeCrash", "reporterException" ).executeTestWithFailure().verifyTextInLog( + "Let's fail with a reporterexception" ); + } + + @Test + public void constructorReuntimeException() + throws Exception + { + unpack( "surefire-141-pluggableproviders" ).addD( "constructorCrash", "runtimeException" ).executeTestWithFailure().verifyTextInLog( + "Let's fail with a runtimeException" ); + } + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-integration-tests/src/test/resources/surefire-141-pluggableproviders-provider/src/main/java/org/apache/maven/surefire/testprovider/TestProvider.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-141-pluggableproviders-provider/src/main/java/org/apache/maven/surefire/testprovider/TestProvider.java b/surefire-integration-tests/src/test/resources/surefire-141-pluggableproviders-provider/src/main/java/org/apache/maven/surefire/testprovider/TestProvider.java index 47faf6f..9ad7715 100644 --- a/surefire-integration-tests/src/test/resources/surefire-141-pluggableproviders-provider/src/main/java/org/apache/maven/surefire/testprovider/TestProvider.java +++ b/surefire-integration-tests/src/test/resources/surefire-141-pluggableproviders-provider/src/main/java/org/apache/maven/surefire/testprovider/TestProvider.java @@ -29,11 +29,13 @@ import org.apache.maven.surefire.testset.TestSetFailedException; /** * @author Kristian Rosenvold */ -public class TestProvider extends AbstractProvider +public class TestProvider + extends AbstractProvider { public TestProvider( ProviderParameters booterParameters ) { + invokeRuntimeExceptionIfSet( System.getProperty( "constructorCrash" ) ); } @@ -44,13 +46,37 @@ public class TestProvider extends AbstractProvider public Iterator getSuites() { - + invokeRuntimeExceptionIfSet( System.getProperty( "getSuitesCrash" ) ); return null; } public RunResult invoke( Object forkTestSet ) throws TestSetFailedException, ReporterException { - return new RunResult( 1,0,0,2 ); + throwIfSet( System.getProperty( "invokeCrash" ) ); + return new RunResult( 1, 0, 0, 2 ); + } + + private void throwIfSet( String throwError ) + throws TestSetFailedException, ReporterException + { + if ( "testSetFailed".equals( throwError ) ) + { + throw new TestSetFailedException( "Let's fail" ); + } + if ( "reporterException".equals( throwError ) ) + { + throw new ReporterException( "Let's fail with a reporterexception", new RuntimeException() ); + } + + invokeRuntimeExceptionIfSet( throwError ); + } + + private void invokeRuntimeExceptionIfSet( String throwError ) + { + if ( "runtimeException".equals( throwError ) ) + { + throw new RuntimeException( "Let's fail with a runtimeException" ); + } } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/pom.xml b/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/pom.xml new file mode 100644 index 0000000..baff4b4 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/pom.xml @@ -0,0 +1,48 @@ +<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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>com.mycompany</groupId> + <artifactId>TestFailed</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>TestFailed</name> + <url>http://maven.apache.org</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>${surefire.version}</version> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>6.8</version> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/main/java/com/mycompany/testfailed/App.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/main/java/com/mycompany/testfailed/App.java b/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/main/java/com/mycompany/testfailed/App.java new file mode 100644 index 0000000..4562c1a --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/main/java/com/mycompany/testfailed/App.java @@ -0,0 +1,13 @@ +package com.mycompany.testfailed; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/test/java/com/mycompany/testfailed/AppTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/test/java/com/mycompany/testfailed/AppTest.java b/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/test/java/com/mycompany/testfailed/AppTest.java new file mode 100644 index 0000000..492f833 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/test/java/com/mycompany/testfailed/AppTest.java @@ -0,0 +1,18 @@ +package com.mycompany.testfailed; + +import junit.framework.TestCase; +import org.testng.annotations.Test; + + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + @Test(groups = "deleteLocation", dependsOnGroups = + { + "postLocation", "getLocation" + }) + public void removeNonExistentLocation() {} +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/cd00d144/surefire-setup-integration-tests/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-setup-integration-tests/pom.xml b/surefire-setup-integration-tests/pom.xml index dd6f6d4..543afa9 100644 --- a/surefire-setup-integration-tests/pom.xml +++ b/surefire-setup-integration-tests/pom.xml @@ -136,7 +136,7 @@ <version>1.8</version> <configuration> <extraArtifacts> - <extraArtifact>org.apache.maven.surefire:surefire-testng-utils:${project.version}</extraArtifact> + <extraArtifact>org.apache.maven.surefire:surefire-testng-utils:${project.version}</extraArtifact> </extraArtifacts> <localRepositoryPath>${project.build.directory}/it-repo</localRepositoryPath> </configuration>