langtools/test/tools/javap/T6715251.java
author mchung
Wed, 27 May 2015 13:25:18 -0700
changeset 30846 2b3f379840f0
parent 30730 d3ce7619db2c
child 36526 3b41f1c69604
permissions -rw-r--r--
8074432: Move jdeps and javap to jdk.jdeps module Reviewed-by: jjg, alanb, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
858
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 7681
diff changeset
     2
 * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
858
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
     4
 *
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
     8
 *
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    13
 * accompanied this code).
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    14
 *
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5213
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5213
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5213
diff changeset
    21
 * questions.
858
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    22
 */
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    23
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    24
import java.io.*;
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    25
import java.util.*;
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    26
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    27
/*
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    28
 * @test
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    29
 * @bug 6715251
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    30
 * @summary javap should be consistent with javac and return 2 if given no arguments
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    31
 * @modules jdk.jdeps
858
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    32
 */
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    33
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    34
public class T6715251 {
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    35
    public static void main(String... args) throws Exception {
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    36
        new T6715251().run();
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    37
    }
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    38
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    39
    void run() throws Exception {
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    40
        String testClasses = System.getProperty("test.classes", ".");
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    41
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    42
        test(2);
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    43
        test(0, "-help");
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    44
        test(0, "-version");
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    45
        test(0, "-fullversion");
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    46
        test(0, "-classpath", testClasses, "T6715251");
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    47
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    48
        if (errors > 0)
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    49
            throw new Exception(errors + " errors received");
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    50
    }
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    51
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    52
    void test(int expect, String ... args) {
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    53
        int rc = javap(args);
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    54
        if (rc != expect)
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    55
            error("bad result: expected: " + expect + ", found " + rc + "\n"
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    56
                  + log);
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    57
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    58
    }
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    59
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    60
    int javap(String... args) {
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    61
        StringWriter sw = new StringWriter();
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    62
        PrintWriter pw = new PrintWriter(sw);
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    63
        int rc = com.sun.tools.javap.Main.run(args, pw);
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    64
        log = sw.toString();
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    65
        return rc;
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    66
    }
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    67
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    68
    void error(String msg) {
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    69
        System.err.println(msg);
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    70
        errors++;
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    71
    }
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    72
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    73
    String log;
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    74
    int errors;
5213
6efe8a6d26eb 6933914: fix missing newlines
jjg
parents: 858
diff changeset
    75
}