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 4934778 4777599 6553182 8146427 8146475 8175055 8185371 27 * @summary Make sure that --help, -helpfile and -nohelp options work correctly. 28 * @author jamieh 29 * @library ../lib 30 * @modules jdk.javadoc/jdk.javadoc.internal.tool 31 * @build JavadocTester TestHelpOption 32 * @run main TestHelpOption 33 */ 34 35 import java.util.*; 36 import java.util.stream.*; 37 38 public class TestHelpOption extends JavadocTester { 39 40 public static void main(String... args) throws Exception { 41 TestHelpOption tester = new TestHelpOption(); 42 tester.runTests(); 43 } 44 45 @Test 46 void testLineLengths() { 47 javadoc("-d", "out1", 48 "-sourcepath", testSrc, 49 "-X", 50 testSrc("TestXOption.java")); 51 checkExit(Exit.OK); 52 List<String> longLines = getOutputLines(Output.OUT).stream() 53 .filter(s -> s.length() > 80) 54 .collect(Collectors.toList()); 55 checking("line lengths"); 56 if (longLines.isEmpty()) { 57 passed("all lines OK"); 58 } else { 59 out.println("long lines:"); 60 longLines.stream().forEach(s -> out.println(">>>" + s + "<<<")); 61 failed(longLines.size() + " long lines"); 62 } 63 } 64 65 @Test 66 void testWithOption() { 67 javadoc("-d", "out1", 68 "-sourcepath", testSrc, 69 "--help", 70 testSrc("Sample.java")); 71 checkExit(Exit.OK); 72 73 checkOutput(true); 74 } 75 76 @Test 77 void testWithoutOption() { 78 javadoc("-d", "out2", 79 "-sourcepath", testSrc, 80 testSrc("Sample.java")); 81 checkExit(Exit.OK); 82 } 83 84 @Test 85 void testNohelpOption() { 86 javadoc("-d", "out3", 87 "-sourcepath", testSrc, 88 "-nohelp", 89 testSrc("Sample.java")); 90 checkOutput("Sample.html", false, "<li><a href=\"../help-doc.html\">Help</a></li>"); 91 checkExit(Exit.OK); 92 } 93 94 @Test 95 void testHelpfileOption() { 96 javadoc("-d", "out4", 97 "-sourcepath", testSrc, 98 "-helpfile", testSrc("test-help.html"), 99 testSrc("Sample.java")); 100 checkExit(Exit.OK); 101 checkOutput("Sample.html", true, 102 "<li><a href=\"test-help.html\">Help</a></li>"); 103 checkOutput("test-help.html", true, 104 "Help, help."); 105 } 106 107 @Test 108 void testHelpfileReuseOption() { 109 javadoc("-d", "out5", 110 "-sourcepath", testSrc, 111 "-helpfile", testSrc("test-help.html"), 112 "-helpfile", testSrc("test-help.html"), 113 testSrc("Sample.java")); 114 checkExit(Exit.CMDERR); 115 } 116 117 @Test 118 void testHelpfileNohelpConflict() { 119 javadoc("-d", "out6", 120 "-sourcepath", testSrc, 121 "-helpfile", testSrc("test-help.html"), 122 "-nohelp", 123 testSrc("Sample.java")); 124 checkExit(Exit.CMDERR); 125 } 126 127 private void checkOutput(boolean withOption) { 128 checkOutput(Output.OUT, withOption, 129 "-d ", 130 "-use ", 131 "-version ", 132 "-author ", 133 "-docfilessubdirs\n", 134 "-splitindex ", 135 "-windowtitle ", 136 "-doctitle ", 137 "-header ", 138 "-footer ", 139 "-bottom ", 140 "-link ", 141 "-linkoffline ", 142 "-excludedocfilessubdir ", 143 "-group ", 144 "-nocomment ", 145 "-nodeprecated\n", 146 "-noqualifier ", 147 "-nosince ", 148 "-notimestamp ", 149 "-nodeprecatedlist\n", 150 "-notree ", 151 "-noindex ", 152 "-nohelp ", 153 "-nonavbar ", 154 "-serialwarn ", 155 "-tag ", 156 "-taglet ", 157 "-tagletpath ", 158 "-charset ", 159 "-helpfile ", 160 "-linksource ", 161 "-sourcetab ", 162 "-keywords ", 163 "-stylesheetfile ", 164 "--add-stylesheet ", 165 "-docencoding ", 166 "-html4 ", 167 "-html5 ", 168 "-top ", 169 "-author ", 170 "-noqualifier ", 171 "-nosince ", 172 "-notimestamp ", 173 "-sourcetab "); 174 175 checkFileAndOutput("Sample.html", !withOption, 176 "<li><a href=\"help-doc.html\">Help</a></li>"); 177 } 178 }