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