1/*
2 * Copyright (c) 2012, 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 8004832
27 * @summary Add new doclint package
28 * @modules jdk.compiler/com.sun.tools.doclint
29 */
30
31import com.sun.tools.doclint.DocLint;
32
33public class OptionTest {
34    public static void main(String... args) throws Exception {
35        new OptionTest().run();
36    }
37
38    String[] positiveTests = {
39        "-Xmsgs",
40        "-Xmsgs:all",
41        "-Xmsgs:none",
42        "-Xmsgs:accessibility",
43        "-Xmsgs:html",
44        "-Xmsgs:missing",
45        "-Xmsgs:reference",
46        "-Xmsgs:syntax",
47        "-Xmsgs:html/public",
48        "-Xmsgs:html/protected",
49        "-Xmsgs:html/package",
50        "-Xmsgs:html/private",
51        "-Xmsgs:-html/public",
52        "-Xmsgs:-html/protected",
53        "-Xmsgs:-html/package",
54        "-Xmsgs:-html/private",
55        "-Xmsgs:html,syntax",
56        "-Xmsgs:html,-syntax",
57        "-Xmsgs:-html,syntax",
58        "-Xmsgs:-html,-syntax",
59        "-Xmsgs:html/public,syntax",
60        "-Xmsgs:html,syntax/public",
61        "-Xmsgs:-html/public,syntax/public"
62    };
63
64    String[] negativeTests = {
65        "-typo",
66        "-Xmsgs:-all",
67        "-Xmsgs:-none",
68        "-Xmsgs:typo",
69        "-Xmsgs:html/typo",
70        "-Xmsgs:html/public,typo",
71        "-Xmsgs:html/public,syntax/typo",
72    };
73
74    void run() throws Exception {
75        test(positiveTests, true);
76        test(negativeTests, false);
77
78        if (errors > 0)
79            throw new Exception(errors + " errors occurred");
80    }
81
82    void test(String[] tests, boolean expect) {
83        for (String test: tests) {
84            System.err.println("test: " + test);
85            boolean found = DocLint.isValidOption(test);
86            if (found != expect)
87                error("Unexpected result: " + found + ",expected: " + expect);
88        }
89    }
90
91    void error(String msg) {
92        System.err.println("Error: " + msg);
93        errors++;
94    }
95
96    int errors;
97}
98