Path: blob/master/test/langtools/jdk/javadoc/tool/6958836/Test.java
40971 views
/*1* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 6958836 8002168 818276526* @summary javadoc should support -Xmaxerrs and -Xmaxwarns27* @modules jdk.javadoc/jdk.javadoc.internal.tool28*/2930import java.io.*;31import java.util.*;3233public class Test {34public static void main(String... args) throws Exception {35new Test().run();36}3738void run() throws Exception {39javadoc("errs", list(), 10, 0);40javadoc("errs", list("-Xmaxerrs", "0"), 10, 0);41javadoc("errs", list("-Xmaxerrs", "2"), 2, 0);42javadoc("errs", list("-Xmaxerrs", "4"), 4, 0);43javadoc("errs", list("-Xmaxerrs", "20"), 10, 0);4445javadoc("warns", list(), 0, 10);46javadoc("warns", list("-Xmaxwarns", "0"), 0, 10);47javadoc("warns", list("-Xmaxwarns", "2"), 0, 2);48javadoc("warns", list("-Xmaxwarns", "4"), 0, 4);49javadoc("warns", list("-Xmaxwarns", "20"), 0, 10);5051if (errors > 0)52throw new Exception(errors + " errors occurred.");53}5455void javadoc(String pkg, List<String> testOpts,56int expectErrs, int expectWarns) {57System.err.println("Test " + (++count) + ": " + pkg + " " + testOpts);58File testOutDir = new File("test" + count);5960List<String> opts = new ArrayList<String>();61// Force en_US locale in lieu of something like -XDrawDiagnostics.62// For some reason, this must be the first option when used.63opts.addAll(list("-locale", "en_US"));64opts.add("-Xdoclint:none");65opts.addAll(list("-classpath", System.getProperty("test.src")));66opts.addAll(list("-d", testOutDir.getPath()));67opts.addAll(testOpts);68opts.add(pkg);6970StringWriter errSW = new StringWriter();71PrintWriter errPW = new PrintWriter(errSW);72int rc = jdk.javadoc.internal.tool.Main.execute(73opts.toArray(new String[opts.size()]),74errPW);75System.err.println("rc: " + rc);7677errPW.close();78String errOut = errSW.toString();79System.err.println("Errors:\n" + errOut);8081check(errOut, "Errors.java", expectErrs);82check(errOut, " warning: ", expectWarns); // requires -locale en_US83}8485void check(String text, String expectText, int expectCount) {86int foundCount = 0;87for (String line: text.split("[\r\n]+")) {88if (line.contains(expectText))89foundCount++;90}91if (foundCount != expectCount) {92error("incorrect number of matches found: " + foundCount93+ ", expected: " + expectCount);94}95}9697private List<String> list(String... args) {98return Arrays.asList(args);99}100101void error(String msg) {102System.err.println(msg);103errors++;104}105106int count;107int errors;108}109110111