author | jjg |
Tue, 22 Nov 2016 15:57:32 -0800 | |
changeset 42269 | 24a766b7c106 |
parent 41942 | 260c724e5614 |
child 42407 | f3702cff2933 |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, 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 |
* @summary simple tests of module provides |
|
41942
260c724e5614
8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents:
40308
diff
changeset
|
27 |
* @bug 8168854 |
36526 | 28 |
* @library /tools/lib |
29 |
* @modules |
|
30 |
* jdk.compiler/com.sun.tools.javac.api |
|
31 |
* jdk.compiler/com.sun.tools.javac.main |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
32 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
36526 | 33 |
* @run main ProvidesTest |
34 |
*/ |
|
35 |
||
36 |
import java.nio.file.Files; |
|
37 |
import java.nio.file.Path; |
|
38 |
import java.util.Arrays; |
|
39 |
import java.util.List; |
|
40 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
41 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
42 |
import toolbox.Task; |
41942
260c724e5614
8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents:
40308
diff
changeset
|
43 |
import toolbox.Task.Expect; |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
44 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
45 |
|
36526 | 46 |
public class ProvidesTest extends ModuleTestBase { |
47 |
public static void main(String... args) throws Exception { |
|
48 |
ProvidesTest t = new ProvidesTest(); |
|
49 |
t.runTests(); |
|
50 |
} |
|
51 |
||
52 |
@Test |
|
37758 | 53 |
public void testSimple(Path base) throws Exception { |
36526 | 54 |
Path src = base.resolve("src"); |
55 |
tb.writeJavaFiles(src, |
|
56 |
"module m { provides p1.C1 with p2.C2; }", |
|
57 |
"package p1; public class C1 { }", |
|
58 |
"package p2; public class C2 extends p1.C1 { }"); |
|
59 |
Path classes = base.resolve("classes"); |
|
60 |
Files.createDirectories(classes); |
|
61 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
62 |
new JavacTask(tb) |
36526 | 63 |
.outdir(classes) |
64 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
65 |
.run(Task.Expect.SUCCESS) |
36526 | 66 |
.writeAll(); |
67 |
} |
|
68 |
||
69 |
@Test |
|
37758 | 70 |
public void testMulti(Path base) throws Exception { |
36526 | 71 |
Path src = base.resolve("src"); |
72 |
tb.writeJavaFiles(src.resolve("m1"), |
|
73 |
"module m1 { exports p1; }", |
|
74 |
"package p1; public class C1 { }"); |
|
75 |
tb.writeJavaFiles(src.resolve("m2"), |
|
76 |
"module m2 { requires m1; provides p1.C1 with p2.C2; }", |
|
77 |
"package p2; public class C2 extends p1.C1 { }"); |
|
78 |
Path modules = base.resolve("modules"); |
|
79 |
Files.createDirectories(modules); |
|
80 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
81 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38827
diff
changeset
|
82 |
.options("--module-source-path", src.toString()) |
36526 | 83 |
.outdir(modules) |
84 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
85 |
.run(Task.Expect.SUCCESS) |
36526 | 86 |
.writeAll(); |
87 |
||
88 |
} |
|
89 |
||
90 |
@Test |
|
37758 | 91 |
public void testMissingWith(Path base) throws Exception { |
36526 | 92 |
Path src = base.resolve("src"); |
93 |
tb.writeJavaFiles(src, |
|
94 |
"module m { provides p.C; }", |
|
95 |
"package p; public class C { }"); |
|
96 |
Path classes = base.resolve("classes"); |
|
97 |
Files.createDirectories(classes); |
|
98 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
99 |
String log = new JavacTask(tb) |
36526 | 100 |
.options("-XDrawDiagnostics") |
101 |
.outdir(classes) |
|
102 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
103 |
.run(Task.Expect.FAIL) |
36526 | 104 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
105 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 106 |
|
107 |
if (!log.contains("module-info.java:1:24: compiler.err.expected: 'with'")) |
|
108 |
throw new Exception("expected output not found"); |
|
109 |
||
110 |
} |
|
111 |
||
112 |
@Test |
|
37758 | 113 |
public void testDuplicateProvides(Path base) throws Exception { |
36526 | 114 |
Path src = base.resolve("src"); |
115 |
tb.writeJavaFiles(src, |
|
116 |
"module m { provides p1.C1 with p2.C2; provides p1.C1 with p2.C2; }", |
|
117 |
"package p1; public class C1 { }", |
|
118 |
"package p2; public class C2 extends p1.C1 { }"); |
|
119 |
Path classes = base.resolve("classes"); |
|
120 |
Files.createDirectories(classes); |
|
121 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
122 |
new JavacTask(tb) |
36526 | 123 |
.options("-XDrawDiagnostic") |
124 |
.outdir(classes) |
|
125 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
126 |
.run(Task.Expect.FAIL) |
36526 | 127 |
.writeAll(); |
128 |
} |
|
129 |
||
130 |
@Test |
|
37758 | 131 |
public void testMissingService(Path base) throws Exception { |
36526 | 132 |
Path src = base.resolve("src"); |
133 |
tb.writeJavaFiles(src, |
|
134 |
"module m { provides p.Missing with p.C; }", |
|
135 |
"package p; public class C extends p.Missing { }"); |
|
136 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
137 |
List<String> output = new JavacTask(tb) |
36526 | 138 |
.options("-XDrawDiagnostics") |
139 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
140 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
141 |
.run(Task.Expect.FAIL) |
36526 | 142 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
143 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 144 |
|
145 |
List<String> expected = Arrays.asList( |
|
146 |
"C.java:1:36: compiler.err.cant.resolve.location: kindname.class, Missing, , , (compiler.misc.location: kindname.package, p, null)", |
|
147 |
"module-info.java:1:22: compiler.err.cant.resolve.location: kindname.class, Missing, , , (compiler.misc.location: kindname.package, p, null)", |
|
38827
884d32899770
8152062: obscure error message for bad 'provides'
vromero
parents:
37758
diff
changeset
|
148 |
"2 errors"); |
36526 | 149 |
if (!output.containsAll(expected)) { |
150 |
throw new Exception("Expected output not found"); |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
@Test |
|
37758 | 155 |
public void testProvidesFromAnotherModule(Path base) throws Exception { |
36526 | 156 |
Path modules = base.resolve("modules"); |
157 |
tb.writeJavaFiles(modules.resolve("M"), |
|
158 |
"module M { exports p; }", |
|
159 |
"package p; public class Service { }"); |
|
160 |
tb.writeJavaFiles(modules.resolve("L"), |
|
161 |
"module L { requires M; provides p.Service with p.Service; }"); |
|
162 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
163 |
List<String> output = new JavacTask(tb) |
36526 | 164 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38827
diff
changeset
|
165 |
"--module-source-path", modules.toString()) |
36526 | 166 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
167 |
.files(findJavaFiles(modules)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
168 |
.run(Task.Expect.FAIL) |
36526 | 169 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
170 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 171 |
List<String> expected = Arrays.asList( |
172 |
"module-info.java:1:24: compiler.err.service.implementation.not.in.right.module: M", |
|
173 |
"1 error"); |
|
174 |
if (!output.containsAll(expected)) { |
|
175 |
throw new Exception("Expected output not found"); |
|
176 |
} |
|
177 |
||
178 |
} |
|
179 |
||
180 |
@Test |
|
37758 | 181 |
public void testServiceIsNotImplemented(Path base) throws Exception { |
36526 | 182 |
Path src = base.resolve("src"); |
183 |
tb.writeJavaFiles(src, |
|
184 |
"module m { provides p.A with p.B; }", |
|
185 |
"package p; public class A { }", |
|
186 |
"package p; public class B { }"); |
|
187 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
188 |
List<String> output = new JavacTask(tb) |
36526 | 189 |
.options("-XDrawDiagnostics") |
190 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
191 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
192 |
.run(Task.Expect.FAIL) |
36526 | 193 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
194 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 195 |
|
38827
884d32899770
8152062: obscure error message for bad 'provides'
vromero
parents:
37758
diff
changeset
|
196 |
List<String> expected = Arrays.asList( |
884d32899770
8152062: obscure error message for bad 'provides'
vromero
parents:
37758
diff
changeset
|
197 |
"module-info.java:1:31: compiler.err.service.implementation.must.be.subtype.of.service.interface", |
884d32899770
8152062: obscure error message for bad 'provides'
vromero
parents:
37758
diff
changeset
|
198 |
"module-info.java:1:12: compiler.warn.service.provided.but.not.exported.or.used: p.A", |
884d32899770
8152062: obscure error message for bad 'provides'
vromero
parents:
37758
diff
changeset
|
199 |
"1 error", |
884d32899770
8152062: obscure error message for bad 'provides'
vromero
parents:
37758
diff
changeset
|
200 |
"1 warning"); |
36526 | 201 |
if (!output.containsAll(expected)) { |
202 |
throw new Exception("Expected output not found"); |
|
203 |
} |
|
204 |
} |
|
205 |
||
206 |
@Test |
|
37758 | 207 |
public void testMissingImplementation(Path base) throws Exception { |
36526 | 208 |
Path src = base.resolve("src"); |
209 |
tb.writeJavaFiles(src, |
|
210 |
"module m { provides p.C with p.Impl; }", |
|
211 |
"package p; public class C { }"); |
|
212 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
213 |
List<String> output = new JavacTask(tb) |
36526 | 214 |
.options("-XDrawDiagnostics") |
215 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
216 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
217 |
.run(Task.Expect.FAIL) |
36526 | 218 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
219 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 220 |
|
221 |
List<String> expected = Arrays.asList("module-info.java:1:31: compiler.err.cant.resolve.location: kindname.class, Impl, , , (compiler.misc.location: kindname.package, p, null)", |
|
222 |
"1 error"); |
|
223 |
if (!output.containsAll(expected)) { |
|
224 |
throw new Exception("Expected output not found"); |
|
225 |
} |
|
226 |
} |
|
227 |
||
228 |
@Test |
|
37758 | 229 |
public void testSeveralImplementations(Path base) throws Exception { |
36526 | 230 |
Path src = base.resolve("src"); |
231 |
tb.writeJavaFiles(src, |
|
232 |
"module m { provides p.C with p.Impl1; provides p.C with p.Impl2; }", |
|
233 |
"package p; public class C { }", |
|
234 |
"package p; public class Impl1 extends p.C { }", |
|
235 |
"package p; public class Impl2 extends p.C { }"); |
|
236 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
237 |
new JavacTask(tb) |
36526 | 238 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
239 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
240 |
.run(Task.Expect.SUCCESS) |
36526 | 241 |
.writeAll(); |
242 |
} |
|
243 |
||
244 |
@Test |
|
37758 | 245 |
public void testOneImplementationsForServices(Path base) throws Exception { |
36526 | 246 |
Path src = base.resolve("src"); |
247 |
tb.writeJavaFiles(src, |
|
248 |
"module m { provides p.Service1 with p.Impl; provides p.Service2 with p.Impl; }", |
|
249 |
"package p; public interface Service1 { }", |
|
250 |
"package p; public abstract class Service2 { }", |
|
251 |
"package p; public class Impl extends p.Service2 implements p.Service1 { }"); |
|
252 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
253 |
new JavacTask(tb) |
36526 | 254 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
255 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
256 |
.run(Task.Expect.SUCCESS) |
36526 | 257 |
.writeAll(); |
258 |
} |
|
259 |
||
260 |
@Test |
|
37758 | 261 |
public void testAbstractImplementation(Path base) throws Exception { |
36526 | 262 |
Path src = base.resolve("src"); |
263 |
tb.writeJavaFiles(src, |
|
264 |
"module m { provides p1.C1 with p2.C2; }", |
|
265 |
"package p1; public class C1 { }", |
|
266 |
"package p2; public abstract class C2 extends p1.C1 { }"); |
|
267 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
268 |
List<String> output = new JavacTask(tb) |
36526 | 269 |
.options("-XDrawDiagnostics") |
270 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
271 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
272 |
.run(Task.Expect.FAIL) |
36526 | 273 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
274 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 275 |
|
276 |
List<String> expected = Arrays.asList( |
|
277 |
"module-info.java:1:34: compiler.err.service.implementation.is.abstract: p2.C2"); |
|
278 |
if (!output.containsAll(expected)) { |
|
279 |
throw new Exception("Expected output not found"); |
|
280 |
} |
|
281 |
} |
|
282 |
||
283 |
@Test |
|
37758 | 284 |
public void testInterfaceImplementation(Path base) throws Exception { |
36526 | 285 |
Path src = base.resolve("src"); |
286 |
tb.writeJavaFiles(src, |
|
287 |
"module m { provides p1.Service with p2.Impl; }", |
|
288 |
"package p1; public interface Service { }", |
|
289 |
"package p2; public interface Impl extends p1.Service { }"); |
|
290 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
291 |
List<String> output = new JavacTask(tb) |
36526 | 292 |
.options("-XDrawDiagnostics") |
293 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
294 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
295 |
.run(Task.Expect.FAIL) |
36526 | 296 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
297 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 298 |
|
299 |
List<String> expected = Arrays.asList( |
|
300 |
"module-info.java:1:39: compiler.err.service.implementation.is.abstract: p2.Impl"); |
|
301 |
if (!output.containsAll(expected)) { |
|
302 |
throw new Exception("Expected output not found"); |
|
303 |
} |
|
304 |
} |
|
305 |
||
306 |
@Test |
|
37758 | 307 |
public void testProtectedImplementation(Path base) throws Exception { |
36526 | 308 |
Path src = base.resolve("src"); |
309 |
tb.writeJavaFiles(src, |
|
310 |
"module m { provides p1.C1 with p2.C2; }", |
|
311 |
"package p1; public class C1 { }", |
|
312 |
"package p2; class C2 extends p1.C1 { }"); |
|
313 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
314 |
List<String> output = new JavacTask(tb) |
36526 | 315 |
.options("-XDrawDiagnostics") |
316 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
317 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
318 |
.run(Task.Expect.FAIL) |
36526 | 319 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
320 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 321 |
|
322 |
List<String> expected = Arrays.asList("module-info.java:1:34: compiler.err.not.def.public.cant.access: p2.C2, p2", |
|
323 |
"1 error"); |
|
324 |
if (!output.containsAll(expected)) { |
|
325 |
throw new Exception("Expected output not found"); |
|
326 |
} |
|
327 |
} |
|
328 |
||
329 |
@Test |
|
37758 | 330 |
public void testNoNoArgConstructor(Path base) throws Exception { |
36526 | 331 |
Path src = base.resolve("src"); |
332 |
tb.writeJavaFiles(src, |
|
333 |
"module m { uses p1.C1; provides p1.C1 with p2.C2; }", |
|
334 |
"package p1; public class C1 { }", |
|
335 |
"package p2; public class C2 extends p1.C1 { public C2(String str) { } }"); |
|
336 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
337 |
List<String> output = new JavacTask(tb) |
36526 | 338 |
.options("-XDrawDiagnostics") |
339 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
340 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
341 |
.run(Task.Expect.FAIL) |
36526 | 342 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
343 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 344 |
|
345 |
List<String> expected = Arrays.asList( |
|
346 |
"module-info.java:1:46: compiler.err.service.implementation.doesnt.have.a.no.args.constructor: p2.C2"); |
|
347 |
if (!output.containsAll(expected)) { |
|
348 |
throw new Exception("Expected output not found"); |
|
349 |
} |
|
350 |
} |
|
351 |
||
352 |
@Test |
|
37758 | 353 |
public void testPrivateNoArgConstructor(Path base) throws Exception { |
36526 | 354 |
Path src = base.resolve("src"); |
355 |
tb.writeJavaFiles(src, |
|
356 |
"module m { uses p1.C1; provides p1.C1 with p2.C2; }", |
|
357 |
"package p1; public class C1 { }", |
|
358 |
"package p2; public class C2 extends p1.C1 { private C2() { } }"); |
|
359 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
360 |
List<String> output = new JavacTask(tb) |
36526 | 361 |
.options("-XDrawDiagnostics") |
362 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
363 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
364 |
.run(Task.Expect.FAIL) |
36526 | 365 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
366 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 367 |
|
368 |
List<String> expected = Arrays.asList( |
|
369 |
"module-info.java:1:46: compiler.err.service.implementation.no.args.constructor.not.public: p2.C2"); |
|
370 |
if (!output.containsAll(expected)) { |
|
371 |
throw new Exception("Expected output not found"); |
|
372 |
} |
|
373 |
} |
|
374 |
||
375 |
@Test |
|
37758 | 376 |
public void testServiceIndirectlyImplemented(Path base) throws Exception { |
36526 | 377 |
Path src = base.resolve("src"); |
378 |
tb.writeJavaFiles(src, |
|
379 |
"module m { provides p1.C1 with p2.C3; }", |
|
380 |
"package p1; public class C1 { }", |
|
381 |
"package p2; public class C2 extends p1.C1 { }", |
|
382 |
"package p2; public class C3 extends p2.C2 { }"); |
|
383 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
384 |
new JavacTask(tb) |
36526 | 385 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
386 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
387 |
.run(Task.Expect.SUCCESS) |
36526 | 388 |
.writeAll(); |
389 |
} |
|
390 |
||
391 |
@Test |
|
37758 | 392 |
public void testServiceImplementationInnerClass(Path base) throws Exception { |
36526 | 393 |
Path src = base.resolve("src"); |
394 |
tb.writeJavaFiles(src, |
|
395 |
"module m { provides p1.C1 with p2.C2.Inner; }", |
|
396 |
"package p1; public class C1 { }", |
|
397 |
"package p2; public class C2 { public class Inner extends p1.C1 { } }"); |
|
398 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
399 |
List<String> output = new JavacTask(tb) |
36526 | 400 |
.options("-XDrawDiagnostics") |
401 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
402 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
403 |
.run(Task.Expect.FAIL) |
36526 | 404 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
405 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 406 |
|
407 |
List<String> expected = Arrays.asList( |
|
408 |
"module-info.java:1:37: compiler.err.service.implementation.is.inner: p2.C2.Inner"); |
|
409 |
if (!output.containsAll(expected)) { |
|
410 |
throw new Exception("Expected output not found"); |
|
411 |
} |
|
412 |
} |
|
413 |
||
414 |
@Test |
|
37758 | 415 |
public void testServiceDefinitionInnerClass(Path base) throws Exception { |
36526 | 416 |
Path src = base.resolve("src"); |
417 |
tb.writeJavaFiles(src, |
|
418 |
"module m { provides p1.C1.InnerDefinition with p2.C2; }", |
|
419 |
"package p1; public class C1 { public class InnerDefinition { } }", |
|
41942
260c724e5614
8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents:
40308
diff
changeset
|
420 |
"package p2; public class C2 extends p1.C1.InnerDefinition { public C2() { new p1.C1().super(); } }"); |
36526 | 421 |
|
41942
260c724e5614
8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents:
40308
diff
changeset
|
422 |
new JavacTask(tb) |
36526 | 423 |
.options("-XDrawDiagnostics") |
424 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
425 |
.files(findJavaFiles(src)) |
|
41942
260c724e5614
8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents:
40308
diff
changeset
|
426 |
.run(Expect.SUCCESS) |
260c724e5614
8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents:
40308
diff
changeset
|
427 |
.writeAll(); |
36526 | 428 |
} |
429 |
} |