1/*
2 * Copyright (c) 2003, 2017, 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      8007687
27 * @summary  Make sure that the -X option works properly.
28 * @library ../lib
29 * @modules jdk.javadoc/jdk.javadoc.internal.tool
30 * @build    JavadocTester
31 * @run main TestXOption
32 */
33
34import java.util.*;
35import java.util.stream.*;
36
37public class TestXOption extends JavadocTester {
38
39    public static void main(String... args) throws Exception {
40        TestXOption tester = new TestXOption();
41        tester.runTests();
42    }
43
44    @Test
45    void testLineLengths() {
46        javadoc("-d", "out1",
47                "-sourcepath", testSrc,
48                "-X",
49                testSrc("TestXOption.java"));
50        checkExit(Exit.OK);
51        List<String> longLines = getOutputLines(Output.OUT).stream()
52                .filter(s -> s.length() > 80)
53                .collect(Collectors.toList());
54        checking("line lengths");
55        if (longLines.isEmpty()) {
56            passed("all lines OK");
57        } else {
58            out.println("long lines:");
59            longLines.stream().forEach(s -> out.println(">>>" + s + "<<<"));
60            failed(longLines.size() + " long lines");
61        }
62    }
63
64    @Test
65    void testWithHelpExtraOption() {
66        javadoc("-d", "out1",
67                "-sourcepath", testSrc,
68                "--help-extra",
69                testSrc("TestXOption.java"));
70        checkExit(Exit.OK);
71        checkOutput(true);
72    }
73
74    @Test
75    void testWithOption() {
76        javadoc("-d", "out1",
77                "-sourcepath", testSrc,
78                "-X",
79                testSrc("TestXOption.java"));
80        checkExit(Exit.OK);
81        checkOutput(true);
82    }
83
84    @Test
85    void testWithoutOption() {
86        javadoc("-d", "out2",
87                "-sourcepath", testSrc,
88                testSrc("TestXOption.java"));
89        checkExit(Exit.OK);
90        checkOutput(false);
91    }
92
93    private void checkOutput(boolean expectFound) {
94        checkOutput(Output.OUT, expectFound,
95                "-Xmaxerrs ",
96                "-Xmaxwarns ",
97                "-Xdocrootparent ",
98                "-Xdoclint ",
99                "-Xdoclint:");
100    }
101}
102