cl@2181: /* cl@2181: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. cl@2181: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. cl@2181: * cl@2181: * This code is free software; you can redistribute it and/or modify it cl@2181: * under the terms of the GNU General Public License version 2 only, as cl@2181: * published by the Free Software Foundation. cl@2181: * cl@2181: * This code is distributed in the hope that it will be useful, but WITHOUT cl@2181: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or cl@2181: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License cl@2181: * version 2 for more details (a copy is included in the LICENSE file that cl@2181: * accompanied this code). cl@2181: * cl@2181: * You should have received a copy of the GNU General Public License version cl@2181: * 2 along with this work; if not, write to the Free Software Foundation, cl@2181: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. cl@2181: * cl@2181: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA cl@2181: * or visit www.oracle.com if you need additional information or have any cl@2181: * questions. cl@2181: */ cl@2181: cl@2181: /* cl@2181: * @test cl@2181: * @bug 8027411 kizune@2289: * @summary test an invalid option cl@2181: */ cl@2181: cl@2181: import java.io.*; cl@2181: import java.util.zip.*; cl@2181: cl@2181: public class InvalidOptions { cl@2181: int errorCount; cl@2181: String log; cl@2181: cl@2181: public static void main(String[] args) throws Exception { cl@2181: new InvalidOptions().run(); cl@2181: } cl@2181: cl@2181: void run() throws Exception { cl@2181: test(2, "-b", "Error: unknown option: -b", cl@2181: "Usage: javap ", cl@2181: "use -help for a list of possible options"); cl@2181: if (errorCount > 0) cl@2181: throw new Exception(errorCount + " errors received"); cl@2181: } cl@2181: cl@2181: void test(int expect, String option, String ... expectedOutput) { cl@2181: String output = runJavap(expect, option); cl@2181: verify(output, expectedOutput); cl@2181: } cl@2181: cl@2181: String runJavap(int expect, String... option) { cl@2181: StringWriter sw = new StringWriter(); cl@2181: PrintWriter pw = new PrintWriter(sw); cl@2181: int rc = com.sun.tools.javap.Main.run(option, pw); cl@2181: pw.close(); cl@2181: System.out.println("javap prints:"); cl@2181: System.out.println(sw); cl@2181: if (rc != expect) cl@2181: throw new Error("Expect to return " + expect + ", but return " + rc); cl@2181: return sw.toString(); cl@2181: } cl@2181: cl@2181: void verify(String output, String... expects) { cl@2181: for (String expect: expects) { cl@2181: if (!output.contains(expect)) cl@2181: error(expect + " not found"); cl@2181: } cl@2181: } cl@2181: cl@2181: void error(String msg) { cl@2181: System.err.println(msg); cl@2181: errorCount++; cl@2181: } cl@2181: }