test/tools/javap/T8032819.java

Mon, 31 Aug 2015 13:37:01 -0700

author
asaha
date
Mon, 31 Aug 2015 13:37:01 -0700
changeset 2971
153d0309e698
parent 0
959103a6100f
permissions
-rw-r--r--

Added tag jdk8u65-b12 for changeset 54e958a3719e

     1 /*
     2  * Copyright (c) 2014, 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  */
    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  * @compile -g T8032819.java
    29  * @run main T8032819
    30  */
    32 import java.io.*;
    33 import java.util.*;
    35 public class T8032819 {
    36     static class Fields {
    37         int f1;
    38         int f2;
    39     }
    41     public static void main(String... args) throws Exception {
    42         new T8032819().run();
    43     }
    45     void run() throws Exception {
    46         Class<?> clazz = Fields.class;
    47         test(clazz);
    48         test(clazz, "-c");
    49         test(clazz, "-l");
    50         test(clazz, "-l", "-c");
    51         test(clazz, "-v");
    52         test(clazz, "-v", "-c");
    53         test(clazz, "-v", "-l");
    54         test(clazz, "-v", "-l", "-c");
    56         if (errors > 0)
    57             throw new Exception(errors + " errors occurred");
    58     }
    60     static final String sep = System.getProperty("line.separator");
    61     static final String doubleBlankLine = sep + sep + sep;
    63     void test(Class<?> clazz, String... opts) throws Exception {
    64         System.err.println("test " + Arrays.asList(opts));
    65         List<String> args = new ArrayList<String>();
    66         args.addAll(Arrays.asList(opts));
    67         args.addAll(Arrays.asList("-classpath", System.getProperty("test.classes")));
    68         args.add(clazz.getName());
    69         StringWriter sw = new StringWriter();
    70         PrintWriter pw = new PrintWriter(sw);
    71         int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw);
    72         pw.close();
    73         String out = sw.toString();
    74         if (rc != 0)
    75             throw new Exception("javap failed unexpectedly: rc=" + rc);
    77         int count = 0;
    78         int i = out.indexOf(doubleBlankLine, 0);
    79         while (i != -1) {
    80             count++;
    81             i = out.indexOf(doubleBlankLine, i + doubleBlankLine.length());
    82         }
    84         if (count > 0)
    85             error(count + " double blank lines found");
    86     }
    88     void error(String msg) {
    89         System.err.println("Error: " + msg);
    90         errors++;
    91     }
    93     int errors = 0;
    94 }

mercurial