test/tools/javah/TestHelpOpts.java

Fri, 23 Aug 2013 14:17:49 -0700

author
lana
date
Fri, 23 Aug 2013 14:17:49 -0700
changeset 1967
375834b5cf08
parent 709
5b5d965900b8
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Merge

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

mercurial