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