43145
|
1 |
/*
|
|
2 |
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
|
|
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 8172474
|
|
27 |
* @summary javac should enable doclint checking for HTML 5
|
|
28 |
* @library /tools/lib
|
|
29 |
* @modules jdk.compiler/com.sun.tools.javac.api
|
|
30 |
* jdk.compiler/com.sun.tools.javac.main
|
|
31 |
* @build toolbox.ToolBox toolbox.JavacTask
|
|
32 |
* @run main DocLintFormatTest
|
|
33 |
*/
|
|
34 |
|
|
35 |
import java.nio.file.Files;
|
|
36 |
import java.nio.file.Path;
|
|
37 |
import java.nio.file.Paths;
|
|
38 |
import java.util.List;
|
|
39 |
|
|
40 |
import toolbox.JavacTask;
|
|
41 |
import toolbox.Task;
|
|
42 |
import toolbox.ToolBox;
|
|
43 |
|
|
44 |
public class DocLintFormatTest {
|
|
45 |
public static void main(String... args) throws Exception {
|
|
46 |
new DocLintFormatTest().run();
|
|
47 |
}
|
|
48 |
|
|
49 |
private ToolBox tb = new ToolBox();
|
|
50 |
private Path src = Paths.get("src");
|
|
51 |
private Path classes = Paths.get("classes");
|
|
52 |
|
|
53 |
void run() throws Exception {
|
|
54 |
Files.createDirectories(classes);
|
|
55 |
|
|
56 |
tb.writeJavaFiles(src,
|
|
57 |
// 1 2
|
|
58 |
//2345678901234567890
|
|
59 |
"/** This is an <tt>HTML 4</tt> comment. */ public class Test4 { }",
|
|
60 |
"/** This is an <mark>HTML 5</mark> comment. */ public class Test5 { }"
|
|
61 |
);
|
|
62 |
|
|
63 |
test(src.resolve("Test4.java"), "html4");
|
|
64 |
test(src.resolve("Test4.java"), "html5",
|
|
65 |
"Test4.java:1:16: compiler.err.proc.messager: tag not supported in the generated HTML version: tt");
|
|
66 |
test(src.resolve("Test5.java"), "html4",
|
|
67 |
"Test5.java:1:16: compiler.err.proc.messager: tag not supported in the generated HTML version: mark");
|
|
68 |
test(src.resolve("Test5.java"), "html5");
|
|
69 |
|
|
70 |
if (errors > 0) {
|
|
71 |
throw new Exception(errors + " errors occurred");
|
|
72 |
}
|
|
73 |
}
|
|
74 |
|
|
75 |
void test(Path file, String format, String... expect) {
|
|
76 |
System.err.println("Test: " + format + " " + file);
|
|
77 |
List<String> output = new JavacTask(tb)
|
|
78 |
.outdir(classes)
|
|
79 |
.options("-XDrawDiagnostics", "-Xdoclint", "--doclint-format", format)
|
|
80 |
.files(file)
|
|
81 |
.run(expect.length == 0 ? Task.Expect.SUCCESS : Task.Expect.FAIL)
|
|
82 |
.writeAll()
|
|
83 |
.getOutputLines(Task.OutputKind.DIRECT);
|
|
84 |
|
|
85 |
if (expect.length == 0) {
|
|
86 |
if (!(output.size() == 1 && output.get(0).isEmpty())) {
|
|
87 |
error("All output unexpected.");
|
|
88 |
}
|
|
89 |
} else {
|
|
90 |
for (String e : expect) {
|
|
91 |
if (!output.contains(e)) {
|
|
92 |
error("expected output not found: " + e);
|
|
93 |
}
|
|
94 |
}
|
|
95 |
}
|
|
96 |
}
|
|
97 |
|
|
98 |
void error(String message) {
|
|
99 |
System.err.println("Error: " + message);
|
|
100 |
errors++;
|
|
101 |
}
|
|
102 |
|
|
103 |
private int errors = 0;
|
|
104 |
}
|
|
105 |
|