test/jdk/tools/launcher/HelpFlagsTest.java
author herrick
Fri, 07 Dec 2018 19:07:08 -0500
branchJDK-8200758-branch
changeset 57065 2446962c555c
parent 52850 f527b24990d7
child 57106 ea870b9ce89a
permissions -rw-r--r--
8214982: jpackage causes failures in existing HelpFlagsTest and VersionCheck tests Reviewed-by: almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
     1
/*
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
     3
 * Copyright (c) 2018 SAP SE. All rights reserved.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
     5
 *
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
     8
 * published by the Free Software Foundation.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
     9
 *
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    14
 * accompanied this code).
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    15
 *
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    19
 *
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    22
 * questions.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    23
 */
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    24
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    25
/**
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    26
 * @test
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    27
 * @summary Validate and test -?, -h and --help flags. All tools in the jdk
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    28
 *          should take the same flags to display the help message. These
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    29
 *          flags should be documented in the printed help message. The
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    30
 *          tool should quit without error code after displaying the
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    31
 *          help message (if there  is no other problem with the command
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    32
 *          line).
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    33
 *          Also check that tools that used to accept -help still do
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    34
 *          so. Test that tools that never accepted -help don't do so
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    35
 *          in future. I.e., check that the tool returns with the same
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    36
 *          return code as called with an invalid flag, and does not
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    37
 *          print anything containing '-help' in that case.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    38
 * @compile HelpFlagsTest.java
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    39
 * @run main HelpFlagsTest
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    40
 */
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    41
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    42
import java.io.File;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    43
import java.io.FileFilter;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    44
import java.util.Map;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    45
import java.util.ArrayList;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    46
import java.util.HashMap;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    47
import java.util.List;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    48
import java.util.HashSet;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    49
import java.util.Set;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    50
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    51
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    52
public class HelpFlagsTest extends TestHelper {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    53
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    54
    // Tools that should not be tested because a usage message is pointless.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    55
    static final String[] TOOLS_NOT_TO_TEST = {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    56
        "appletviewer",     // deprecated, don't test
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    57
        "jaccessinspector", // gui, don't test, win only
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    58
        "jaccesswalker",    // gui, don't test, win only
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    59
        "jconsole",         // gui, don't test
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    60
        "servertool",       // none. Shell, don't test.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    61
        "javaw",            // don't test, win only
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    62
        // These shall have a help message that resembles that of
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    63
        // MIT's tools. Thus -?, -h and --help are supported, but not
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    64
        // mentioned in the help text.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    65
        "kinit",
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    66
        "klist",
48650
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
    67
        "ktab",
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
    68
        // Oracle proprietary tools without help message.
48659
9dfffaceb477 8195824: tools/launcher/HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48650
diff changeset
    69
        "javacpl",
48650
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
    70
        "jmc",
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
    71
        "jweblauncher",
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
    72
        "jcontrol",
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
    73
        "ssvagent"
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    74
    };
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    75
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    76
    // Lists which tools support which flags.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    77
    private static class ToolHelpSpec {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    78
        String toolname;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    79
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    80
        // How the flags supposed to be supported are handled.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    81
        //
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    82
        // These flags are supported, i.e.,
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    83
        // * the tool accepts the flag
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    84
        // * the tool prints a help message if the flag is specified
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    85
        // * this help message lists the flag
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    86
        // * the tool exits with exit code '0'.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    87
        boolean supportsQuestionMark;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    88
        boolean supportsH;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    89
        boolean supportsHelp;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    90
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    91
        // One tool returns with exit code != '0'.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    92
        int exitcodeOfHelp;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    93
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    94
        // How legacy -help is handled.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    95
        //
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    96
        // Tools that so far support -help should still do so, but
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    97
        // not print documentation about it. Tools that do not
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    98
        // support -help should not do so in future.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
    99
        //
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   100
        // The tools accepts legacy -help. -help should not be
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   101
        // documented in the usage message.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   102
        boolean supportsLegacyHelp;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   103
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   104
        // Java itself documents -help. -help prints to stderr,
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   105
        // while --help prints to stdout. Leave as is.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   106
        boolean documentsLegacyHelp;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   107
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   108
        // The exit code of the tool if an invalid argument is passed to it.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   109
        // An exit code != 0 would be expected, but not all tools handle it
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   110
        // that way.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   111
        int exitcodeOfWrongFlag;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   112
48650
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   113
        ToolHelpSpec(String n, int q, int h, int hp, int ex1, int l, int dl, int ex2) {
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   114
            toolname = n;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   115
            supportsQuestionMark = ( q  == 1 ? true : false );
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   116
            supportsH            = ( h  == 1 ? true : false );
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   117
            supportsHelp         = ( hp == 1 ? true : false );
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   118
            exitcodeOfHelp       = ex1;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   119
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   120
            supportsLegacyHelp   = (  l == 1 ? true : false );
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   121
            documentsLegacyHelp  = ( dl == 1 ? true : false );
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   122
            exitcodeOfWrongFlag  = ex2;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   123
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   124
    }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   125
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   126
    static ToolHelpSpec[] jdkTools = {
48650
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   127
        //               name          -?   -h --help exitcode   -help -help  exitcode
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   128
        //                                            of help          docu   of wrong
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   129
        //                                                             mented flag
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   130
        new ToolHelpSpec("jabswitch",   0,   0,   0,   0,         0,    0,     0),     // /?, prints help message anyways, win only
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   131
        new ToolHelpSpec("jaotc",       1,   1,   1,   0,         0,    0,     2),     // -?, -h, --help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   132
        new ToolHelpSpec("jar",         1,   1,   1,   0,         0,    0,     1),     // -?, -h, --help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   133
        new ToolHelpSpec("jarsigner",   1,   1,   1,   0,         1,    0,     1),     // -?, -h, --help, -help accepted but not documented.
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   134
        new ToolHelpSpec("java",        1,   1,   1,   0,         1,    1,     1),     // -?, -h, --help -help, Documents -help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   135
        new ToolHelpSpec("javac",       1,   0,   1,   0,         1,    1,     2),     // -?,     --help -help, Documents -help, -h is already taken for "native header output directory".
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   136
        new ToolHelpSpec("javadoc",     1,   1,   1,   0,         1,    1,     1),     // -?, -h, --help -help, Documents -help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   137
        new ToolHelpSpec("javap",       1,   1,   1,   0,         1,    1,     2),     // -?, -h, --help -help, Documents -help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   138
        new ToolHelpSpec("javaw",       1,   1,   1,   0,         1,    1,     1),     // -?, -h, --help -help, Documents -help, win only
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   139
        new ToolHelpSpec("jcmd",        1,   1,   1,   0,         1,    0,     1),     // -?, -h, --help, -help accepted but not documented.
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   140
        new ToolHelpSpec("jdb",         1,   1,   1,   0,         1,    1,     0),     // -?, -h, --help -help, Documents -help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   141
        new ToolHelpSpec("jdeprscan",   1,   1,   1,   0,         0,    0,     1),     // -?, -h, --help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   142
        new ToolHelpSpec("jdeps",       1,   1,   1,   0,         1,    0,     2),     // -?, -h, --help, -help accepted but not documented.
52850
f527b24990d7 8205516: JFR tool
egahlin
parents: 48841
diff changeset
   143
        new ToolHelpSpec("jfr",         1,   1,   1,   0,         0,    0,     2),     // -?, -h, --help
48650
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   144
        new ToolHelpSpec("jhsdb",       0,   0,   0,   0,         0,    0,     0),     // none, prints help message anyways.
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   145
        new ToolHelpSpec("jimage",      1,   1,   1,   0,         0,    0,     2),     // -?, -h, --help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   146
        new ToolHelpSpec("jinfo",       1,   1,   1,   0,         1,    1,     1),     // -?, -h, --help -help, Documents -help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   147
        new ToolHelpSpec("jjs",         0,   1,   1, 100,         0,    0,   100),     //     -h, --help, return code 100
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   148
        new ToolHelpSpec("jlink",       1,   1,   1,   0,         0,    0,     2),     // -?, -h, --help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   149
        new ToolHelpSpec("jmap",        1,   1,   1,   0,         1,    0,     1),     // -?, -h, --help, -help accepted but not documented.
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   150
        new ToolHelpSpec("jmod",        1,   1,   1,   0,         1,    0,     2),     // -?, -h, --help, -help accepted but not documented.
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   151
        new ToolHelpSpec("jps",         1,   1,   1,   0,         1,    1,     1),     // -?, -h, --help -help, Documents -help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   152
        new ToolHelpSpec("jrunscript",  1,   1,   1,   0,         1,    1,     7),     // -?, -h, --help -help, Documents -help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   153
        new ToolHelpSpec("jshell",      1,   1,   1,   0,         1,    0,     1),     // -?, -h, --help, -help accepted but not documented.
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   154
        new ToolHelpSpec("jstack",      1,   1,   1,   0,         1,    1,     1),     // -?, -h, --help -help, Documents -help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   155
        new ToolHelpSpec("jstat",       1,   1,   1,   0,         1,    1,     1),     // -?, -h, --help -help, Documents -help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   156
        new ToolHelpSpec("jstatd",      1,   1,   1,   0,         0,    0,     1),     // -?, -h, --help
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   157
        new ToolHelpSpec("keytool",     1,   1,   1,   0,         1,    0,     1),     // none, prints help message anyways.
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   158
        new ToolHelpSpec("pack200",     1,   1,   1,   0,         1,    0,     2),     // -?, -h, --help, -help accepted but not documented.
57065
2446962c555c 8214982: jpackage causes failures in existing HelpFlagsTest and VersionCheck tests
herrick
parents: 52850
diff changeset
   159
        new ToolHelpSpec("rmic",        0,   0,   0,   0,         0,    0,     1),     // none, prints help message anyways.
48650
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   160
        new ToolHelpSpec("rmid",        0,   0,   0,   0,         0,    0,     1),     // none, prints help message anyways.
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   161
        new ToolHelpSpec("rmiregistry", 0,   0,   0,   0,         0,    0,     1),     // none, prints help message anyways.
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   162
        new ToolHelpSpec("serialver",   0,   0,   0,   0,         0,    0,     1),     // none, prints help message anyways.
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   163
        new ToolHelpSpec("unpack200",   1,   1,   1,   0,         1,    0,     2),     // -?, -h, --help, -help accepted but not documented.
57065
2446962c555c 8214982: jpackage causes failures in existing HelpFlagsTest and VersionCheck tests
herrick
parents: 52850
diff changeset
   164
        new ToolHelpSpec("jpackage",    0,   1,   1,   0,         0,    0,   255),     //     -h, --help,
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   165
    };
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   166
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   167
    // Returns true if the file is not a tool.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   168
    static boolean notATool(String file) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   169
        if (isWindows && !file.endsWith(EXE_FILE_EXT))
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   170
            return true;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   171
        return false;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   172
    }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   173
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   174
    // Returns true if tool is listed in TOOLS_NOT_TO_TEST.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   175
    static boolean dontTestTool(String tool) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   176
        tool = tool.toLowerCase();
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   177
        for (String x : TOOLS_NOT_TO_TEST) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   178
            if (tool.toLowerCase().startsWith(x))
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   179
                return true;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   180
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   181
        return false;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   182
    }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   183
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   184
    // Returns corresponding object from jdkTools array.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   185
    static ToolHelpSpec getToolHelpSpec(String tool) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   186
        for (ToolHelpSpec x : jdkTools) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   187
            if (tool.toLowerCase().equals(x.toolname) ||
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   188
                tool.toLowerCase().equals(x.toolname + ".exe"))
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   189
                return x;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   190
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   191
        return null;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   192
    }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   193
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   194
    // Check whether 'flag' appears in 'line' as a word of itself. It must not
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   195
    // be a substring of a word, as then similar flags might be matched.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   196
    // E.g.: --help matches in the documentation of --help-extra.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   197
    // This works only with english locale, as some tools have translated
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   198
    // usage messages.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   199
    static boolean findFlagInLine(String line, String flag) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   200
        if (line.contains(flag) &&
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   201
            !line.contains("nknown") &&                       // Some tools say 'Unknown option "<flag>"',
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   202
            !line.contains("invalid flag") &&                 // 'invalid flag: <flag>'
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   203
            !line.contains("invalid option") &&               // or 'invalid option: <flag>'. Skip that.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   204
            !line.contains("FileNotFoundException: -help") && // Special case for idlj.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   205
            !line.contains("-h requires an argument") &&      // Special case for javac.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   206
            !line.contains("port argument,")) {               // Special case for rmiregistry.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   207
            // There might be several appearances of 'flag' in
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   208
            // 'line'. (-h as substring of --help).
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   209
            int flagLen = flag.length();
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   210
            int lineLen = line.length();
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   211
            for (int i = line.indexOf(flag); i >= 0; i = line.indexOf(flag, i+1)) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   212
                // There should be a space before 'flag' in 'line', or it's right at the beginning.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   213
                if (i > 0 &&
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   214
                    line.charAt(i-1) != ' ' &&
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   215
                    line.charAt(i-1) != '[' &&  // jarsigner
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   216
                    line.charAt(i-1) != '|' &&  // jstatd
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   217
                    line.charAt(i-1) != '\t') { // jjs
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   218
                    continue;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   219
                }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   220
                // There should be a space or comma after 'flag' in 'line', or it's just at the end.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   221
                int posAfter = i + flagLen;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   222
                if (posAfter < lineLen &&
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   223
                    line.charAt(posAfter) != ' ' &&
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   224
                    line.charAt(posAfter) != ',' &&
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   225
                    line.charAt(posAfter) != '[' && // jar
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   226
                    line.charAt(posAfter) != ']' && // jarsigner
52850
f527b24990d7 8205516: JFR tool
egahlin
parents: 48841
diff changeset
   227
                    line.charAt(posAfter) != ')' && // jfr
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   228
                    line.charAt(posAfter) != '|' && // jstatd
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   229
                    line.charAt(posAfter) != ':' && // jps
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   230
                    line.charAt(posAfter) != '"') { // keytool
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   231
                    continue;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   232
                }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   233
                return true;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   234
            }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   235
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   236
        return false;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   237
    }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   238
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   239
    static TestResult runToolWithFlag(File f, String flag) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   240
        String x = f.getAbsolutePath();
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   241
        TestResult tr = doExec(x, flag);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   242
        System.out.println("Testing " + f.getName());
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   243
        System.out.println("#> " + x + " " + flag);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   244
        tr.testOutput.forEach(System.out::println);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   245
        System.out.println("#> echo $?");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   246
        System.out.println(tr.exitValue);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   247
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   248
        return tr;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   249
    }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   250
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   251
    // Checks whether tool supports flag 'flag' and documents it
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   252
    // in the help message.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   253
    static String testTool(File f, String flag, int exitcode) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   254
        String result = "";
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   255
        TestResult tr = runToolWithFlag(f, flag);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   256
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   257
        // Check that the tool accepted the flag.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   258
        if (exitcode == 0 && !tr.isOK()) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   259
            System.out.println("failed");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   260
            result = "failed: " + f.getName() + " " + flag + " has exit code " + tr.exitValue + ".\n";
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   261
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   262
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   263
        // Check there is a help message listing the flag.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   264
        boolean foundFlag = false;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   265
        for (String y : tr.testOutput) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   266
            if (!foundFlag && findFlagInLine(y, flag)) { // javac
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   267
                foundFlag = true;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   268
                System.out.println("Found documentation of '" + flag + "': '" + y.trim() +"'");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   269
            }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   270
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   271
        if (!foundFlag) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   272
            result += "failed: " + f.getName() + " does not document " +
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   273
                flag + " in help message.\n";
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   274
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   275
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   276
        if (!result.isEmpty())
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   277
            System.out.println(result);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   278
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   279
        return result;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   280
    }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   281
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   282
    // Test the tool supports legacy option -help, but does
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   283
    // not document it.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   284
    static String testLegacyFlag(File f, int exitcode) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   285
        String result = "";
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   286
        TestResult tr = runToolWithFlag(f, "-help");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   287
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   288
        // Check that the tool accepted the flag.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   289
        if (exitcode == 0 && !tr.isOK()) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   290
            System.out.println("failed");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   291
            result = "failed: " + f.getName() + " -help has exit code " + tr.exitValue + ".\n";
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   292
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   293
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   294
        // Check there is _no_ documentation of -help.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   295
        boolean foundFlag = false;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   296
        for (String y : tr.testOutput) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   297
            if (!foundFlag && findFlagInLine(y, "-help")) {  // javac
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   298
                foundFlag = true;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   299
                System.out.println("Found documentation of '-help': '" + y.trim() +"'");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   300
            }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   301
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   302
        if (foundFlag) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   303
            result += "failed: " + f.getName() + " does document -help " +
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   304
                "in help message. This legacy flag should not be documented.\n";
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   305
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   306
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   307
        if (!result.isEmpty())
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   308
            System.out.println(result);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   309
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   310
        return result;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   311
    }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   312
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   313
    // Test that the tool exits with the exit code expected for
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   314
    // invalid flags. In general, one would expect this to be != 0,
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   315
    // but currently a row of tools exit with 0 in this case.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   316
    // The output should not ask to get help with flag '-help'.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   317
    static String testInvalidFlag(File f, String flag, int exitcode, boolean documentsLegacyHelp) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   318
        String result = "";
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   319
        TestResult tr = runToolWithFlag(f, flag);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   320
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   321
        // Check that the tool did exit with the expected return code.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   322
        if (!((exitcode == tr.exitValue) ||
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   323
              // Windows reports -1 where unix reports 255.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   324
              (tr.exitValue < 0 && exitcode == tr.exitValue + 256))) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   325
            System.out.println("failed");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   326
            result = "failed: " + f.getName() + " " + flag + " should not be " +
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   327
                     "accepted. But it has exit code " + tr.exitValue + ".\n";
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   328
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   329
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   330
        if (!documentsLegacyHelp) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   331
            // Check there is _no_ documentation of -help.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   332
            boolean foundFlag = false;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   333
            for (String y : tr.testOutput) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   334
                if (!foundFlag && findFlagInLine(y, "-help")) {  // javac
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   335
                    foundFlag = true;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   336
                    System.out.println("Found documentation of '-help': '" + y.trim() +"'");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   337
                }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   338
            }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   339
            if (foundFlag) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   340
                result += "failed: " + f.getName() + " does document -help " +
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   341
                    "in error message. This legacy flag should not be documented.\n";
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   342
            }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   343
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   344
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   345
        if (!result.isEmpty())
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   346
            System.out.println(result);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   347
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   348
        return result;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   349
    }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   350
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   351
    public static void main(String[] args) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   352
        String errorMessage = "";
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   353
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   354
        // The test analyses the help messages printed. It assumes englisch
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   355
        // help messages. Thus it only works with english locale.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   356
        if (!isEnglishLocale()) { return; }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   357
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   358
        for (File f : new File(JAVA_BIN).listFiles()) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   359
            String toolName = f.getName();
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   360
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   361
            if (notATool(toolName)) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   362
                continue;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   363
            }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   364
            if (dontTestTool(toolName)) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   365
                System.out.println("Skipping test of tool " + toolName +
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   366
                                   ". Tool has no help message.");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   367
                continue;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   368
            }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   369
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   370
            ToolHelpSpec tool = getToolHelpSpec(toolName);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   371
            if (tool == null) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   372
                errorMessage += "Tool " + toolName + " not covered by this test. " +
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   373
                    "Add specification to jdkTools array!\n";
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   374
                continue;
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   375
            }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   376
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   377
            // Test for help flags to be supported.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   378
            if (tool.supportsQuestionMark == true) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   379
                errorMessage += testTool(f, "-?", tool.exitcodeOfHelp);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   380
            } else {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   381
                System.out.println("Skip " + tool.toolname + ". It does not support -?.");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   382
            }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   383
            if (tool.supportsH == true) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   384
                errorMessage += testTool(f, "-h", tool.exitcodeOfHelp);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   385
            } else {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   386
                System.out.println("Skip " + tool.toolname + ". It does not support -h.");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   387
            }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   388
            if (tool.supportsHelp == true) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   389
                errorMessage += testTool(f, "--help", tool.exitcodeOfHelp);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   390
            } else {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   391
                System.out.println("Skip " + tool.toolname + ". It does not support --help.");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   392
            }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   393
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   394
            // Check that the return code listing in jdkTools[] is
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   395
            // correct for an invalid flag.
48650
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   396
            errorMessage += testInvalidFlag(f, "-asdfxgr", tool.exitcodeOfWrongFlag, tool.documentsLegacyHelp);
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   397
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   398
            // Test for legacy -help flag.
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   399
            if (!tool.documentsLegacyHelp) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   400
                if (tool.supportsLegacyHelp == true) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   401
                    errorMessage += testLegacyFlag(f, tool.exitcodeOfHelp);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   402
                } else {
48650
e7164f73c4d3 8195663: Java launcher HelpFlagsTest.java fails with java.lang.AssertionError
goetz
parents: 48543
diff changeset
   403
                    errorMessage += testInvalidFlag(f, "-help", tool.exitcodeOfWrongFlag, false);
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   404
                }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   405
            }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   406
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   407
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   408
        if (errorMessage.isEmpty()) {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   409
            System.out.println("All help string tests: PASS");
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   410
        } else {
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   411
            throw new AssertionError("HelpFlagsTest failed:\n" + errorMessage);
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   412
        }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   413
    }
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents:
diff changeset
   414
}