Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/InvalidOptions.java
32285 views
/*1* Copyright (c) 2013, 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 802741126* @summary test an invalid option27*/2829import java.io.*;30import java.util.zip.*;3132public class InvalidOptions {33int errorCount;34String log;3536public static void main(String[] args) throws Exception {37new InvalidOptions().run();38}3940void run() throws Exception {41test(2, "-b", "Error: unknown option: -b",42"Usage: javap <options> <classes>",43"use -help for a list of possible options");44if (errorCount > 0)45throw new Exception(errorCount + " errors received");46}4748void test(int expect, String option, String ... expectedOutput) {49String output = runJavap(expect, option);50verify(output, expectedOutput);51}5253String runJavap(int expect, String... option) {54StringWriter sw = new StringWriter();55PrintWriter pw = new PrintWriter(sw);56int rc = com.sun.tools.javap.Main.run(option, pw);57pw.close();58System.out.println("javap prints:");59System.out.println(sw);60if (rc != expect)61throw new Error("Expect to return " + expect + ", but return " + rc);62return sw.toString();63}6465void verify(String output, String... expects) {66for (String expect: expects) {67if (!output.contains(expect))68error(expect + " not found");69}70}7172void error(String msg) {73System.err.println(msg);74errorCount++;75}76}777879