aoqi@0: /* aoqi@0: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 6958836 8002168 aoqi@0: * @summary javadoc should support -Xmaxerrs and -Xmaxwarns aoqi@0: */ aoqi@0: aoqi@0: import java.io.*; aoqi@0: import java.util.*; aoqi@0: aoqi@0: public class Test { aoqi@0: public static void main(String... args) throws Exception { aoqi@0: new Test().run(); aoqi@0: } aoqi@0: aoqi@0: void run() throws Exception { aoqi@0: javadoc("errs", list(), 10, 0); aoqi@0: javadoc("errs", list("-Xmaxerrs", "0"), 10, 0); aoqi@0: javadoc("errs", list("-Xmaxerrs", "2"), 2, 0); aoqi@0: javadoc("errs", list("-Xmaxerrs", "4"), 4, 0); aoqi@0: javadoc("errs", list("-Xmaxerrs", "20"), 10, 0); aoqi@0: aoqi@0: javadoc("warns", list(), 0, 10); aoqi@0: javadoc("warns", list("-Xmaxwarns", "0"), 0, 10); aoqi@0: javadoc("warns", list("-Xmaxwarns", "2"), 0, 2); aoqi@0: javadoc("warns", list("-Xmaxwarns", "4"), 0, 4); aoqi@0: javadoc("warns", list("-Xmaxwarns", "20"), 0, 10); aoqi@0: aoqi@0: if (errors > 0) aoqi@0: throw new Exception(errors + " errors occurred."); aoqi@0: } aoqi@0: aoqi@0: void javadoc(String pkg, List testOpts, aoqi@0: int expectErrs, int expectWarns) { aoqi@0: System.err.println("Test " + (++count) + ": " + pkg + " " + testOpts); aoqi@0: File testOutDir = new File("test" + count); aoqi@0: aoqi@0: List opts = new ArrayList(); aoqi@0: // Force en_US locale in lieu of something like -XDrawDiagnostics. aoqi@0: // For some reason, this must be the first option when used. aoqi@0: opts.addAll(list("-locale", "en_US")); aoqi@0: opts.add("-Xdoclint:none"); aoqi@0: opts.addAll(list("-classpath", System.getProperty("test.src"))); aoqi@0: opts.addAll(list("-d", testOutDir.getPath())); aoqi@0: opts.addAll(testOpts); aoqi@0: opts.add(pkg); aoqi@0: aoqi@0: StringWriter errSW = new StringWriter(); aoqi@0: PrintWriter errPW = new PrintWriter(errSW); aoqi@0: StringWriter warnSW = new StringWriter(); aoqi@0: PrintWriter warnPW = new PrintWriter(warnSW); aoqi@0: StringWriter noteSW = new StringWriter(); aoqi@0: PrintWriter notePW = new PrintWriter(noteSW); aoqi@0: aoqi@0: int rc = com.sun.tools.javadoc.Main.execute("javadoc", aoqi@0: errPW, warnPW, notePW, aoqi@0: "com.sun.tools.doclets.standard.Standard", aoqi@0: getClass().getClassLoader(), aoqi@0: opts.toArray(new String[opts.size()])); aoqi@0: System.err.println("rc: " + rc); aoqi@0: aoqi@0: errPW.close(); aoqi@0: String errOut = errSW.toString(); aoqi@0: System.err.println("Errors:\n" + errOut); aoqi@0: warnPW.close(); aoqi@0: String warnOut = warnSW.toString(); aoqi@0: System.err.println("Warnings:\n" + warnOut); aoqi@0: notePW.close(); aoqi@0: String noteOut = noteSW.toString(); aoqi@0: System.err.println("Notes:\n" + noteOut); aoqi@0: aoqi@0: check(errOut, "Errors.java", expectErrs); aoqi@0: check(warnOut, " warning ", expectWarns); // requires -locale en_US aoqi@0: } aoqi@0: aoqi@0: void check(String text, String expectText, int expectCount) { aoqi@0: int foundCount = 0; aoqi@0: for (String line: text.split("[\r\n]+")) { aoqi@0: if (line.contains(expectText)) aoqi@0: foundCount++; aoqi@0: } aoqi@0: if (foundCount != expectCount) { aoqi@0: error("incorrect number of matches found: " + foundCount aoqi@0: + ", expected: " + expectCount); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private List list(String... args) { aoqi@0: return Arrays.asList(args); aoqi@0: } aoqi@0: aoqi@0: void error(String msg) { aoqi@0: System.err.println(msg); aoqi@0: errors++; aoqi@0: } aoqi@0: aoqi@0: int count; aoqi@0: int errors; aoqi@0: }