T8032819.java revision 2942:08092deced3f
1/*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 8032819
27 * @summary Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options
28 * @modules jdk.jdeps
29 * @compile -g T8032819.java
30 * @run main T8032819
31 */
32
33import java.io.*;
34import java.util.*;
35
36public class T8032819 {
37    static class Fields {
38        int f1;
39        int f2;
40    }
41
42    public static void main(String... args) throws Exception {
43        new T8032819().run();
44    }
45
46    void run() throws Exception {
47        Class<?> clazz = Fields.class;
48        test(clazz);
49        test(clazz, "-c");
50        test(clazz, "-l");
51        test(clazz, "-l", "-c");
52        test(clazz, "-v");
53        test(clazz, "-v", "-c");
54        test(clazz, "-v", "-l");
55        test(clazz, "-v", "-l", "-c");
56
57        if (errors > 0)
58            throw new Exception(errors + " errors occurred");
59    }
60
61    static final String sep = System.getProperty("line.separator");
62    static final String doubleBlankLine = sep + sep + sep;
63
64    void test(Class<?> clazz, String... opts) throws Exception {
65        System.err.println("test " + Arrays.asList(opts));
66        List<String> args = new ArrayList<String>();
67        args.addAll(Arrays.asList(opts));
68        args.addAll(Arrays.asList("-classpath", System.getProperty("test.classes")));
69        args.add(clazz.getName());
70        StringWriter sw = new StringWriter();
71        PrintWriter pw = new PrintWriter(sw);
72        int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw);
73        pw.close();
74        String out = sw.toString();
75        if (rc != 0)
76            throw new Exception("javap failed unexpectedly: rc=" + rc);
77
78        int count = 0;
79        int i = out.indexOf(doubleBlankLine, 0);
80        while (i != -1) {
81            count++;
82            i = out.indexOf(doubleBlankLine, i + doubleBlankLine.length());
83        }
84
85        if (count > 0)
86            error(count + " double blank lines found");
87    }
88
89    void error(String msg) {
90        System.err.println("Error: " + msg);
91        errors++;
92    }
93
94    int errors = 0;
95}
96
97