On Wed, 3 Jul 2024 12:13:34 GMT, Kevin Walls <kev...@openjdk.org> wrote:
>> Sonia Zaldana Calles has updated the pull request incrementally with one >> additional commit since the last revision: >> >> Making enabling help more restrictive. Will not accept -help > > Additional test possibility. I copied what you had already, but should have > used the OutputAnalyzer "shouldContain" method. > > > *** orig.txt 2024-07-03 13:08:46.460514793 +0100 > --- test/jdk/sun/tools/jcmd/TestJcmdSubcommandHelp.java 2024-07-03 > 12:50:48.324022729 +0100 > *************** > *** 39,48 **** > --- 39,49 ---- > public class TestJcmdSubcommandHelp { > > private static final String HELP_ONE_DASH = "-h"; > private static final String HELP_TWO_DASH = "--help"; > private static final String CMD = "VM.metaspace"; > + private static final String ILLEGAL = "IllegalArgumentException: > Unknown argument"; > > public static void main(String[] args) throws Exception { > > // Sanity check with empty input > OutputAnalyzer output = JcmdBase.jcmd(); > *************** > *** 59,68 **** > --- 60,72 ---- > testIgnoreAdditionalArgs(HELP_ONE_DASH, expectedOutput); > testIgnoreAdditionalArgs(HELP_TWO_DASH, expectedOutput); > > testIgnoreTrailingSpaces(HELP_ONE_DASH, expectedOutput); > testIgnoreTrailingSpaces(HELP_TWO_DASH, expectedOutput); > + > + testSimilarCommand(HELP_ONE_DASH + "ello", ILLEGAL); > + testSimilarCommand(HELP_TWO_DASH + "me", ILLEGAL); > } > > private static void testExpectedUsage(String helpOption, String > expectedOutput) throws Exception { > verifyOutput(new String[] {CMD, helpOption}, expectedOutput, > "Expected jcmd to accept '%s' suboption as a command > argument and issue the same help output.".formatted(helpOption)); > *************** > *** 76,93 **** > --- 80,114 ---- > private static void testIgnoreTrailingSpaces(String helpOption, String > expectedOutput) throws Exception { > verifyOutput(new String[] {CMD, "%s ".formatted(helpOption)}, > expectedOutput, > "Expected jcmd to accept '%s' suboption with trailing > spaces".formatted(helpOption)); > } > > + private static void testSimilarCommand(String helpOption, String > expectedOutput) throws Exception { > + verifyOutputContains(new String[] {CMD, helpOption}, expectedOutput, > + "Expected jcmd to NOT accept '%s' suboption with trailing > content".formatted(helpOption)); > + } > + > private static void verifyOutput(String[] args, String expectedOutput, > String errorMessage) throws Exception { > OutputAnalyzer output = JcmdBase.jcmd(args); > String issuedOutput = output.getOutput(); > if (!expectedOutput.equals(issuedOutput)) { > ... Hi @kevinjwalls, thanks for taking a look! I made some updates based on your comments. ------------- PR Comment: https://git.openjdk.org/jdk/pull/19776#issuecomment-2206297148