author | dstewart |
Thu, 29 Mar 2018 16:07:39 -0400 | |
changeset 49649 | 17c6ab93710e |
parent 47216 | 71c04702a3d5 |
child 49822 | 53aae0c219e6 |
permissions | -rw-r--r-- |
42260 | 1 |
/* |
45742 | 2 |
* Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved. |
42260 | 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 8169676 |
|
27 |
* @summary boolean result of Option.process is often ignored |
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.api |
|
29 |
* @modules jdk.compiler/com.sun.tools.javac.main |
|
30 |
* @modules jdk.javadoc/jdk.javadoc.internal.api |
|
31 |
* @modules jdk.javadoc/jdk.javadoc.internal.tool |
|
45742 | 32 |
* @library /tools/lib /tools/javadoc/lib |
33 |
* @build toolbox.JavacTask toolbox.JavadocTask toolbox.TestRunner toolbox.ToolBox ToyDoclet |
|
42260 | 34 |
* @run main BadOptionsTest |
35 |
*/ |
|
36 |
||
37 |
import java.io.IOException; |
|
38 |
import java.nio.file.Path; |
|
39 |
import java.nio.file.Paths; |
|
40 |
import java.util.ArrayList; |
|
41 |
import java.util.Arrays; |
|
42 |
import java.util.HashSet; |
|
43 |
import java.util.List; |
|
44 |
import java.util.ListIterator; |
|
45 |
import java.util.Locale; |
|
46 |
import java.util.Objects; |
|
47 |
import java.util.Set; |
|
48 |
||
49 |
import javax.lang.model.SourceVersion; |
|
50 |
||
51 |
import jdk.javadoc.doclet.Doclet; |
|
52 |
import jdk.javadoc.doclet.DocletEnvironment; |
|
53 |
import jdk.javadoc.doclet.Reporter; |
|
54 |
||
55 |
import toolbox.JavadocTask; |
|
56 |
import toolbox.ModuleBuilder; |
|
57 |
import toolbox.Task; |
|
58 |
import toolbox.TestRunner; |
|
59 |
import toolbox.ToolBox; |
|
60 |
||
61 |
/* |
|
62 |
* This is primarily a test of the error reporting mechanisms |
|
63 |
* for bad options provided by javac and utilized by javadoc. |
|
64 |
* It is not an exhaustive test of all bad option forms detected |
|
65 |
* by javac/javadoc. |
|
66 |
*/ |
|
67 |
public class BadOptionsTest extends TestRunner { |
|
68 |
||
69 |
public static void main(String... args) throws Exception { |
|
70 |
BadOptionsTest t = new BadOptionsTest(); |
|
71 |
t.runTests(); |
|
72 |
} |
|
73 |
||
74 |
private final ToolBox tb = new ToolBox(); |
|
75 |
private final Path src = Paths.get("src"); |
|
45742 | 76 |
private final Class<?> docletClass; |
42260 | 77 |
|
45742 | 78 |
BadOptionsTest() throws Exception { |
42260 | 79 |
super(System.err); |
45742 | 80 |
docletClass = getClass().getClassLoader().loadClass("ToyDoclet"); |
42260 | 81 |
init(); |
82 |
} |
|
83 |
||
84 |
void init() throws IOException { |
|
85 |
tb.writeJavaFiles(src, |
|
86 |
"public class C { }"); |
|
87 |
||
88 |
} |
|
89 |
||
90 |
@Test |
|
91 |
public void testAddModulesEmptyArg() { |
|
45742 | 92 |
Task.Result result = new JavadocTask(tb, Task.Mode.API) |
93 |
.docletClass(docletClass) |
|
94 |
.options("--add-modules", "") |
|
42260 | 95 |
.files(src.resolve("C.java")) |
96 |
.run(Task.Expect.FAIL) |
|
97 |
.writeAll(); |
|
98 |
checkFound(result.getOutput(Task.OutputKind.DIRECT), |
|
99 |
"javadoc: error - no value for --add-modules option"); |
|
100 |
checkNotFound(result, "Exception", "at jdk.javadoc/"); |
|
101 |
} |
|
102 |
||
103 |
@Test |
|
104 |
public void testAddModulesBadName() { |
|
45742 | 105 |
Task.Result result = new JavadocTask(tb, Task.Mode.API) |
106 |
.docletClass(docletClass) |
|
107 |
.options("--add-modules", "123") |
|
42260 | 108 |
.files(src.resolve("C.java")) |
42269
24a766b7c106
8164590: javac --inherit-runtime-environment fails with "cannot find modules: ALL-DEFAULT"
jjg
parents:
42260
diff
changeset
|
109 |
.run(Task.Expect.FAIL) |
42260 | 110 |
.writeAll(); |
111 |
checkFound(result.getOutput(Task.OutputKind.DIRECT), |
|
42269
24a766b7c106
8164590: javac --inherit-runtime-environment fails with "cannot find modules: ALL-DEFAULT"
jjg
parents:
42260
diff
changeset
|
112 |
"error: bad name in value for --add-modules option: '123'"); |
42260 | 113 |
checkNotFound(result, "Exception", "at jdk.javadoc/"); |
114 |
} |
|
115 |
||
116 |
@Test |
|
117 |
public void testAddExportsEmptyArg() { |
|
45742 | 118 |
Task.Result result = new JavadocTask(tb, Task.Mode.API) |
119 |
.docletClass(docletClass) |
|
120 |
.options("--add-exports", "") |
|
42260 | 121 |
.files(src.resolve("C.java")) |
122 |
.run(Task.Expect.FAIL) |
|
123 |
.writeAll(); |
|
124 |
checkFound(result.getOutput(Task.OutputKind.DIRECT), |
|
125 |
"javadoc: error - no value for --add-exports option"); |
|
126 |
checkNotFound(result, "Exception", "at jdk.javadoc/"); |
|
127 |
} |
|
128 |
||
129 |
@Test |
|
130 |
public void testAddExportsBadArg() { |
|
45742 | 131 |
Task.Result result = new JavadocTask(tb, Task.Mode.API) |
132 |
.docletClass(docletClass) |
|
133 |
.options("--add-exports", "m/p") |
|
42260 | 134 |
.files(src.resolve("C.java")) |
135 |
.run(Task.Expect.FAIL) |
|
136 |
.writeAll(); |
|
137 |
checkFound(result.getOutput(Task.OutputKind.DIRECT), |
|
138 |
"javadoc: error - bad value for --add-exports option"); |
|
139 |
checkNotFound(result, "Exception", "at jdk.javadoc/"); |
|
140 |
} |
|
141 |
||
142 |
@Test |
|
143 |
public void testAddExportsBadName() { |
|
45742 | 144 |
Task.Result result = new JavadocTask(tb, Task.Mode.API) |
145 |
.docletClass(docletClass) |
|
146 |
.options("--add-exports", "m!/p1=m2") |
|
42260 | 147 |
.files(src.resolve("C.java")) |
148 |
.run() |
|
149 |
.writeAll(); |
|
150 |
checkFound(result.getOutput(Task.OutputKind.DIRECT), |
|
151 |
"warning: bad name in value for --add-exports option: 'm!'"); |
|
152 |
checkNotFound(result, "Exception", "at jdk.javadoc/"); |
|
153 |
} |
|
154 |
||
155 |
private void checkFound(String log, String... expect) { |
|
156 |
for (String e : expect) { |
|
157 |
if (!log.contains(e)) { |
|
158 |
error("Expected string not found: '" + e + "'"); |
|
159 |
} |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
private void checkNotFound(Task.Result result, String... unexpected) { |
|
164 |
for (Task.OutputKind k : Task.OutputKind.values()) { |
|
165 |
String r = result.getOutput(k); |
|
166 |
for (String u : unexpected) { |
|
167 |
if (r.contains(u)) { |
|
168 |
error("Unexpected string found: '" + u + "'"); |
|
169 |
} |
|
170 |
} |
|
171 |
} |
|
172 |
} |
|
173 |
} |