1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javadoc/6958836/Test.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,121 @@ 1.4 +/* 1.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 6958836 8002168 1.30 + * @summary javadoc should support -Xmaxerrs and -Xmaxwarns 1.31 + */ 1.32 + 1.33 +import java.io.*; 1.34 +import java.util.*; 1.35 + 1.36 +public class Test { 1.37 + public static void main(String... args) throws Exception { 1.38 + new Test().run(); 1.39 + } 1.40 + 1.41 + void run() throws Exception { 1.42 + javadoc("errs", list(), 10, 0); 1.43 + javadoc("errs", list("-Xmaxerrs", "0"), 10, 0); 1.44 + javadoc("errs", list("-Xmaxerrs", "2"), 2, 0); 1.45 + javadoc("errs", list("-Xmaxerrs", "4"), 4, 0); 1.46 + javadoc("errs", list("-Xmaxerrs", "20"), 10, 0); 1.47 + 1.48 + javadoc("warns", list(), 0, 10); 1.49 + javadoc("warns", list("-Xmaxwarns", "0"), 0, 10); 1.50 + javadoc("warns", list("-Xmaxwarns", "2"), 0, 2); 1.51 + javadoc("warns", list("-Xmaxwarns", "4"), 0, 4); 1.52 + javadoc("warns", list("-Xmaxwarns", "20"), 0, 10); 1.53 + 1.54 + if (errors > 0) 1.55 + throw new Exception(errors + " errors occurred."); 1.56 + } 1.57 + 1.58 + void javadoc(String pkg, List<String> testOpts, 1.59 + int expectErrs, int expectWarns) { 1.60 + System.err.println("Test " + (++count) + ": " + pkg + " " + testOpts); 1.61 + File testOutDir = new File("test" + count); 1.62 + 1.63 + List<String> opts = new ArrayList<String>(); 1.64 + // Force en_US locale in lieu of something like -XDrawDiagnostics. 1.65 + // For some reason, this must be the first option when used. 1.66 + opts.addAll(list("-locale", "en_US")); 1.67 + opts.add("-Xdoclint:none"); 1.68 + opts.addAll(list("-classpath", System.getProperty("test.src"))); 1.69 + opts.addAll(list("-d", testOutDir.getPath())); 1.70 + opts.addAll(testOpts); 1.71 + opts.add(pkg); 1.72 + 1.73 + StringWriter errSW = new StringWriter(); 1.74 + PrintWriter errPW = new PrintWriter(errSW); 1.75 + StringWriter warnSW = new StringWriter(); 1.76 + PrintWriter warnPW = new PrintWriter(warnSW); 1.77 + StringWriter noteSW = new StringWriter(); 1.78 + PrintWriter notePW = new PrintWriter(noteSW); 1.79 + 1.80 + int rc = com.sun.tools.javadoc.Main.execute("javadoc", 1.81 + errPW, warnPW, notePW, 1.82 + "com.sun.tools.doclets.standard.Standard", 1.83 + getClass().getClassLoader(), 1.84 + opts.toArray(new String[opts.size()])); 1.85 + System.err.println("rc: " + rc); 1.86 + 1.87 + errPW.close(); 1.88 + String errOut = errSW.toString(); 1.89 + System.err.println("Errors:\n" + errOut); 1.90 + warnPW.close(); 1.91 + String warnOut = warnSW.toString(); 1.92 + System.err.println("Warnings:\n" + warnOut); 1.93 + notePW.close(); 1.94 + String noteOut = noteSW.toString(); 1.95 + System.err.println("Notes:\n" + noteOut); 1.96 + 1.97 + check(errOut, "Errors.java", expectErrs); 1.98 + check(warnOut, " warning ", expectWarns); // requires -locale en_US 1.99 + } 1.100 + 1.101 + void check(String text, String expectText, int expectCount) { 1.102 + int foundCount = 0; 1.103 + for (String line: text.split("[\r\n]+")) { 1.104 + if (line.contains(expectText)) 1.105 + foundCount++; 1.106 + } 1.107 + if (foundCount != expectCount) { 1.108 + error("incorrect number of matches found: " + foundCount 1.109 + + ", expected: " + expectCount); 1.110 + } 1.111 + } 1.112 + 1.113 + private List<String> list(String... args) { 1.114 + return Arrays.asList(args); 1.115 + } 1.116 + 1.117 + void error(String msg) { 1.118 + System.err.println(msg); 1.119 + errors++; 1.120 + } 1.121 + 1.122 + int count; 1.123 + int errors; 1.124 +}