Mon, 20 Jul 2015 11:41:52 -0700
Added tag jdk8u65-b06 for changeset ae5e31450299
jjg@584 | 1 | /* |
jjg@1490 | 2 | * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
jjg@584 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@584 | 4 | * |
jjg@584 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@584 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@584 | 7 | * published by the Free Software Foundation. |
jjg@584 | 8 | * |
jjg@584 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@584 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@584 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@584 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@584 | 13 | * accompanied this code). |
jjg@584 | 14 | * |
jjg@584 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@584 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@584 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@584 | 18 | * |
jjg@584 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@584 | 20 | * or visit www.oracle.com if you need additional information or have any |
jjg@584 | 21 | * questions. |
jjg@584 | 22 | */ |
jjg@584 | 23 | |
jjg@584 | 24 | /* |
jjg@584 | 25 | * @test |
jjg@1392 | 26 | * @bug 6958836 8002168 |
jjg@584 | 27 | * @summary javadoc should support -Xmaxerrs and -Xmaxwarns |
jjg@584 | 28 | */ |
jjg@584 | 29 | |
jjg@584 | 30 | import java.io.*; |
jjg@584 | 31 | import java.util.*; |
jjg@584 | 32 | |
jjg@584 | 33 | public class Test { |
jjg@584 | 34 | public static void main(String... args) throws Exception { |
jjg@584 | 35 | new Test().run(); |
jjg@584 | 36 | } |
jjg@584 | 37 | |
jjg@584 | 38 | void run() throws Exception { |
jjg@584 | 39 | javadoc("errs", list(), 10, 0); |
jjg@584 | 40 | javadoc("errs", list("-Xmaxerrs", "0"), 10, 0); |
jjg@584 | 41 | javadoc("errs", list("-Xmaxerrs", "2"), 2, 0); |
jjg@584 | 42 | javadoc("errs", list("-Xmaxerrs", "4"), 4, 0); |
jjg@584 | 43 | javadoc("errs", list("-Xmaxerrs", "20"), 10, 0); |
jjg@584 | 44 | |
jjg@584 | 45 | javadoc("warns", list(), 0, 10); |
jjg@584 | 46 | javadoc("warns", list("-Xmaxwarns", "0"), 0, 10); |
jjg@584 | 47 | javadoc("warns", list("-Xmaxwarns", "2"), 0, 2); |
jjg@584 | 48 | javadoc("warns", list("-Xmaxwarns", "4"), 0, 4); |
jjg@584 | 49 | javadoc("warns", list("-Xmaxwarns", "20"), 0, 10); |
jjg@584 | 50 | |
jjg@584 | 51 | if (errors > 0) |
jjg@584 | 52 | throw new Exception(errors + " errors occurred."); |
jjg@584 | 53 | } |
jjg@584 | 54 | |
jjg@584 | 55 | void javadoc(String pkg, List<String> testOpts, |
jjg@584 | 56 | int expectErrs, int expectWarns) { |
jjg@584 | 57 | System.err.println("Test " + (++count) + ": " + pkg + " " + testOpts); |
jjg@584 | 58 | File testOutDir = new File("test" + count); |
jjg@584 | 59 | |
jjg@584 | 60 | List<String> opts = new ArrayList<String>(); |
jjg@584 | 61 | // Force en_US locale in lieu of something like -XDrawDiagnostics. |
jjg@584 | 62 | // For some reason, this must be the first option when used. |
jjg@584 | 63 | opts.addAll(list("-locale", "en_US")); |
jjg@1490 | 64 | opts.add("-Xdoclint:none"); |
jjg@584 | 65 | opts.addAll(list("-classpath", System.getProperty("test.src"))); |
jjg@584 | 66 | opts.addAll(list("-d", testOutDir.getPath())); |
jjg@584 | 67 | opts.addAll(testOpts); |
jjg@584 | 68 | opts.add(pkg); |
jjg@584 | 69 | |
jjg@584 | 70 | StringWriter errSW = new StringWriter(); |
jjg@584 | 71 | PrintWriter errPW = new PrintWriter(errSW); |
jjg@584 | 72 | StringWriter warnSW = new StringWriter(); |
jjg@584 | 73 | PrintWriter warnPW = new PrintWriter(warnSW); |
jjg@584 | 74 | StringWriter noteSW = new StringWriter(); |
jjg@584 | 75 | PrintWriter notePW = new PrintWriter(noteSW); |
jjg@584 | 76 | |
jjg@584 | 77 | int rc = com.sun.tools.javadoc.Main.execute("javadoc", |
jjg@584 | 78 | errPW, warnPW, notePW, |
jjg@584 | 79 | "com.sun.tools.doclets.standard.Standard", |
jjg@584 | 80 | getClass().getClassLoader(), |
jjg@584 | 81 | opts.toArray(new String[opts.size()])); |
jjg@584 | 82 | System.err.println("rc: " + rc); |
jjg@584 | 83 | |
jjg@584 | 84 | errPW.close(); |
jjg@584 | 85 | String errOut = errSW.toString(); |
jjg@584 | 86 | System.err.println("Errors:\n" + errOut); |
jjg@584 | 87 | warnPW.close(); |
jjg@584 | 88 | String warnOut = warnSW.toString(); |
jjg@584 | 89 | System.err.println("Warnings:\n" + warnOut); |
jjg@584 | 90 | notePW.close(); |
jjg@584 | 91 | String noteOut = noteSW.toString(); |
jjg@584 | 92 | System.err.println("Notes:\n" + noteOut); |
jjg@584 | 93 | |
jjg@584 | 94 | check(errOut, "Errors.java", expectErrs); |
jjg@584 | 95 | check(warnOut, " warning ", expectWarns); // requires -locale en_US |
jjg@584 | 96 | } |
jjg@584 | 97 | |
jjg@584 | 98 | void check(String text, String expectText, int expectCount) { |
jjg@584 | 99 | int foundCount = 0; |
jjg@584 | 100 | for (String line: text.split("[\r\n]+")) { |
jjg@584 | 101 | if (line.contains(expectText)) |
jjg@584 | 102 | foundCount++; |
jjg@584 | 103 | } |
jjg@584 | 104 | if (foundCount != expectCount) { |
jjg@584 | 105 | error("incorrect number of matches found: " + foundCount |
jjg@584 | 106 | + ", expected: " + expectCount); |
jjg@584 | 107 | } |
jjg@584 | 108 | } |
jjg@584 | 109 | |
jjg@584 | 110 | private List<String> list(String... args) { |
jjg@584 | 111 | return Arrays.asList(args); |
jjg@584 | 112 | } |
jjg@584 | 113 | |
jjg@584 | 114 | void error(String msg) { |
jjg@584 | 115 | System.err.println(msg); |
jjg@584 | 116 | errors++; |
jjg@584 | 117 | } |
jjg@584 | 118 | |
jjg@584 | 119 | int count; |
jjg@584 | 120 | int errors; |
jjg@584 | 121 | } |