Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javadoc/6958836/Test.java
38813 views
/*1* Copyright (c) 2010, 2013, 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 800216826* @summary javadoc should support -Xmaxerrs and -Xmaxwarns27*/2829import java.io.*;30import java.util.*;3132public class Test {33public static void main(String... args) throws Exception {34new Test().run();35}3637void run() throws Exception {38javadoc("errs", list(), 10, 0);39javadoc("errs", list("-Xmaxerrs", "0"), 10, 0);40javadoc("errs", list("-Xmaxerrs", "2"), 2, 0);41javadoc("errs", list("-Xmaxerrs", "4"), 4, 0);42javadoc("errs", list("-Xmaxerrs", "20"), 10, 0);4344javadoc("warns", list(), 0, 10);45javadoc("warns", list("-Xmaxwarns", "0"), 0, 10);46javadoc("warns", list("-Xmaxwarns", "2"), 0, 2);47javadoc("warns", list("-Xmaxwarns", "4"), 0, 4);48javadoc("warns", list("-Xmaxwarns", "20"), 0, 10);4950if (errors > 0)51throw new Exception(errors + " errors occurred.");52}5354void javadoc(String pkg, List<String> testOpts,55int expectErrs, int expectWarns) {56System.err.println("Test " + (++count) + ": " + pkg + " " + testOpts);57File testOutDir = new File("test" + count);5859List<String> opts = new ArrayList<String>();60// Force en_US locale in lieu of something like -XDrawDiagnostics.61// For some reason, this must be the first option when used.62opts.addAll(list("-locale", "en_US"));63opts.add("-Xdoclint:none");64opts.addAll(list("-classpath", System.getProperty("test.src")));65opts.addAll(list("-d", testOutDir.getPath()));66opts.addAll(testOpts);67opts.add(pkg);6869StringWriter errSW = new StringWriter();70PrintWriter errPW = new PrintWriter(errSW);71StringWriter warnSW = new StringWriter();72PrintWriter warnPW = new PrintWriter(warnSW);73StringWriter noteSW = new StringWriter();74PrintWriter notePW = new PrintWriter(noteSW);7576int rc = com.sun.tools.javadoc.Main.execute("javadoc",77errPW, warnPW, notePW,78"com.sun.tools.doclets.standard.Standard",79getClass().getClassLoader(),80opts.toArray(new String[opts.size()]));81System.err.println("rc: " + rc);8283errPW.close();84String errOut = errSW.toString();85System.err.println("Errors:\n" + errOut);86warnPW.close();87String warnOut = warnSW.toString();88System.err.println("Warnings:\n" + warnOut);89notePW.close();90String noteOut = noteSW.toString();91System.err.println("Notes:\n" + noteOut);9293check(errOut, "Errors.java", expectErrs);94check(warnOut, " warning ", expectWarns); // requires -locale en_US95}9697void check(String text, String expectText, int expectCount) {98int foundCount = 0;99for (String line: text.split("[\r\n]+")) {100if (line.contains(expectText))101foundCount++;102}103if (foundCount != expectCount) {104error("incorrect number of matches found: " + foundCount105+ ", expected: " + expectCount);106}107}108109private List<String> list(String... args) {110return Arrays.asList(args);111}112113void error(String msg) {114System.err.println(msg);115errors++;116}117118int count;119int errors;120}121122123