langtools/test/tools/javah/TestHelpOpts.java
author jwilhelm
Thu, 07 Feb 2013 15:51:25 +0100
changeset 15605 bf7de87bbe3a
parent 6927 5bc46d9ca5b9
child 30730 d3ce7619db2c
permissions -rw-r--r--
8006432: Ratio flags should be unsigned Summary: Flags changed to be of uintx type Reviewed-by: johnc, tamao
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
/*
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
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
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    28
 */
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
import java.io.*;
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    31
import java.util.*;
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    32
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    33
public class TestHelpOpts {
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    34
    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
    35
        new TestHelpOpts().run();
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    36
    }
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
    void run() throws Exception {
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    39
        Locale prev = Locale.getDefault();
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    40
        try {
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    41
            Locale.setDefault(Locale.ENGLISH);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    42
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    43
            String[] opts = { "-h", "-help", "-?", "--help" };
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    44
            for (String opt: opts)
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    45
                test(opt);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    46
        } finally {
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    47
            Locale.setDefault(prev);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    48
        }
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
        if (errors > 0)
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    51
            throw new Exception(errors + " errors occurred");
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    52
    }
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
    void test(String opt) {
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    55
        System.err.println("test " + opt);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    56
        String[] args = { opt };
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    57
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    58
        StringWriter sw = new StringWriter();
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    59
        PrintWriter pw = new PrintWriter(sw);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    60
        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
    61
        pw.close();
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    62
        String out = sw.toString();
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    63
        if (!out.isEmpty())
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    64
            System.err.println(out);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    65
        if (rc != 0)
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    66
            error("Unexpected exit: rc=" + rc);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    67
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    68
        String flat = out.replaceAll("\\s+", " "); // canonicalize whitespace
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    69
        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
    70
            error("expected text not found");
6927
5bc46d9ca5b9 6990390: javah -help produces help screen with extraneous output
jjg
parents: 6925
diff changeset
    71
        if (flat.contains("main.opt"))
5bc46d9ca5b9 6990390: javah -help produces help screen with extraneous output
jjg
parents: 6925
diff changeset
    72
            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
    73
    }
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
    void error(String msg) {
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    76
        System.err.println(msg);
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    77
        errors++;
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    78
    }
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
    int errors;
2196feb18c96 6893932: javah help screen lists -h and -? but does not accept them
jjg
parents:
diff changeset
    81
}