author | naoto |
Tue, 29 Mar 2016 17:06:33 -0700 | |
changeset 36739 | 145210aba850 |
parent 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
14952 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
17799
diff
changeset
|
2 |
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
14952 | 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 |
/* @test |
|
17799 | 25 |
* @bug 8004832 8000103 |
14962 | 26 |
* @summary Add new doclint package |
14952 | 27 |
* @summary Create doclint utility |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
17799
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.doclint |
14952 | 29 |
*/ |
30 |
||
31 |
import java.io.File; |
|
32 |
import java.io.IOException; |
|
33 |
import java.io.PrintWriter; |
|
34 |
import java.io.StringWriter; |
|
35 |
import java.lang.annotation.Annotation; |
|
36 |
import java.lang.annotation.Retention; |
|
37 |
import java.lang.annotation.RetentionPolicy; |
|
38 |
import java.lang.reflect.InvocationTargetException; |
|
39 |
import java.lang.reflect.Method; |
|
40 |
||
17799 | 41 |
import com.sun.tools.doclint.DocLint; |
42 |
import com.sun.tools.doclint.DocLint.BadArgs; |
|
43 |
||
14952 | 44 |
/** javadoc error on toplevel: a & b. */ |
45 |
public class RunTest { |
|
46 |
/** javadoc error on member: a < b */ |
|
47 |
public static void main(String... args) throws Exception { |
|
48 |
new RunTest().run(); |
|
49 |
} |
|
50 |
||
51 |
||
52 |
File testSrc = new File(System.getProperty("test.src")); |
|
53 |
File thisFile = new File(testSrc, RunTest.class.getSimpleName() + ".java"); |
|
54 |
||
55 |
void run() throws Exception { |
|
56 |
for (Method m: getClass().getDeclaredMethods()) { |
|
57 |
Annotation a = m.getAnnotation(Test.class); |
|
58 |
if (a != null) { |
|
59 |
System.err.println("test: " + m.getName()); |
|
60 |
try { |
|
61 |
StringWriter sw = new StringWriter(); |
|
62 |
PrintWriter pw = new PrintWriter(sw);; |
|
63 |
m.invoke(this, new Object[] { pw }); |
|
64 |
String out = sw.toString(); |
|
65 |
System.err.println(">>> " + out.replace("\n", "\n>>> ")); |
|
66 |
if (!out.contains("a < b")) |
|
67 |
error("\"a < b\" not found"); |
|
68 |
if (!out.contains("a & b")) |
|
69 |
error("\"a & b\" not found"); |
|
70 |
} catch (InvocationTargetException e) { |
|
71 |
Throwable cause = e.getCause(); |
|
72 |
throw (cause instanceof Exception) ? ((Exception) cause) : e; |
|
73 |
} |
|
74 |
System.err.println(); |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
if (errors > 0) |
|
79 |
throw new Exception(errors + " errors occurred"); |
|
80 |
} |
|
81 |
||
82 |
||
83 |
void error(String msg) { |
|
84 |
System.err.println("Error: " + msg); |
|
85 |
errors++; |
|
86 |
} |
|
87 |
||
88 |
int errors; |
|
89 |
||
90 |
/** Marker annotation for test cases. */ |
|
91 |
@Retention(RetentionPolicy.RUNTIME) |
|
92 |
@interface Test { } |
|
93 |
||
94 |
@Test |
|
95 |
void testMain(PrintWriter pw) throws BadArgs, IOException { |
|
96 |
String[] args = { "-Xmsgs", thisFile.getPath() }; |
|
97 |
DocLint d = new DocLint(); |
|
98 |
d.run(pw, args); |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |