langtools/test/tools/javap/8007907/JavapReturns0AfterClassNotFoundTest.java
author alanb
Thu, 17 Mar 2016 19:04:28 +0000
changeset 36526 3b41f1c69604
parent 30846 2b3f379840f0
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, jan.lahoda@oracle.com, vicente.romero@oracle.com, andreas.lundblad@oracle.com, andrey.x.nazarov@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, kumar.x.srinivasan@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18388
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
     1
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
18388
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
     4
 *
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
     8
 *
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    13
 * accompanied this code).
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    14
 *
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    18
 *
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    21
 * questions.
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    22
 */
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    23
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    24
/*
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    25
 * @test
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    26
 * @bug 8007907
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    27
 * @summary javap, method com.sun.tools.javap.Main.run returns 0 even in case
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    28
 * of class not found error
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
    29
 * @modules jdk.jdeps/com.sun.tools.javap
18388
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    30
 */
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    31
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    32
import java.io.IOException;
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    33
import java.io.PrintWriter;
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    34
import java.io.StringWriter;
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    35
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    36
public class JavapReturns0AfterClassNotFoundTest {
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    37
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    38
    static final String fileNotFoundErrorMsg =
18906
69fe82f7bd35 8020214: TEST_BUG: test/tools/javap/8007907/JavapReturns0AfterClassNotFoundTest.java broken
ksrini
parents: 18388
diff changeset
    39
            "Error: class not found: Unexisting.class";
18388
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    40
    static final String exitCodeClassNotFoundAssertionMsg =
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    41
            "Javap's exit code for class not found should be 1";
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    42
    static final String classNotFoundMsgAssertionMsg =
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    43
            "Javap's error message for class not found is incorrect";
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    44
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    45
    public static void main(String args[]) throws Exception {
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    46
        new JavapReturns0AfterClassNotFoundTest().run();
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    47
    }
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    48
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    49
    void run() throws IOException {
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    50
        check(exitCodeClassNotFoundAssertionMsg, classNotFoundMsgAssertionMsg,
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    51
                fileNotFoundErrorMsg, "-v", "Unexisting.class");
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    52
    }
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    53
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    54
    void check(String exitCodeAssertionMsg, String errMsgAssertionMsg,
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    55
            String expectedErrMsg, String... params) {
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    56
        int result;
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    57
        StringWriter s;
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    58
        String out;
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    59
        try (PrintWriter pw = new PrintWriter(s = new StringWriter())) {
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    60
            result = com.sun.tools.javap.Main.run(params, pw);
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    61
            //no line separator, no problem
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    62
            out = s.toString().trim();
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    63
        }
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    64
        if (result != 1) {
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    65
            System.out.println("actual exit code " + result);
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    66
            throw new AssertionError(exitCodeAssertionMsg);
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    67
        }
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    68
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    69
        if (!out.equals(expectedErrMsg)) {
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    70
            System.out.println("actual " + out);
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    71
            System.out.println("expected " + expectedErrMsg);
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    72
            throw new AssertionError(errMsgAssertionMsg);
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    73
        }
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    74
    }
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    75
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents:
diff changeset
    76
}