From 2a7fb1f3eed15f928c174977b1b06a92951397aa Mon Sep 17 00:00:00 2001 From: bbottema Date: Fri, 17 Aug 2018 19:49:29 +0200 Subject: [PATCH] #433: Added test case for custom color scheme --- .../java/picocli/CommandLineHelpTest.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/test/java/picocli/CommandLineHelpTest.java b/src/test/java/picocli/CommandLineHelpTest.java index 6714cfc17..540e5d4f5 100644 --- a/src/test/java/picocli/CommandLineHelpTest.java +++ b/src/test/java/picocli/CommandLineHelpTest.java @@ -3072,7 +3072,7 @@ public void test200NPEWithEmptyCommandName() throws UnsupportedEncodingException ""); assertEquals(expected, actual); } - + @Test public void testPrintHelpIfRequestedReturnsTrueForUsageHelp() throws IOException { class App { @@ -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:
[-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 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
\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 {