Skip to content

Commit

Permalink
#433: Added test case for custom color scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
bbottema authored and remkop committed Aug 17, 2018
1 parent 288d2e6 commit ab81874
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/test/java/picocli/CommandLineHelpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3072,7 +3072,7 @@ public void test200NPEWithEmptyCommandName() throws UnsupportedEncodingException
"");
assertEquals(expected, actual);
}

@Test
public void testPrintHelpIfRequestedReturnsTrueForUsageHelp() throws IOException {
class App {
Expand All @@ -3082,12 +3082,32 @@ class App {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
final PrintStream out = new PrintStream(baos);
assertTrue(CommandLine.printHelpIfRequested(list, out, out, Help.Ansi.OFF));

String expected = String.format("" +
"Usage: <main class> [-h]%n" +
" -h%n");
assertEquals(expected, baos.toString());
}

@Test
public void testPrintHelpIfRequestedCustomColorScheme() throws IOException {
ColorScheme customColorScheme = Help.defaultColorScheme(Help.Ansi.ON).optionParams(Style.fg_magenta);

@Command(mixinStandardHelpOptions = true)
class App {
@Option(names = { "-f" }, paramLabel = "ARCHIVE", description = "the archive file") File archive;
}
List<CommandLine> list = new CommandLine(new App()).parse("--help");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
final PrintStream out = new PrintStream(baos);
assertTrue(CommandLine.printHelpIfRequested(list, out, out, customColorScheme));

String expected = String.format("Usage: \u001B[1m<main class>\u001B[21m\u001B[0m [\u001B[33m-hV\u001B[39m\u001B[0m] [\u001B[33m-f\u001B[39m\u001B[0m=\u001B[3m\u001B[35mARCHIVE\u001B[39m\u001B[23m\u001B[0m]%n" +
" \u001B[33m-f\u001B[39m\u001B[0m= \u001B[3m\u001B[35mA\u001B[39m\u001B[23m\u001B[0m\u001B[3m\u001B[35mRCHIVE\u001B[39m\u001B[23m\u001B[0m the archive file%n" +
" \u001B[33m-h\u001B[39m\u001B[0m, \u001B[33m--help\u001B[39m\u001B[0m Show this help message and exit.%n" +
" \u001B[33m-V\u001B[39m\u001B[0m, \u001B[33m--version\u001B[39m\u001B[0m Print version information and exit.%n");
assertEquals(expected, baos.toString());
}

@Test
public void testPrintHelpIfRequestedReturnsTrueForVersionHelp() throws IOException {
Expand Down

0 comments on commit ab81874

Please sign in to comment.