Fri, 24 Apr 2020 03:58:51 +0100
Merge
vromero@1819 | 1 | /* |
vromero@1819 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
vromero@1819 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
vromero@1819 | 4 | * |
vromero@1819 | 5 | * This code is free software; you can redistribute it and/or modify it |
vromero@1819 | 6 | * under the terms of the GNU General Public License version 2 only, as |
vromero@1819 | 7 | * published by the Free Software Foundation. |
vromero@1819 | 8 | * |
vromero@1819 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
vromero@1819 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
vromero@1819 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
vromero@1819 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
vromero@1819 | 13 | * accompanied this code). |
vromero@1819 | 14 | * |
vromero@1819 | 15 | * You should have received a copy of the GNU General Public License version |
vromero@1819 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
vromero@1819 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
vromero@1819 | 18 | * |
vromero@1819 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
vromero@1819 | 20 | * or visit www.oracle.com if you need additional information or have any |
vromero@1819 | 21 | * questions. |
vromero@1819 | 22 | */ |
vromero@1819 | 23 | |
vromero@1819 | 24 | /* |
vromero@1819 | 25 | * @test |
vromero@1819 | 26 | * @bug 8007907 |
vromero@1819 | 27 | * @summary javap, method com.sun.tools.javap.Main.run returns 0 even in case |
vromero@1819 | 28 | * of class not found error |
vromero@1819 | 29 | */ |
vromero@1819 | 30 | |
vromero@1819 | 31 | import java.io.IOException; |
vromero@1819 | 32 | import java.io.PrintWriter; |
vromero@1819 | 33 | import java.io.StringWriter; |
vromero@1819 | 34 | |
vromero@1819 | 35 | public class JavapReturns0AfterClassNotFoundTest { |
vromero@1819 | 36 | |
vromero@1819 | 37 | static final String fileNotFoundErrorMsg = |
ksrini@1893 | 38 | "Error: class not found: Unexisting.class"; |
vromero@1819 | 39 | static final String exitCodeClassNotFoundAssertionMsg = |
vromero@1819 | 40 | "Javap's exit code for class not found should be 1"; |
vromero@1819 | 41 | static final String classNotFoundMsgAssertionMsg = |
vromero@1819 | 42 | "Javap's error message for class not found is incorrect"; |
vromero@1819 | 43 | |
vromero@1819 | 44 | public static void main(String args[]) throws Exception { |
vromero@1819 | 45 | new JavapReturns0AfterClassNotFoundTest().run(); |
vromero@1819 | 46 | } |
vromero@1819 | 47 | |
vromero@1819 | 48 | void run() throws IOException { |
vromero@1819 | 49 | check(exitCodeClassNotFoundAssertionMsg, classNotFoundMsgAssertionMsg, |
vromero@1819 | 50 | fileNotFoundErrorMsg, "-v", "Unexisting.class"); |
vromero@1819 | 51 | } |
vromero@1819 | 52 | |
vromero@1819 | 53 | void check(String exitCodeAssertionMsg, String errMsgAssertionMsg, |
vromero@1819 | 54 | String expectedErrMsg, String... params) { |
vromero@1819 | 55 | int result; |
vromero@1819 | 56 | StringWriter s; |
vromero@1819 | 57 | String out; |
vromero@1819 | 58 | try (PrintWriter pw = new PrintWriter(s = new StringWriter())) { |
vromero@1819 | 59 | result = com.sun.tools.javap.Main.run(params, pw); |
vromero@1819 | 60 | //no line separator, no problem |
vromero@1819 | 61 | out = s.toString().trim(); |
vromero@1819 | 62 | } |
vromero@1819 | 63 | if (result != 1) { |
vromero@1819 | 64 | System.out.println("actual exit code " + result); |
vromero@1819 | 65 | throw new AssertionError(exitCodeAssertionMsg); |
vromero@1819 | 66 | } |
vromero@1819 | 67 | |
vromero@1819 | 68 | if (!out.equals(expectedErrMsg)) { |
vromero@1819 | 69 | System.out.println("actual " + out); |
vromero@1819 | 70 | System.out.println("expected " + expectedErrMsg); |
vromero@1819 | 71 | throw new AssertionError(errMsgAssertionMsg); |
vromero@1819 | 72 | } |
vromero@1819 | 73 | } |
vromero@1819 | 74 | |
vromero@1819 | 75 | } |