author | alanb |
Thu, 01 Dec 2016 09:02:42 +0000 | |
changeset 42407 | f3702cff2933 |
parent 41938 | 8e66bf10fcec |
child 42822 | a84956e7ee4d |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
36526 | 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 |
|
41516
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
26 |
* @bug 8154283 8167320 |
36526 | 27 |
* @summary tests for multi-module mode compilation |
28 |
* @library /tools/lib |
|
29 |
* @modules |
|
30 |
* jdk.compiler/com.sun.tools.javac.api |
|
31 |
* jdk.compiler/com.sun.tools.javac.code |
|
32 |
* jdk.compiler/com.sun.tools.javac.main |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
33 |
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask ModuleTestBase |
36526 | 34 |
* @run main EdgeCases |
35 |
*/ |
|
36 |
||
37 |
import java.io.Writer; |
|
38 |
import java.nio.file.Files; |
|
39 |
import java.nio.file.Path; |
|
40 |
import java.nio.file.Paths; |
|
41 |
import java.util.Arrays; |
|
42 |
import java.util.HashSet; |
|
43 |
import java.util.List; |
|
44 |
import java.util.Objects; |
|
45 |
import java.util.Set; |
|
46 |
||
47 |
import javax.lang.model.element.Element; |
|
48 |
import javax.tools.JavaCompiler; |
|
49 |
import javax.tools.JavaFileObject; |
|
50 |
import javax.tools.StandardJavaFileManager; |
|
51 |
import javax.tools.ToolProvider; |
|
52 |
||
53 |
import com.sun.source.tree.CompilationUnitTree; |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
54 |
//import com.sun.source.util.JavacTask; // conflicts with toolbox.JavacTask |
36526 | 55 |
import com.sun.tools.javac.api.JavacTaskImpl; |
56 |
import com.sun.tools.javac.code.Symbol.ModuleSymbol; |
|
41516
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
57 |
import com.sun.tools.javac.code.Symtab; |
36526 | 58 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
59 |
import toolbox.JarTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
60 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
61 |
import toolbox.Task; |
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
62 |
import toolbox.Task.Expect; |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
63 |
import toolbox.Task.OutputKind; |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
64 |
|
36526 | 65 |
public class EdgeCases extends ModuleTestBase { |
66 |
||
67 |
public static void main(String... args) throws Exception { |
|
68 |
new EdgeCases().runTests(); |
|
69 |
} |
|
70 |
||
71 |
@Test |
|
37758 | 72 |
public void testAddExportUndefinedModule(Path base) throws Exception { |
36526 | 73 |
Path src = base.resolve("src"); |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
74 |
tb.writeJavaFiles(src, "package test; import undefPackage.Any; public class Test {}"); |
36526 | 75 |
Path classes = base.resolve("classes"); |
76 |
tb.createDirectories(classes); |
|
77 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
78 |
List<String> log = new JavacTask(tb) |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
79 |
.options("--add-exports", "undefModule/undefPackage=ALL-UNNAMED", |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
80 |
"-XDrawDiagnostics") |
36526 | 81 |
.outdir(classes) |
82 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
83 |
.run(Task.Expect.FAIL) |
36526 | 84 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
85 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 86 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
87 |
List<String> expected = Arrays.asList("- compiler.warn.module.for.option.not.found: --add-exports, undefModule", |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
88 |
"Test.java:1:34: compiler.err.doesnt.exist: undefPackage", |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
89 |
"1 error", "1 warning"); |
36526 | 90 |
|
91 |
if (!expected.equals(log)) |
|
92 |
throw new Exception("expected output not found: " + log); |
|
93 |
} |
|
94 |
||
95 |
@Test |
|
37758 | 96 |
public void testModuleSymbolOutterMostClass(Path base) throws Exception { |
36526 | 97 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
98 |
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) { |
|
99 |
Path moduleSrc = base.resolve("module-src"); |
|
100 |
Path m1 = moduleSrc.resolve("m1"); |
|
101 |
||
102 |
tb.writeJavaFiles(m1, "module m1 { }"); |
|
103 |
||
104 |
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(moduleSrc)); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
105 |
com.sun.source.util.JavacTask task = |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
106 |
(com.sun.source.util.JavacTask) compiler.getTask(null, fm, null, null, null, files); |
36526 | 107 |
|
108 |
task.analyze(); |
|
109 |
||
110 |
ModuleSymbol msym = (ModuleSymbol) task.getElements().getModuleElement("m1"); |
|
111 |
||
112 |
msym.outermostClass(); |
|
113 |
} |
|
114 |
} |
|
115 |
||
116 |
@Test |
|
37758 | 117 |
public void testParseEnterAnalyze(Path base) throws Exception { |
36526 | 118 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
119 |
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) { |
|
120 |
Path moduleSrc = base.resolve("module-src"); |
|
121 |
Path m1 = moduleSrc.resolve("m1"); |
|
122 |
||
123 |
tb.writeJavaFiles(m1, "module m1 { }", |
|
124 |
"package p;", |
|
125 |
"package p; class T { }"); |
|
126 |
||
127 |
Path classes = base.resolve("classes"); |
|
128 |
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(moduleSrc)); |
|
129 |
List<String> options = Arrays.asList("-d", classes.toString(), "-Xpkginfo:always"); |
|
130 |
JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, fm, null, options, null, files); |
|
131 |
||
132 |
Iterable<? extends CompilationUnitTree> parsed = task.parse(); |
|
133 |
Iterable<? extends Element> entered = task.enter(parsed); |
|
134 |
Iterable<? extends Element> analyzed = task.analyze(entered); |
|
135 |
Iterable<? extends JavaFileObject> generatedFiles = task.generate(analyzed); |
|
136 |
||
137 |
Set<String> generated = new HashSet<>(); |
|
138 |
||
139 |
for (JavaFileObject jfo : generatedFiles) { |
|
140 |
generated.add(jfo.getName()); |
|
141 |
} |
|
142 |
||
143 |
Set<String> expected = new HashSet<>( |
|
144 |
Arrays.asList(Paths.get("testParseEnterAnalyze", "classes", "p", "package-info.class").toString(), |
|
145 |
Paths.get("testParseEnterAnalyze", "classes", "module-info.class").toString(), |
|
146 |
Paths.get("testParseEnterAnalyze", "classes", "p", "T.class").toString()) |
|
147 |
); |
|
148 |
||
149 |
if (!Objects.equals(expected, generated)) |
|
150 |
throw new AssertionError("Incorrect generated files: " + generated); |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
@Test |
|
37758 | 155 |
public void testModuleImplicitModuleBoundaries(Path base) throws Exception { |
36526 | 156 |
Path src = base.resolve("src"); |
157 |
Path src_m1 = src.resolve("m1"); |
|
158 |
tb.writeJavaFiles(src_m1, |
|
159 |
"module m1 { exports api1; }", |
|
160 |
"package api1; public class Api1 { public void call() { } }"); |
|
161 |
Path src_m2 = src.resolve("m2"); |
|
162 |
tb.writeJavaFiles(src_m2, |
|
163 |
"module m2 { requires m1; exports api2; }", |
|
164 |
"package api2; public class Api2 { public static api1.Api1 get() { return null; } }"); |
|
165 |
Path src_m3 = src.resolve("m3"); |
|
166 |
tb.writeJavaFiles(src_m3, |
|
167 |
"module m3 { requires m2; }", |
|
168 |
"package test; public class Test { { api2.Api2.get().call(); api2.Api2.get().toString(); } }"); |
|
169 |
Path classes = base.resolve("classes"); |
|
170 |
tb.createDirectories(classes); |
|
171 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
172 |
String log = new JavacTask(tb) |
36526 | 173 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
174 |
"--module-source-path", src.toString()) |
36526 | 175 |
.outdir(classes) |
176 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
177 |
.run(Task.Expect.FAIL) |
36526 | 178 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
179 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 180 |
|
41932 | 181 |
if (!log.contains("Test.java:1:52: compiler.err.not.def.access.class.intf.cant.access: call(), api1.Api1") || |
36526 | 182 |
!log.contains("Test.java:1:76: compiler.err.not.def.access.class.intf.cant.access: toString(), java.lang.Object")) |
183 |
throw new Exception("expected output not found"); |
|
184 |
} |
|
185 |
||
186 |
@Test |
|
37758 | 187 |
public void testAssignClassToAutomaticModule(Path base) throws Exception { |
36526 | 188 |
//check that if a ClassSymbol belongs to an automatic module, it is properly assigned and not |
189 |
//duplicated when being accessed through a classfile. |
|
190 |
Path automaticSrc = base.resolve("automaticSrc"); |
|
191 |
tb.writeJavaFiles(automaticSrc, "package api1; public class Api1 {}"); |
|
192 |
Path automaticClasses = base.resolve("automaticClasses"); |
|
193 |
tb.createDirectories(automaticClasses); |
|
194 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
195 |
String automaticLog = new JavacTask(tb) |
36526 | 196 |
.outdir(automaticClasses) |
197 |
.files(findJavaFiles(automaticSrc)) |
|
198 |
.run() |
|
199 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
200 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 201 |
|
202 |
if (!automaticLog.isEmpty()) |
|
203 |
throw new Exception("expected output not found: " + automaticLog); |
|
204 |
||
205 |
Path modulePath = base.resolve("module-path"); |
|
206 |
||
207 |
Files.createDirectories(modulePath); |
|
208 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
209 |
Path automaticJar = modulePath.resolve("a-1.0.jar"); |
36526 | 210 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
211 |
new JarTask(tb, automaticJar) |
36526 | 212 |
.baseDir(automaticClasses) |
213 |
.files("api1/Api1.class") |
|
214 |
.run(); |
|
215 |
||
216 |
Path src = base.resolve("src"); |
|
217 |
Path src_m2 = src.resolve("m2"); |
|
218 |
tb.writeJavaFiles(src_m2, |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
219 |
"module m2 { requires a; exports api2; }", |
36526 | 220 |
"package api2; public class Api2 { public static api1.Api1 get() { return null; } }"); |
221 |
Path src_m3 = src.resolve("m3"); |
|
222 |
tb.writeJavaFiles(src_m3, |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
223 |
"module m3 { requires a; requires m2; }", |
36526 | 224 |
"package test; public class Test { { api2.Api2.get(); api1.Api1 a1; } }"); |
225 |
Path classes = base.resolve("classes"); |
|
226 |
tb.createDirectories(classes); |
|
227 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
228 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
229 |
.options("--module-path", modulePath.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
230 |
"--module-source-path", src.toString()) |
36526 | 231 |
.outdir(classes) |
232 |
.files(findJavaFiles(src_m2)) |
|
233 |
.run() |
|
234 |
.writeAll(); |
|
235 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
236 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
237 |
.options("--module-path", modulePath.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
238 |
"--module-source-path", src.toString()) |
36526 | 239 |
.outdir(classes) |
240 |
.files(findJavaFiles(src_m3)) |
|
241 |
.run() |
|
242 |
.writeAll(); |
|
243 |
} |
|
244 |
||
245 |
@Test |
|
37758 | 246 |
public void testEmptyImplicitModuleInfo(Path base) throws Exception { |
36526 | 247 |
Path src = base.resolve("src"); |
248 |
Path src_m1 = src.resolve("m1"); |
|
249 |
Files.createDirectories(src_m1); |
|
250 |
try (Writer w = Files.newBufferedWriter(src_m1.resolve("module-info.java"))) {} |
|
251 |
tb.writeJavaFiles(src_m1, |
|
252 |
"package test; public class Test {}"); |
|
253 |
Path classes = base.resolve("classes"); |
|
254 |
tb.createDirectories(classes); |
|
255 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
256 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
257 |
.options("--source-path", src_m1.toString(), |
36526 | 258 |
"-XDrawDiagnostics") |
259 |
.outdir(classes) |
|
260 |
.files(findJavaFiles(src_m1.resolve("test"))) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
261 |
.run(Task.Expect.FAIL) |
36526 | 262 |
.writeAll(); |
263 |
||
264 |
tb.writeJavaFiles(src_m1, |
|
265 |
"module m1 {}"); |
|
266 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
267 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
268 |
.options("--source-path", src_m1.toString()) |
36526 | 269 |
.outdir(classes) |
270 |
.files(findJavaFiles(src_m1.resolve("test"))) |
|
271 |
.run() |
|
272 |
.writeAll(); |
|
273 |
||
274 |
} |
|
275 |
||
37744
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
276 |
@Test |
37758 | 277 |
public void testClassPackageClash(Path base) throws Exception { |
37744
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
278 |
Path src = base.resolve("src"); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
279 |
Path src_m1 = src.resolve("m1"); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
280 |
tb.writeJavaFiles(src_m1, |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
281 |
"module m1 { exports test.m1; }", |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
282 |
"package test.m1;\n" + |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
283 |
"public class Test {}\n"); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
284 |
Path src_m2 = src.resolve("m2"); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
285 |
tb.writeJavaFiles(src_m2, |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
286 |
"module m2 { requires m1; }", |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
287 |
"package test;\n" + |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
288 |
"public class m1 {}\n"); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
289 |
Path classes = base.resolve("classes"); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
290 |
tb.createDirectories(classes); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
291 |
|
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
292 |
List<String> log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
293 |
.options("--module-source-path", src.toString(), |
37744
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
294 |
"-XDrawDiagnostics") |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
295 |
.outdir(classes) |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
296 |
.files(findJavaFiles(src)) |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
297 |
.run(Task.Expect.FAIL) |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
298 |
.writeAll() |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
299 |
.getOutputLines(Task.OutputKind.DIRECT); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
300 |
|
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
301 |
List<String> expected = Arrays.asList( |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
302 |
"m1.java:2:8: compiler.err.clash.with.pkg.of.same.name: kindname.class, test.m1", |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
303 |
"1 error" |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
304 |
); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
305 |
|
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
306 |
if (!expected.equals(log)) { |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
307 |
throw new IllegalStateException(log.toString()); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
308 |
} |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
309 |
} |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
310 |
|
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
311 |
@Test |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
312 |
public void testImplicitJavaBase(Path base) throws Exception { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
313 |
Path src = base.resolve("src"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
314 |
Path src_java_base = src.resolve("java.base"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
315 |
Files.createDirectories(src_java_base); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
316 |
tb.writeJavaFiles(src_java_base, "module java.base { exports java.lang; }"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
317 |
tb.writeJavaFiles(src_java_base, |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
318 |
"package java.lang; public class Object {}"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
319 |
Path classes = base.resolve("classes"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
320 |
tb.createDirectories(classes); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
321 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
322 |
//module-info from source: |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
323 |
new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
324 |
.options("-sourcepath", src_java_base.toString()) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
325 |
.outdir(classes) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
326 |
.files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java"))) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
327 |
.run() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
328 |
.writeAll(); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
329 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
330 |
//module-info from class: |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
331 |
if (!Files.exists(classes.resolve("module-info.class"))) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
332 |
throw new AssertionError("module-info.class not created!"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
333 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
334 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
335 |
new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
336 |
.outdir(classes) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
337 |
.files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java"))) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
338 |
.run() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
339 |
.writeAll(); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
340 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
341 |
//broken module-info.class: |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
342 |
Files.newOutputStream(classes.resolve("module-info.class")).close(); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
343 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
344 |
List<String> log = new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
345 |
.options("-XDrawDiagnostics") |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
346 |
.outdir(classes) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
347 |
.files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java"))) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
348 |
.run(Expect.FAIL) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
349 |
.writeAll() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
350 |
.getOutputLines(OutputKind.DIRECT); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
351 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
352 |
List<String> expected = Arrays.asList( |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
353 |
"- compiler.err.cant.access: <error>.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.illegal.start.of.class.file))", |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
354 |
"1 error"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
355 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
356 |
if (!expected.equals(log)) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
357 |
throw new AssertionError("Unexpected output: " + log); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
358 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
359 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
360 |
//broken module-info.java: |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
361 |
Files.delete(classes.resolve("module-info.class")); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
362 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
363 |
try (Writer out = Files.newBufferedWriter(src_java_base.resolve("module-info.java"))) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
364 |
out.write("class Broken {}"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
365 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
366 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
367 |
log = new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
368 |
.options("-sourcepath", src_java_base.toString(), |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
369 |
"-XDrawDiagnostics") |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
370 |
.outdir(classes) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
371 |
.files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java"))) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
372 |
.run(Expect.FAIL) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
373 |
.writeAll() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
374 |
.getOutputLines(OutputKind.DIRECT); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
375 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
376 |
expected = Arrays.asList("X"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
377 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
378 |
if (expected.equals(log)) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
379 |
throw new AssertionError("Unexpected output: " + log); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
380 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
381 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
382 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
383 |
@Test |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
384 |
public void testModuleInfoNameMismatchSource(Path base) throws Exception { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
385 |
Path src = base.resolve("src"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
386 |
Path m1 = src.resolve("m1"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
387 |
Files.createDirectories(m1); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
388 |
tb.writeJavaFiles(m1, "module other { }", |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
389 |
"package test; public class Test {}"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
390 |
Path classes = base.resolve("classes"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
391 |
tb.createDirectories(classes); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
392 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
393 |
List<String> log = new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
394 |
.options("--module-source-path", src.toString(), |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
395 |
"-XDrawDiagnostics") |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
396 |
.outdir(classes) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
397 |
.files(findJavaFiles(m1.resolve("test").resolve("Test.java"))) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
398 |
.run(Expect.FAIL) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
399 |
.writeAll() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
400 |
.getOutputLines(OutputKind.DIRECT); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
401 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
402 |
List<String> expected = Arrays.asList( |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
403 |
"module-info.java:1:1: compiler.err.module.name.mismatch: other, m1", |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
404 |
"- compiler.err.cant.access: m1.module-info, (compiler.misc.cant.resolve.modules)", |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
405 |
"2 errors"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
406 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
407 |
if (!expected.equals(log)) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
408 |
throw new AssertionError("Unexpected output: " + log); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
409 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
410 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
411 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
412 |
@Test |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
413 |
public void testModuleInfoNameMismatchClass(Path base) throws Exception { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
414 |
Path src = base.resolve("src"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
415 |
Files.createDirectories(src); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
416 |
tb.writeJavaFiles(src, "module other { }", |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
417 |
"package test; public class Test {}"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
418 |
Path classes = base.resolve("classes"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
419 |
Path m1Classes = classes.resolve("m1"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
420 |
tb.createDirectories(m1Classes); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
421 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
422 |
new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
423 |
.outdir(m1Classes) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
424 |
.files(findJavaFiles(src)) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
425 |
.run() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
426 |
.writeAll() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
427 |
.getOutputLines(OutputKind.DIRECT); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
428 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
429 |
Path src2 = base.resolve("src2"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
430 |
Files.createDirectories(src2); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
431 |
tb.writeJavaFiles(src2, "module use { requires m1; }"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
432 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
433 |
Path classes2 = base.resolve("classes2"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
434 |
tb.createDirectories(classes2); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
435 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
436 |
List<String> log = new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
437 |
.options("--module-path", classes.toString(), |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
438 |
"-XDrawDiagnostics") |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
439 |
.outdir(classes2) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
440 |
.files(findJavaFiles(src2)) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
441 |
.run(Expect.FAIL) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
442 |
.writeAll() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
443 |
.getOutputLines(OutputKind.DIRECT); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
444 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
445 |
List<String> expected = Arrays.asList( |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
446 |
"- compiler.err.cant.access: m1.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.module.name.mismatch: other, m1))", |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
447 |
"1 error"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
448 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
449 |
if (!expected.equals(log)) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
450 |
throw new AssertionError("Unexpected output: " + log); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
451 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
452 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
453 |
|
41516
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
454 |
@Test |
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
455 |
public void testGetDirectivesComplete(Path base) throws Exception { |
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
456 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
457 |
JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, null, null, null, null, null); |
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
458 |
Symtab syms = Symtab.instance(task.getContext()); |
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
459 |
|
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
460 |
syms.java_base.getDirectives(); |
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
461 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
462 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
463 |
@Test |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
464 |
public void testPackageInModuleInfo(Path base) throws Exception { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
465 |
Path src = base.resolve("src"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
466 |
Files.createDirectories(src); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
467 |
tb.writeJavaFiles(src, "package p; module foo { }"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
468 |
Path classes = base.resolve("classes"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
469 |
tb.createDirectories(classes); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
470 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
471 |
List<String> log = new JavacTask(tb) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
472 |
.options("-XDrawDiagnostics", "-XDshould-stop.ifError=FLOW") |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
473 |
.outdir(classes) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
474 |
.files(findJavaFiles(src)) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
475 |
.run(Expect.FAIL) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
476 |
.writeAll() |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
477 |
.getOutputLines(OutputKind.DIRECT); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
478 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
479 |
List<String> expected = Arrays.asList( |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
480 |
"module-info.java:1:1: compiler.err.no.pkg.in.module-info.java", |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
481 |
"1 error"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
482 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
483 |
if (!expected.equals(log)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
484 |
throw new AssertionError("Unexpected output: " + log); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
485 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
486 |
} |
36526 | 487 |
} |