langtools/test/tools/javap/T6715251.java
author jjg
Tue, 08 Jul 2008 16:59:27 -0700
changeset 858 3081a24a8223
child 5213 6efe8a6d26eb
permissions -rw-r--r--
6715251: javap should be consistent with javac and return 2 if given no arguments Reviewed-by: ksrini
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
/*
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    21
 * have any questions.
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
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    31
 */
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
public class T6715251 {
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    34
    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
    35
        new T6715251().run();
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    36
    }
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
    void run() throws Exception {
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    39
        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
    40
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    41
        test(2);
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    42
        test(0, "-help");
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    43
        test(0, "-version");
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    44
        test(0, "-fullversion");
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    45
        test(0, "-classpath", testClasses, "T6715251");
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    46
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    47
        if (errors > 0)
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    48
            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
    49
    }
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
    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
    52
        int rc = javap(args);
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    53
        if (rc != expect)
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    54
            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
    55
                  + log);
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    56
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
    int javap(String... args) {
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    60
        StringWriter sw = new StringWriter();
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    61
        PrintWriter pw = new PrintWriter(sw);
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    62
        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
    63
        log = sw.toString();
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    64
        return rc;
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    65
    }
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
    void error(String msg) {
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    68
        System.err.println(msg);
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    69
        errors++;
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    70
    }
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
    String log;
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    73
    int errors;
3081a24a8223 6715251: javap should be consistent with javac and return 2 if given no arguments
jjg
parents:
diff changeset
    74
}