if ( forkConfiguration.isDebug() )
{
System.out.println( "Forking command line: " + cli );
}
RunResult runResult = null;
try
{
final int timeout = forkedProcessTimeoutInSeconds > 0 ? forkedProcessTimeoutInSeconds : 0;
final int result =
CommandLineUtils.executeCommandLine( cli, testProvidingInputStream, threadedStreamConsumer,
threadedStreamConsumer, timeout, inputStreamCloser );
if ( result != RunResult.SUCCESS )
{
throw new SurefireBooterForkException( "Error occurred in starting fork, check output in log" );
}
}
catch ( CommandLineTimeOutException e )
{
runResult = RunResult.timeout(
forkClient.getDefaultReporterFactory().getGlobalRunStatistics().getRunResult() );
}
catch ( CommandLineException e )
{
runResult =
RunResult.failure( forkClient.getDefaultReporterFactory().getGlobalRunStatistics().getRunResult(), e );
throw new SurefireBooterForkException( "Error while executing forked tests.", e.getCause() );
}
finally
{
threadedStreamConsumer.close();
if ( inputStreamCloser != null )
{
inputStreamCloser.run();
ShutdownHookUtils.removeShutdownHook( inputStreamCloserHook );
}
if ( runResult == null )
{
runResult = forkClient.getDefaultReporterFactory().getGlobalRunStatistics().getRunResult();
}
if ( !runResult.isTimeout() )
{
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 properly saying goodbye. VM crash or System.exit called?"
+ "\nCommand was " + cli.toString() );
}
}
forkClient.close( runResult.isTimeout() );
}
return runResult;
}