jjg@707: /* jjg@707: * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. jjg@707: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@707: * jjg@707: * This code is free software; you can redistribute it and/or modify it jjg@707: * under the terms of the GNU General Public License version 2 only, as jjg@707: * published by the Free Software Foundation. jjg@707: * jjg@707: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@707: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@707: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@707: * version 2 for more details (a copy is included in the LICENSE file that jjg@707: * accompanied this code). jjg@707: * jjg@707: * You should have received a copy of the GNU General Public License version jjg@707: * 2 along with this work; if not, write to the Free Software Foundation, jjg@707: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@707: * jjg@707: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jjg@707: * or visit www.oracle.com if you need additional information or have any jjg@707: * questions. jjg@707: */ jjg@707: jjg@707: /* jjg@707: * @test jjg@709: * @bug 6893932 6990390 jjg@707: * @summary javah help screen lists -h and -? but does not accept them jjg@707: */ jjg@707: jjg@707: import java.io.*; jjg@707: import java.util.*; jjg@707: jjg@707: public class TestHelpOpts { jjg@707: public static void main(String... args) throws Exception { jjg@707: new TestHelpOpts().run(); jjg@707: } jjg@707: jjg@707: void run() throws Exception { jjg@707: Locale prev = Locale.getDefault(); jjg@707: try { jjg@707: Locale.setDefault(Locale.ENGLISH); jjg@707: jjg@707: String[] opts = { "-h", "-help", "-?", "--help" }; jjg@707: for (String opt: opts) jjg@707: test(opt); jjg@707: } finally { jjg@707: Locale.setDefault(prev); jjg@707: } jjg@707: jjg@707: if (errors > 0) jjg@707: throw new Exception(errors + " errors occurred"); jjg@707: } jjg@707: jjg@707: void test(String opt) { jjg@707: System.err.println("test " + opt); jjg@707: String[] args = { opt }; jjg@707: jjg@707: StringWriter sw = new StringWriter(); jjg@707: PrintWriter pw = new PrintWriter(sw); jjg@707: int rc = com.sun.tools.javah.Main.run(args, pw); jjg@707: pw.close(); jjg@707: String out = sw.toString(); jjg@707: if (!out.isEmpty()) jjg@707: System.err.println(out); jjg@707: if (rc != 0) jjg@707: error("Unexpected exit: rc=" + rc); jjg@707: jjg@707: String flat = out.replaceAll("\\s+", " "); // canonicalize whitespace jjg@707: if (!flat.contains("Usage: javah [options] where [options] include:")) jjg@707: error("expected text not found"); jjg@709: if (flat.contains("main.opt")) jjg@709: error("key not found in resource bundle: " + flat.replaceAll(".*(main.opt.[^ ]*).*", "$1")); jjg@707: } jjg@707: jjg@707: void error(String msg) { jjg@707: System.err.println(msg); jjg@707: errors++; jjg@707: } jjg@707: jjg@707: int errors; jjg@707: }