vromero@1819: /* vromero@1819: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. vromero@1819: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. vromero@1819: * vromero@1819: * This code is free software; you can redistribute it and/or modify it vromero@1819: * under the terms of the GNU General Public License version 2 only, as vromero@1819: * published by the Free Software Foundation. vromero@1819: * vromero@1819: * This code is distributed in the hope that it will be useful, but WITHOUT vromero@1819: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or vromero@1819: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License vromero@1819: * version 2 for more details (a copy is included in the LICENSE file that vromero@1819: * accompanied this code). vromero@1819: * vromero@1819: * You should have received a copy of the GNU General Public License version vromero@1819: * 2 along with this work; if not, write to the Free Software Foundation, vromero@1819: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. vromero@1819: * vromero@1819: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA vromero@1819: * or visit www.oracle.com if you need additional information or have any vromero@1819: * questions. vromero@1819: */ vromero@1819: vromero@1819: /* vromero@1819: * @test vromero@1819: * @bug 8007907 vromero@1819: * @summary javap, method com.sun.tools.javap.Main.run returns 0 even in case vromero@1819: * of class not found error vromero@1819: */ vromero@1819: vromero@1819: import java.io.IOException; vromero@1819: import java.io.PrintWriter; vromero@1819: import java.io.StringWriter; vromero@1819: vromero@1819: public class JavapReturns0AfterClassNotFoundTest { vromero@1819: vromero@1819: static final String fileNotFoundErrorMsg = ksrini@1893: "Error: class not found: Unexisting.class"; vromero@1819: static final String exitCodeClassNotFoundAssertionMsg = vromero@1819: "Javap's exit code for class not found should be 1"; vromero@1819: static final String classNotFoundMsgAssertionMsg = vromero@1819: "Javap's error message for class not found is incorrect"; vromero@1819: vromero@1819: public static void main(String args[]) throws Exception { vromero@1819: new JavapReturns0AfterClassNotFoundTest().run(); vromero@1819: } vromero@1819: vromero@1819: void run() throws IOException { vromero@1819: check(exitCodeClassNotFoundAssertionMsg, classNotFoundMsgAssertionMsg, vromero@1819: fileNotFoundErrorMsg, "-v", "Unexisting.class"); vromero@1819: } vromero@1819: vromero@1819: void check(String exitCodeAssertionMsg, String errMsgAssertionMsg, vromero@1819: String expectedErrMsg, String... params) { vromero@1819: int result; vromero@1819: StringWriter s; vromero@1819: String out; vromero@1819: try (PrintWriter pw = new PrintWriter(s = new StringWriter())) { vromero@1819: result = com.sun.tools.javap.Main.run(params, pw); vromero@1819: //no line separator, no problem vromero@1819: out = s.toString().trim(); vromero@1819: } vromero@1819: if (result != 1) { vromero@1819: System.out.println("actual exit code " + result); vromero@1819: throw new AssertionError(exitCodeAssertionMsg); vromero@1819: } vromero@1819: vromero@1819: if (!out.equals(expectedErrMsg)) { vromero@1819: System.out.println("actual " + out); vromero@1819: System.out.println("expected " + expectedErrMsg); vromero@1819: throw new AssertionError(errMsgAssertionMsg); vromero@1819: } vromero@1819: } vromero@1819: vromero@1819: }