langtools/test/tools/doclint/OptionTest.java
author jjg
Mon, 17 Dec 2012 07:47:05 -0800
changeset 14952 d0022ae20516
child 14962 19ffdfafbcd2
permissions -rw-r--r--
8004832: Add new doclint package Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     1
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     2
import com.sun.tools.doclint.DocLint;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     3
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     4
/*
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     5
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     6
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     7
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     8
 * This code is free software; you can redistribute it and/or modify it
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
     9
 * under the terms of the GNU General Public License version 2 only, as
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    10
 * published by the Free Software Foundation.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    11
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    12
 * This code is distributed in the hope that it will be useful, but WITHOUT
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    14
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    15
 * version 2 for more details (a copy is included in the LICENSE file that
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    16
 * accompanied this code).
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    17
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    18
 * You should have received a copy of the GNU General Public License version
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    19
 * 2 along with this work; if not, write to the Free Software Foundation,
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    20
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    21
 *
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    22
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    23
 * or visit www.oracle.com if you need additional information or have any
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    24
 * questions.
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    25
 */
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    26
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    27
/*
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    28
 * @test
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    29
 */
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    30
public class OptionTest {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    31
    public static void main(String... args) throws Exception {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    32
        new OptionTest().run();
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    33
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    34
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    35
    String[] positiveTests = {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    36
        "-Xmsgs",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    37
        "-Xmsgs:all",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    38
        "-Xmsgs:none",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    39
        "-Xmsgs:accessibility",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    40
        "-Xmsgs:html",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    41
        "-Xmsgs:missing",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    42
        "-Xmsgs:reference",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    43
        "-Xmsgs:syntax",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    44
        "-Xmsgs:html/public",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    45
        "-Xmsgs:html/protected",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    46
        "-Xmsgs:html/package",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    47
        "-Xmsgs:html/private",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    48
        "-Xmsgs:-html/public",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    49
        "-Xmsgs:-html/protected",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    50
        "-Xmsgs:-html/package",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    51
        "-Xmsgs:-html/private",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    52
        "-Xmsgs:html,syntax",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    53
        "-Xmsgs:html,-syntax",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    54
        "-Xmsgs:-html,syntax",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    55
        "-Xmsgs:-html,-syntax",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    56
        "-Xmsgs:html/public,syntax",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    57
        "-Xmsgs:html,syntax/public",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    58
        "-Xmsgs:-html/public,syntax/public"
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    59
    };
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    60
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    61
    String[] negativeTests = {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    62
        "-typo",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    63
        "-Xmsgs:-all",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    64
        "-Xmsgs:-none",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    65
        "-Xmsgs:typo",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    66
        "-Xmsgs:html/typo",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    67
        "-Xmsgs:html/public,typo",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    68
        "-Xmsgs:html/public,syntax/typo",
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    69
    };
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    70
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    71
    void run() throws Exception {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    72
        test(positiveTests, true);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    73
        test(negativeTests, false);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    74
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    75
        if (errors > 0)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    76
            throw new Exception(errors + " errors occurred");
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    77
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    78
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    79
    void test(String[] tests, boolean expect) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    80
        for (String test: tests) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    81
            System.err.println("test: " + test);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    82
            boolean found = DocLint.isValidOption(test);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    83
            if (found != expect)
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    84
                error("Unexpected result: " + found + ",expected: " + expect);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    85
        }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    86
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    87
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    88
    void error(String msg) {
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    89
        System.err.println("Error: " + msg);
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    90
        errors++;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    91
    }
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    92
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    93
    int errors;
d0022ae20516 8004832: Add new doclint package
jjg
parents:
diff changeset
    94
}