Drop -d option from CLI as it was not POSIX compliant

Closes gh-16663
This commit is contained in:
Andy Wilkinson
2019-07-09 09:48:49 +01:00
parent 7536d88ece
commit 9f253603db
3 changed files with 41 additions and 29 deletions

View File

@@ -16,12 +16,10 @@
package org.springframework.boot.cli.command;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.cli.command.run.RunCommand;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.boot.cli.command.status.ExitStatus;
import static org.assertj.core.api.Assertions.assertThat;
@@ -29,26 +27,49 @@ import static org.assertj.core.api.Assertions.assertThat;
* Integration tests for {@link CommandRunner}.
*
* @author Dave Syer
* @author Andy Wilkinson
*/
@ExtendWith(OutputCaptureExtension.class)
class CommandRunnerIntegrationTests {
@Test
void debugAddsAutoconfigReport(CapturedOutput capturedOutput) {
CommandRunner runner = new CommandRunner("spring");
runner.addCommand(new RunCommand());
// -d counts as "debug" for the spring command, but not for the
// LoggingApplicationListener
runner.runAndHandleErrors("run", "samples/app.groovy", "-d");
assertThat(capturedOutput).contains("Negative matches:");
@BeforeEach
void clearDebug() {
System.clearProperty("debug");
}
@Test
void debugSwitchedOffForAppArgs(CapturedOutput capturedOutput) {
void debugEnabledAndArgumentRemovedWhenNotAnApplicationArgument() {
CommandRunner runner = new CommandRunner("spring");
runner.addCommand(new RunCommand());
runner.runAndHandleErrors("run", "samples/app.groovy", "--", "-d");
assertThat(capturedOutput).doesNotContain("Negative matches:");
ArgHandlingCommand command = new ArgHandlingCommand();
runner.addCommand(command);
runner.runAndHandleErrors("args", "samples/app.groovy", "--debug");
assertThat(command.args).containsExactly("samples/app.groovy");
assertThat(System.getProperty("debug")).isEqualTo("true");
}
@Test
void debugNotEnabledAndArgumentRetainedWhenAnApplicationArgument() {
CommandRunner runner = new CommandRunner("spring");
ArgHandlingCommand command = new ArgHandlingCommand();
runner.addCommand(command);
runner.runAndHandleErrors("args", "samples/app.groovy", "--", "--debug");
assertThat(command.args).containsExactly("samples/app.groovy", "--", "--debug");
assertThat(System.getProperty("debug")).isNull();
}
static class ArgHandlingCommand extends AbstractCommand {
private String[] args;
ArgHandlingCommand() {
super("args", "");
}
@Override
public ExitStatus run(String... args) throws Exception {
this.args = args;
return ExitStatus.OK;
}
}
}

View File

@@ -147,15 +147,6 @@ class CommandRunnerTests {
assertThat(this.calls).containsOnly(Call.ERROR_MESSAGE, Call.PRINT_STACK_TRACE);
}
@Test
void handlesExceptionWithDashD() throws Exception {
willThrow(new RuntimeException()).given(this.regularCommand).run();
int status = this.commandRunner.runAndHandleErrors("command", "-d");
assertThat(System.getProperty("debug")).isEqualTo("true");
assertThat(status).isEqualTo(1);
assertThat(this.calls).containsOnly(Call.ERROR_MESSAGE, Call.PRINT_STACK_TRACE);
}
@Test
void handlesExceptionWithDashDashDebug() throws Exception {
willThrow(new RuntimeException()).given(this.regularCommand).run();