T4501660.java revision 2942:08092deced3f
1158115Sume/*
2158115Sume * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
3158115Sume * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4158115Sume *
5158115Sume * This code is free software; you can redistribute it and/or modify it
6158115Sume * under the terms of the GNU General Public License version 2 only, as
7158115Sume * published by the Free Software Foundation.
8158115Sume *
9158115Sume * This code is distributed in the hope that it will be useful, but WITHOUT
10158115Sume * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11158115Sume * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12158115Sume * version 2 for more details (a copy is included in the LICENSE file that
13158115Sume * accompanied this code).
14158115Sume *
15158115Sume * You should have received a copy of the GNU General Public License version
16158115Sume * 2 along with this work; if not, write to the Free Software Foundation,
17158115Sume * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18158115Sume *
19158115Sume * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20158115Sume * or visit www.oracle.com if you need additional information or have any
21158115Sume * questions.
22158115Sume */
23158115Sume
24158115Sume/*
25158115Sume * @test
26158115Sume * @bug 4501660
27158115Sume * @summary change diagnostic of -help as 'print this help message and exit'
28158115Sume *            (actually, verify -help does not cause premature exit)
29158115Sume * @modules jdk.jdeps
30158115Sume */
31158115Sume
32158115Sumeimport java.io.*;
33158115Sumeimport java.util.zip.*;
34158115Sume
35158115Sumepublic class T4501660 {
36158115Sume    public static void main(String[] args) throws Exception {
37158115Sume        new T4501660().run();
38158115Sume    }
39158115Sume
40158115Sume    public void run() throws IOException {
41158115Sume        String testClasses = System.getProperty("test.classes", ".");
42158115Sume        String output = javap("-classpath", testClasses, "-help", "T4501660");
43158115Sume        verify(output,
44158115Sume               "-public", "-protected", "-private", // check -help output is present
45158115Sume               "class T4501660"                     // check class output is present
46158115Sume               );
47158115Sume
48158115Sume        if (errors > 0)
49158115Sume            throw new Error(errors + " found.");
50158115Sume    }
51158115Sume
52158115Sume    String javap(String... args) {
53158115Sume        StringWriter sw = new StringWriter();
54158115Sume        PrintWriter out = new PrintWriter(sw);
55158115Sume        //sun.tools.javap.Main.entry(args);
56158115Sume        int rc = com.sun.tools.javap.Main.run(args, out);
57158115Sume        if (rc != 0)
58158115Sume            throw new Error("javap failed. rc=" + rc);
59158115Sume        out.close();
60158115Sume        System.out.println(sw);
61158115Sume        return sw.toString();
62158115Sume    }
63158115Sume
64158115Sume    void verify(String output, String... expects) {
65158115Sume        for (String expect: expects) {
66158115Sume            if (output.indexOf(expect)< 0)
67158115Sume                error(expect + " not found");
68158115Sume        }
69158115Sume    }
70158115Sume
71158115Sume    void error(String msg) {
72158115Sume        System.err.println(msg);
73158115Sume        errors++;
74158115Sume    }
75158115Sume
76158115Sume    int errors;
77158115Sume}
78158115Sume