author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 45742 | langtools/test/tools/javadoc/MaxWarns.java@36bf0f2436ad |
permissions | -rw-r--r-- |
15041 | 1 |
/* |
45742 | 2 |
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. |
15041 | 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 |
|
26 |
* @bug 8005644 |
|
27 |
* @summary set default max errs and max warns |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
15354
diff
changeset
|
28 |
* @modules jdk.javadoc/com.sun.tools.doclets.standard |
15041 | 29 |
*/ |
30 |
||
31 |
import java.io.File; |
|
32 |
import java.io.PrintWriter; |
|
33 |
import java.io.StringWriter; |
|
34 |
import java.util.regex.Matcher; |
|
35 |
import java.util.regex.Pattern; |
|
36 |
||
45742 | 37 |
import com.sun.javadoc.DocErrorReporter; |
38 |
import com.sun.javadoc.RootDoc; |
|
15041 | 39 |
|
40 |
public class MaxWarns { |
|
41 |
public static void main(String... args) throws Exception { |
|
42 |
new MaxWarns().run(); |
|
43 |
} |
|
44 |
||
45 |
void run() throws Exception { |
|
46 |
final int defaultMaxWarns = 100; |
|
45742 | 47 |
File f = new File(System.getProperty("test.src"), "MaxWarns.java"); |
15041 | 48 |
String out = javadoc(f); |
49 |
check(out, defaultMaxWarns); |
|
50 |
||
51 |
if (errors > 0) |
|
52 |
throw new Exception(errors + " errors occurred"); |
|
53 |
} |
|
54 |
||
55 |
String javadoc(File f) { |
|
56 |
StringWriter sw = new StringWriter(); |
|
57 |
PrintWriter pw = new PrintWriter(sw); |
|
45742 | 58 |
String[] args = { f.getPath() }; |
15041 | 59 |
int rc = com.sun.tools.javadoc.Main.execute("javadoc", pw, pw, pw, |
45742 | 60 |
"MaxWarns$TestDoclet", |
61 |
getClass().getClassLoader(), args); |
|
15041 | 62 |
pw.flush(); |
63 |
return sw.toString(); |
|
64 |
} |
|
65 |
||
45742 | 66 |
private static final String WARNING_TEXT = "count "; |
67 |
||
15041 | 68 |
void check(String out, int count) { |
69 |
System.err.println(out); |
|
45742 | 70 |
Pattern warn = Pattern.compile("warning - " + WARNING_TEXT + "[0-9]+"); |
15041 | 71 |
Matcher m = warn.matcher(out); |
72 |
int n = 0; |
|
73 |
for (int start = 0; m.find(start); start = m.start() + 1) { |
|
74 |
n++; |
|
75 |
} |
|
76 |
if (n != count) |
|
77 |
error("unexpected number of warnings reported: " + n + "; expected: " + count); |
|
78 |
||
79 |
Pattern warnCount = Pattern.compile("(?ms).*^([0-9]+) warnings$.*"); |
|
80 |
m = warnCount.matcher(out); |
|
81 |
if (m.matches()) { |
|
82 |
n = Integer.parseInt(m.group(1)); |
|
83 |
if (n != count) |
|
84 |
error("unexpected number of warnings reported: " + n + "; expected: " + count); |
|
85 |
} else |
|
86 |
error("total count not found"); |
|
87 |
} |
|
88 |
||
89 |
void error(String msg) { |
|
90 |
System.err.println("Error: " + msg); |
|
91 |
errors++; |
|
92 |
} |
|
93 |
||
94 |
int errors; |
|
45742 | 95 |
|
96 |
public static class TestDoclet { |
|
97 |
||
98 |
public static boolean start(RootDoc root) { |
|
99 |
// generate 150 warnings |
|
100 |
for (int i = 1 ; i <= 150 ; i++) { |
|
101 |
root.printWarning(WARNING_TEXT + i); |
|
102 |
} |
|
103 |
return true; |
|
104 |
} |
|
105 |
||
106 |
public static int optionLength(String option) { |
|
107 |
return 0; |
|
108 |
} |
|
109 |
||
110 |
public static boolean validOptions(String[][] options, DocErrorReporter reporter) { |
|
111 |
return true; |
|
112 |
} |
|
113 |
} |
|
15041 | 114 |
} |
115 |