diff --git a/src/test/java/picocli/Issue2342.java b/src/test/java/picocli/Issue2342.java index dde4fd785..667d9859b 100644 --- a/src/test/java/picocli/Issue2342.java +++ b/src/test/java/picocli/Issue2342.java @@ -26,14 +26,33 @@ public void testArgsWithSpaces() { "\"--release 21\"", "--nowarn" }; - new CommandLine(co) - .setAllowOptionsAsOptionParameters(true) - .parseArgs(args); + new CommandLine(co).parseArgs(args); List expected = new ArrayList(Arrays.asList(args)); expected.remove(0); + + // spaces are preserved, quotes are preserved + System.out.println(co.compilerArguments); assertEquals(expected, co.compilerArguments); } + @Test + public void testSingleQuotesAreNotSupported() { + CompileOptions co = new CompileOptions(); + String[] args = new String[] { + "--compiler-arguments", + "'--a-param with space'", + "--parameters", + "'--release 21'", + "--nowarn" + }; + new CommandLine(co).parseArgs(args); + + String[] expected = new String[] { + "'--a-param", "with", "space'", "--parameters", "'--release", "21'", "--nowarn" + }; + assertArrayEquals(expected, co.compilerArguments.toArray()); + } + @Test public void testArgsWithSpacesQuotesTrimmed() { CompileOptions co = new CompileOptions(); @@ -45,9 +64,11 @@ public void testArgsWithSpacesQuotesTrimmed() { "--nowarn" }; new CommandLine(co) - .setAllowOptionsAsOptionParameters(true) .setTrimQuotes(true) .parseArgs(args); + + // note: .setTrimQuotes(true) + // results in "--a-param with space" being treated as 3 separate values List expected = Arrays.asList( "--a-param", "with", "space", "--parameters", "--release", "21", "--nowarn"); assertEquals(expected, co.compilerArguments); @@ -64,6 +85,25 @@ public void testArgsSeparateReleaseFrom21() { "21", "--nowarn" }; + new CommandLine(co).parseArgs(args); + List expected = new ArrayList(Arrays.asList(args)); + expected.remove(0); + assertEquals(expected, co.compilerArguments); + } + + @Test + public void testArgsWithOptionLikeValues() { + CompileOptions co = new CompileOptions(); + String[] args = new String[] { + "--compiler-arguments", + // need to set .setAllowOptionsAsOptionParameters(true) + // if we want an option to consume other options as parameters + "--compiler-arguments", // <-- value that looks like an option + "\"--a-param with space\"", + "--parameters=--parameters", + "\"--release 21\"", + "--nowarn" + }; new CommandLine(co) .setAllowOptionsAsOptionParameters(true) .parseArgs(args);