KathrynN commented on a change in pull request #4: [MSHARED-750] - Unbalanced
quotes in command with escaped double quot…
URL: https://github.com/apache/maven-shared-utils/pull/4#discussion_r205876862
##########
File path:
src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java
##########
@@ -99,27 +100,38 @@ public void testTranslateCommandline()
assertCmdLineArgs( new String[] { "foo", " ' ", "bar" }, "foo \" ' \"
bar" );
}
- @Test
- public void
givenASingleQuoteMarkInArgument_whenExecutingCode_thenExitCode0Returned()
throws Exception {
- final Process p = exec("echo \"let's go\"");
- assertEquals(0, p.exitValue());
+ @Test
+ public void
givenASingleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkIsNotEscaped()
throws Exception
+ {
+ final String command = "echo \"let's go\"";
+ final String[] expected = new String[]{"echo", "let's go"};
+ assertCmdLineArgs(expected, command);
}
@Test
- public void
givenADoubleQuoteMarkInArgument_whenExecutingCode_thenExitCode0Returned()
throws Exception {
- final Process p = exec("echo \"let\"s go\"");
+ public void
givenAnEscapedDoubleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped()
throws Exception
+ {
+ final String command = "echo \"let\\\"s go\"";
+ final String[] expected = new String[]{"echo", "let\\\"s go"};
+ assertCmdLineArgs(expected, command);
+ }
- assertEquals(0, p.exitValue());
+ @Test
+ public void
givenAnEscapedSingleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped()
throws Exception
+ {
+ final String command = "echo \"let\\\'s go\"";
+ final String[] expected = new String[]{"echo", "let\\\'s go"};
+ assertCmdLineArgs(expected, command);
}
- private Process exec(String cmd) throws CommandLineException,
InterruptedException {
Review comment:
Removed these tests as they seemed to always return 0, even when the
exception was thrown. However, they might be useful because they run on the
system rather than just testing the setup?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services