-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package picocli; | ||
|
||
import static org.junit.Assert.*; | ||
import picocli.CommandLine; | ||
|
||
import org.junit.Test; | ||
|
||
public class Issue1880 { | ||
|
||
@CommandLine.Command | ||
static class TestCommand implements Runnable { | ||
|
||
@CommandLine.Option( | ||
names = {"--no-interactive"}, | ||
/* defaultValue = "true",*/ | ||
negatable = true | ||
) | ||
public boolean interactive = true; | ||
|
||
public void run() {} | ||
} | ||
|
||
@Test | ||
public void optionIsTrueByDefault() { | ||
final CommandLine commandLine = new CommandLine(new TestCommand()); | ||
final CommandLine.ParseResult parseResult = commandLine.parseArgs(); | ||
final TestCommand command = (TestCommand) parseResult.commandSpec().userObject(); | ||
assertTrue(command.interactive); | ||
} | ||
|
||
@Test | ||
public void optionFalseWhenSpecified() { | ||
final TestCommand command = new TestCommand(); | ||
new CommandLine(command).parseArgs("--no-interactive"); | ||
assertFalse(command.interactive); | ||
} | ||
|
||
@Test | ||
public void optionTrueWhenNegatedFormSpecified() { | ||
final TestCommand command = new TestCommand(); | ||
new CommandLine(command).parseArgs("--interactive"); | ||
assertTrue(command.interactive); | ||
} | ||
|
||
@Test | ||
public void optionCanBeSetToFalse() { | ||
final TestCommand command = new TestCommand(); | ||
//CommandLine.tracer().setLevel(CommandLine.TraceLevel.DEBUG); | ||
new CommandLine(command).parseArgs("--no-interactive=false"); | ||
assertFalse(command.interactive); | ||
} | ||
|
||
@Test | ||
public void optionNegatedFormSetToFalseIsTrue() { | ||
final TestCommand command = new TestCommand(); | ||
new CommandLine(command).parseArgs("--interactive=false"); | ||
assertTrue(command.interactive); | ||
} | ||
|
||
} |