langtools/test/tools/javap/T8033180.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:
22700
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 22700
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
22700
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     4
 *
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     8
 *
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    13
 * accompanied this code).
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    14
 *
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    18
 *
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    21
 * questions.
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    22
 */
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    23
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    24
/*
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    25
 * @test
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    26
 * @bug 8033180
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    27
 * @summary Bad newline characters
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    28
 * @modules jdk.jdeps
22700
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    29
 */
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    30
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    31
import java.io.*;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    32
import java.util.*;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    33
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    34
public class T8033180 {
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    35
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    36
    public static void main(String... args) throws Exception {
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    37
        new T8033180().run();
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    38
    }
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    39
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    40
    void run() throws Exception {
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    41
        // fast-track this case, because test cannot fail in this case
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    42
        if (lineSep.equals(nl))
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    43
            return;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    44
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    45
        test("-help");
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    46
        test("-version");
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    47
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    48
        if (errors > 0)
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    49
            throw new Exception(errors + " errors occurred");
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    50
    }
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    51
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    52
    static final String lineSep = System.getProperty("line.separator");
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    53
    static final String nl = "\n";
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    54
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    55
    void test(String... opts) throws Exception {
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    56
        System.err.println("test " + Arrays.asList(opts));
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    57
        List<String> args = new ArrayList<String>();
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    58
        args.addAll(Arrays.asList(opts));
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    59
        StringWriter sw = new StringWriter();
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    60
        PrintWriter pw = new PrintWriter(sw);
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    61
        int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw);
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    62
        pw.close();
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    63
        String out = sw.toString();
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    64
        if (rc != 0)
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    65
            throw new Exception("javap failed unexpectedly: rc=" + rc);
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    66
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    67
        // remove all valid platform newline sequences
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    68
        String out2 = out.replace(lineSep, "");
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    69
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    70
        // count the remaining simple newline characters
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    71
        int count = 0;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    72
        int i = out2.indexOf(nl, 0);
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    73
        while (i != -1) {
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    74
            count++;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    75
            i = out2.indexOf(nl, i + nl.length());
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    76
        }
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    77
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    78
        if (count > 0)
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    79
            error(count + " newline characters found");
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    80
    }
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    81
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    82
    void error(String msg) {
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    83
        System.err.println("Error: " + msg);
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    84
        errors++;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    85
    }
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    86
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    87
    int errors = 0;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    88
}
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    89