-
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.
Merge pull request #1505 from ahmede41/master
[#1380] Fix for requiredOptionMarker displayed on ArgGroup
- Loading branch information
Showing
4 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
picocli-annotation-processing-tests/src/test/java/picocli/Issue1380Test.java
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,89 @@ | ||
package picocli; | ||
|
||
import org.junit.Test; | ||
import picocli.CommandLine.ArgGroup; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Testing class for exclusiveOptions | ||
*/ | ||
class Issue1380ExclusiveOptions { | ||
@Option(names = {"-s", "--silent"}, description = "Silent mode", required = false) | ||
protected boolean silent; | ||
|
||
@Option(names = {"-v", "--verbose"}, description = "Verbose mode", required = false) | ||
protected boolean verbose; | ||
|
||
@Option(names = {"-j", "--json"}, description = "JSON printing", required = false) | ||
protected boolean json; | ||
} | ||
|
||
/** | ||
* Testing class for creating a commandline with ArgGroup exclusive tree | ||
*/ | ||
@Command(requiredOptionMarker = '*') | ||
class TestingClassExclusiveTrue { | ||
|
||
@ArgGroup(exclusive = true, multiplicity = "0..1") | ||
protected Issue1380ExclusiveOptions exclusive; | ||
} | ||
|
||
/** | ||
* Testing class for creating a commandline with ArgGroup exclusive false | ||
*/ | ||
@Command(requiredOptionMarker = '*') | ||
class TestingClassExclusiveFalse { | ||
|
||
@ArgGroup(exclusive = false, multiplicity = "0..1") | ||
protected Issue1380ExclusiveOptions exclusive; | ||
} | ||
|
||
/** | ||
* JUnit testing class for issue#1380 // CS427 https://github.com/remkop/picocli/issues/1380 | ||
*/ | ||
public class Issue1380Test { | ||
|
||
/** | ||
* JUnit test class for issue#1380 with exclusive set to true // CS427 https://github.com/remkop/picocli/issues/1380 | ||
*/ | ||
@Test | ||
public void testingWithExclusiveTrue() { | ||
ByteArrayOutputStream tempOut = new ByteArrayOutputStream(); | ||
PrintStream printStream = new PrintStream(tempOut); | ||
new CommandLine(new TestingClassExclusiveTrue()).usage(printStream); | ||
|
||
String returnedText = tempOut.toString(); | ||
String expectedText = String.format( | ||
"Usage: <main class> [-s | -v | -j]%n"+ | ||
" -j, --json JSON printing%n"+ | ||
" -s, --silent Silent mode%n"+ | ||
" -v, --verbose Verbose mode%n"); | ||
|
||
assertEquals(expectedText, returnedText); | ||
} | ||
|
||
/** | ||
* JUnit test class for issue#1380 with exclusive set to false// CS427 https://github.com/remkop/picocli/issues/1380 | ||
*/ | ||
@Test | ||
public void testingWithExclusiveFalse() { | ||
ByteArrayOutputStream tempOut = new ByteArrayOutputStream(); | ||
PrintStream printStream = new PrintStream(tempOut); | ||
new CommandLine(new TestingClassExclusiveFalse()).usage(printStream); | ||
|
||
String returnedText = tempOut.toString(); | ||
String expectedText = String.format( | ||
"Usage: <main class> [[-s] [-v] [-j]]%n" + | ||
" -j, --json JSON printing%n" + | ||
" -s, --silent Silent mode%n" + | ||
" -v, --verbose Verbose mode%n"); | ||
|
||
assertEquals(expectedText, returnedText); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
picocli-annotation-processing-tests/src/test/java/picocli/Issue1420Test.java
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,58 @@ | ||
package picocli; | ||
|
||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import picocli.CommandLine.ArgGroup; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Testing class for creating a commandline with resourceBundle | ||
*/ | ||
@Command(name = "TestingCommand", resourceBundle = ("picocli.Message")) | ||
class TestingClass { | ||
|
||
@ArgGroup(exclusive = true, multiplicity = "0..1") | ||
protected TestingClass.ExclusiveOptions exclusive; | ||
|
||
public TestingClass.ExclusiveOptions getExclusive() { | ||
return this.exclusive; | ||
} | ||
private static class ExclusiveOptions { | ||
@Option(names = {"-h", "--help"}, descriptionKey = "help.message", required = false) | ||
protected boolean showHelp; | ||
|
||
@Option(names = {"-j", "--json"}, descriptionKey = "json.message", required = false) | ||
protected boolean isJson; | ||
|
||
} | ||
} | ||
|
||
@Ignore | ||
/** | ||
* JUnit testing class for issue#1420 // CS427 https://github.com/remkop/picocli/issues/1420 | ||
*/ | ||
public class Issue1420Test { | ||
|
||
/** | ||
* JUnit test class for issue#1420 with resourceBundle // CS427 https://github.com/remkop/picocli/issues/1420 | ||
*/ | ||
@Test | ||
public void testingWithResourceBundle1() { | ||
ByteArrayOutputStream tempOut = new ByteArrayOutputStream(); | ||
PrintStream printStream = new PrintStream(tempOut); | ||
new CommandLine(new TestingClass()).usage(printStream); | ||
|
||
String returnedText = tempOut.toString(); | ||
String expectedText = "Usage: TestingCommand [[-h] | [-j]]\n" + | ||
" -h, --help Show help options\n" + | ||
" -j, --json Set json export-on\n"; | ||
|
||
assertEquals(expectedText, returnedText); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
picocli-annotation-processing-tests/src/test/resources/picocli/Message.properties
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,6 @@ | ||
/** | ||
* Testing class for // CS427 https://github.com/remkop/picocli/issues/1420 | ||
*/ | ||
help.message=Show help options | ||
json.message =Set json export-on | ||
|
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