author | bobv |
Tue, 07 Nov 2017 10:30:53 -0500 | |
changeset 47801 | c7b50c23ea71 |
parent 47216 | 71c04702a3d5 |
child 49822 | 53aae0c219e6 |
permissions | -rw-r--r-- |
42260 | 1 |
/* |
44020
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
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 |
|
44020
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
26 |
* @bug 8169676 8175055 |
42260 | 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 |
|
32 |
* @library /tools/lib |
|
33 |
* @build toolbox.JavacTask toolbox.JavadocTask toolbox.TestRunner toolbox.ToolBox |
|
34 |
* @run main BadOptionsTest |
|
35 |
*/ |
|
36 |
||
37 |
import java.io.IOException; |
|
38 |
import java.nio.file.Path; |
|
39 |
import java.nio.file.Paths; |
|
40 |
||
41 |
import toolbox.JavadocTask; |
|
42 |
import toolbox.ModuleBuilder; |
|
43 |
import toolbox.Task; |
|
44 |
import toolbox.TestRunner; |
|
45 |
import toolbox.ToolBox; |
|
46 |
||
47 |
/* |
|
48 |
* This is primarily a test of the error reporting mechanisms |
|
49 |
* for bad options provided by javac and utilized by javadoc. |
|
50 |
* It is not an exhaustive test of all bad option forms detected |
|
51 |
* by javac/javadoc. |
|
52 |
*/ |
|
53 |
public class BadOptionsTest extends TestRunner { |
|
54 |
||
55 |
public static void main(String... args) throws Exception { |
|
56 |
BadOptionsTest t = new BadOptionsTest(); |
|
57 |
t.runTests(); |
|
58 |
} |
|
59 |
||
60 |
private final ToolBox tb = new ToolBox(); |
|
61 |
private final Path src = Paths.get("src"); |
|
62 |
||
63 |
BadOptionsTest() throws IOException { |
|
64 |
super(System.err); |
|
65 |
init(); |
|
66 |
} |
|
67 |
||
68 |
void init() throws IOException { |
|
69 |
tb.writeJavaFiles(src, |
|
70 |
"public class C { }"); |
|
71 |
||
72 |
} |
|
73 |
||
74 |
@Test |
|
75 |
public void testAddModulesEmptyArg() { |
|
76 |
Task.Result result = new JavadocTask(tb, Task.Mode.CMDLINE) |
|
77 |
.options("--add-modules=") |
|
78 |
.files(src.resolve("C.java")) |
|
79 |
.run(Task.Expect.FAIL) |
|
80 |
.writeAll(); |
|
81 |
checkFound(result.getOutput(Task.OutputKind.DIRECT), |
|
82 |
"javadoc: error - no value for --add-modules option"); |
|
83 |
checkNotFound(result, "Exception", "at jdk.javadoc/"); |
|
84 |
} |
|
85 |
||
86 |
@Test |
|
87 |
public void testAddModulesBadName() { |
|
88 |
Task.Result result = new JavadocTask(tb, Task.Mode.CMDLINE) |
|
89 |
.options("-quiet", |
|
90 |
"--add-modules", "123") |
|
91 |
.files(src.resolve("C.java")) |
|
42269
24a766b7c106
8164590: javac --inherit-runtime-environment fails with "cannot find modules: ALL-DEFAULT"
jjg
parents:
42260
diff
changeset
|
92 |
.run(Task.Expect.FAIL) |
42260 | 93 |
.writeAll(); |
94 |
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
|
95 |
"error: bad name in value for --add-modules option: '123'"); |
42260 | 96 |
checkNotFound(result, "Exception", "at jdk.javadoc/"); |
97 |
} |
|
98 |
||
99 |
@Test |
|
100 |
public void testAddExportsEmptyArg() { |
|
101 |
Task.Result result = new JavadocTask(tb, Task.Mode.CMDLINE) |
|
102 |
.options("--add-exports=") |
|
103 |
.files(src.resolve("C.java")) |
|
104 |
.run(Task.Expect.FAIL) |
|
105 |
.writeAll(); |
|
106 |
checkFound(result.getOutput(Task.OutputKind.DIRECT), |
|
107 |
"javadoc: error - no value for --add-exports option"); |
|
108 |
checkNotFound(result, "Exception", "at jdk.javadoc/"); |
|
109 |
} |
|
110 |
||
111 |
@Test |
|
112 |
public void testAddExportsBadArg() { |
|
113 |
Task.Result result = new JavadocTask(tb, Task.Mode.CMDLINE) |
|
114 |
.options("--add-exports=m/p") |
|
115 |
.files(src.resolve("C.java")) |
|
116 |
.run(Task.Expect.FAIL) |
|
117 |
.writeAll(); |
|
118 |
checkFound(result.getOutput(Task.OutputKind.DIRECT), |
|
119 |
"javadoc: error - bad value for --add-exports option"); |
|
120 |
checkNotFound(result, "Exception", "at jdk.javadoc/"); |
|
121 |
} |
|
122 |
||
123 |
@Test |
|
124 |
public void testAddExportsBadName() { |
|
125 |
Task.Result result = new JavadocTask(tb, Task.Mode.CMDLINE) |
|
126 |
.options("--add-exports", "m!/p1=m2") |
|
127 |
.files(src.resolve("C.java")) |
|
128 |
.run() |
|
129 |
.writeAll(); |
|
130 |
checkFound(result.getOutput(Task.OutputKind.DIRECT), |
|
131 |
"warning: bad name in value for --add-exports option: 'm!'"); |
|
132 |
checkNotFound(result, "Exception", "at jdk.javadoc/"); |
|
133 |
} |
|
134 |
||
44020
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
135 |
@Test |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
136 |
public void testSourcePathAndModuleSourceConflict() throws IOException { |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
137 |
Path msrc = Paths.get("msrc"); |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
138 |
new ModuleBuilder(tb, "m1") |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
139 |
.exports("p1") |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
140 |
.classes("package p1; public class C1 { }") |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
141 |
.write(msrc); |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
142 |
Task.Result result = new JavadocTask(tb, Task.Mode.CMDLINE) |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
143 |
.options("-sourcepath", "src", |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
144 |
"--module-source-path", msrc.getFileName().toString(), |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
145 |
"--module", "m1") |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
146 |
.run(Task.Expect.FAIL) |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
147 |
.writeAll(); |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
148 |
checkFound(result.getOutput(Task.OutputKind.DIRECT), |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
149 |
"javadoc: cannot specify both --source-path and --module-source-path"); |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
150 |
checkFound(result.getOutput(Task.OutputKind.DIRECT), |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
151 |
"1 error"); |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
152 |
} |
ef5f709f4fd8
8175055: Errors reported by Arguments.validate should (probably) be fatal
ksrini
parents:
42269
diff
changeset
|
153 |
|
42260 | 154 |
private void checkFound(String log, String... expect) { |
155 |
for (String e : expect) { |
|
156 |
if (!log.contains(e)) { |
|
157 |
error("Expected string not found: '" + e + "'"); |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
161 |
||
162 |
private void checkNotFound(Task.Result result, String... unexpected) { |
|
163 |
for (Task.OutputKind k : Task.OutputKind.values()) { |
|
164 |
String r = result.getOutput(k); |
|
165 |
for (String u : unexpected) { |
|
166 |
if (r.contains(u)) { |
|
167 |
error("Unexpected string found: '" + u + "'"); |
|
168 |
} |
|
169 |
} |
|
170 |
} |
|
171 |
} |
|
172 |
} |