test/langtools/tools/javah/TestHelpOpts.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 36991 langtools/test/tools/javah/TestHelpOpts.java@7f814aac1f80
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6925
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
     1
/*
36991
7f814aac1f80 8153416: unexport javah from jdk.compiler module
jjg
parents: 30730
diff changeset
     2
 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
6925
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
     4
 *
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
     8
 *
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    13
 * accompanied this code).
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    14
 *
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    18
 *
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    21
 * questions.
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    22
 */
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    23
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    24
/*
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    25
 * @test
6927
5bc46d9ca5b9 6990390: javah -help produces help screen with extraneous output
jjg
parents: 6925
diff changeset
    26
 * @bug 6893932 6990390
6925
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    27
 * @summary javah help screen lists -h and -? but does not accept them
36991
7f814aac1f80 8153416: unexport javah from jdk.compiler module
jjg
parents: 30730
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javah
6925
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    29
 */
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    30
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    31
import java.io.*;
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    32
import java.util.*;
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    33
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    34
public class TestHelpOpts {
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    35
    public static void main(String... args) throws Exception {
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    36
        new TestHelpOpts().run();
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    37
    }
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    38
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    39
    void run() throws Exception {
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    40
        Locale prev = Locale.getDefault();
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    41
        try {
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    42
            Locale.setDefault(Locale.ENGLISH);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    43
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    44
            String[] opts = { "-h", "-help", "-?", "--help" };
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    45
            for (String opt: opts)
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    46
                test(opt);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    47
        } finally {
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    48
            Locale.setDefault(prev);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    49
        }
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    50
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    51
        if (errors > 0)
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    52
            throw new Exception(errors + " errors occurred");
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    53
    }
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    54
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    55
    void test(String opt) {
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    56
        System.err.println("test " + opt);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    57
        String[] args = { opt };
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    58
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    59
        StringWriter sw = new StringWriter();
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    60
        PrintWriter pw = new PrintWriter(sw);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    61
        int rc = com.sun.tools.javah.Main.run(args, pw);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    62
        pw.close();
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    63
        String out = sw.toString();
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    64
        if (!out.isEmpty())
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    65
            System.err.println(out);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    66
        if (rc != 0)
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    67
            error("Unexpected exit: rc=" + rc);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    68
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    69
        String flat = out.replaceAll("\\s+", " "); // canonicalize whitespace
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    70
        if (!flat.contains("Usage: javah [options] <classes> where [options] include:"))
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    71
            error("expected text not found");
6927
5bc46d9ca5b9 6990390: javah -help produces help screen with extraneous output
jjg
parents: 6925
diff changeset
    72
        if (flat.contains("main.opt"))
5bc46d9ca5b9 6990390: javah -help produces help screen with extraneous output
jjg
parents: 6925
diff changeset
    73
            error("key not found in resource bundle: " + flat.replaceAll(".*(main.opt.[^ ]*).*", "$1"));
6925
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    74
    }
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    75
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    76
    void error(String msg) {
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    77
        System.err.println(msg);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    78
        errors++;
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    79
    }
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    80
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    81
    int errors;
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    82
}