Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javah/TestHelpOpts.java
32285 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 6893932 699039026* @summary javah help screen lists -h and -? but does not accept them27*/2829import java.io.*;30import java.util.*;3132public class TestHelpOpts {33public static void main(String... args) throws Exception {34new TestHelpOpts().run();35}3637void run() throws Exception {38Locale prev = Locale.getDefault();39try {40Locale.setDefault(Locale.ENGLISH);4142String[] opts = { "-h", "-help", "-?", "--help" };43for (String opt: opts)44test(opt);45} finally {46Locale.setDefault(prev);47}4849if (errors > 0)50throw new Exception(errors + " errors occurred");51}5253void test(String opt) {54System.err.println("test " + opt);55String[] args = { opt };5657StringWriter sw = new StringWriter();58PrintWriter pw = new PrintWriter(sw);59int rc = com.sun.tools.javah.Main.run(args, pw);60pw.close();61String out = sw.toString();62if (!out.isEmpty())63System.err.println(out);64if (rc != 0)65error("Unexpected exit: rc=" + rc);6667String flat = out.replaceAll("\\s+", " "); // canonicalize whitespace68if (!flat.contains("Usage: javah [options] <classes> where [options] include:"))69error("expected text not found");70if (flat.contains("main.opt"))71error("key not found in resource bundle: " + flat.replaceAll(".*(main.opt.[^ ]*).*", "$1"));72}7374void error(String msg) {75System.err.println(msg);76errors++;77}7879int errors;80}818283