Allow tests to System.exit() by default

Otherwise the ApplicationContext stays alive and if it's a
server app the JVM does not exit at the end of "spring test".
User can override with "spring test foo.groovy --nohup"
(which we have to do in our unit tests).
pull/1016/head
Dave Syer 11 years ago
parent 7fd26a556d
commit 8436627598

1
.gitignore vendored

@ -13,6 +13,7 @@ build
lib/ lib/
target target
.springBeans .springBeans
interpolated*.xml
dependency-reduced-pom.xml dependency-reduced-pom.xml
build.log build.log
_site/ _site/

@ -50,6 +50,7 @@ public class SpringCli {
int exitCode = runner.runAndHandleErrors(args); int exitCode = runner.runAndHandleErrors(args);
if (exitCode != 0) { if (exitCode != 0) {
// If successful, leave it to run in case it's a server app
System.exit(exitCode); System.exit(exitCode);
} }
} }

@ -17,6 +17,7 @@
package org.springframework.boot.cli.command.test; package org.springframework.boot.cli.command.test;
import joptsimple.OptionSet; import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.springframework.boot.cli.command.Command; import org.springframework.boot.cli.command.Command;
import org.springframework.boot.cli.command.OptionParsingCommand; import org.springframework.boot.cli.command.OptionParsingCommand;
@ -45,6 +46,12 @@ public class TestCommand extends OptionParsingCommand {
private TestRunner runner; private TestRunner runner;
@Override
protected void doOptions() {
option("nohup",
"Flag to indicate that the JVM should not exit when tests are finished");
}
@Override @Override
protected void run(OptionSet options) throws Exception { protected void run(OptionSet options) throws Exception {
SourceOptions sourceOptions = new SourceOptions(options); SourceOptions sourceOptions = new SourceOptions(options);
@ -53,6 +60,9 @@ public class TestCommand extends OptionParsingCommand {
this.runner = new TestRunner(configuration, sourceOptions.getSourcesArray(), this.runner = new TestRunner(configuration, sourceOptions.getSourcesArray(),
sourceOptions.getArgsArray()); sourceOptions.getArgsArray());
this.runner.compileAndRunTests(); this.runner.compileAndRunTests();
if (!options.has("nohup")) {
System.exit(0); // TODO: non-zero if test fails?
}
} }
/** /**

@ -75,7 +75,10 @@ public class CliTester implements TestRule {
} }
public String test(String... args) throws Exception { public String test(String... args) throws Exception {
Future<TestCommand> future = submitCommand(new TestCommand(), args); String[] argsToUse = new String[args.length + 1];
System.arraycopy(args, 0, argsToUse, 1, args.length);
argsToUse[0] = "--nohup";
Future<TestCommand> future = submitCommand(new TestCommand(), argsToUse);
this.commands.add(future.get(this.timeout, TimeUnit.MILLISECONDS)); this.commands.add(future.get(this.timeout, TimeUnit.MILLISECONDS));
return getOutput(); return getOutput();
} }

Loading…
Cancel
Save