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