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 8144342 8149658
|
|
26 |
* @summary javac doesn't report errors if module exports non-existent package
|
|
27 |
* @library /tools/lib
|
|
28 |
* @modules
|
|
29 |
* jdk.compiler/com.sun.tools.javac.api
|
|
30 |
* jdk.compiler/com.sun.tools.javac.main
|
|
31 |
* jdk.jdeps/com.sun.tools.javap
|
|
32 |
* @build ToolBox ModuleTestBase
|
|
33 |
* @run main ReportNonExistentPackageTest
|
|
34 |
*/
|
|
35 |
|
|
36 |
import java.nio.file.Files;
|
|
37 |
import java.nio.file.Path;
|
|
38 |
|
|
39 |
public class ReportNonExistentPackageTest extends ModuleTestBase {
|
|
40 |
public static void main(String... args) throws Exception {
|
|
41 |
ReportNonExistentPackageTest t = new ReportNonExistentPackageTest();
|
|
42 |
t.runTests();
|
|
43 |
}
|
|
44 |
|
|
45 |
@Test
|
|
46 |
void testExportUnknownPackage(Path base) throws Exception {
|
|
47 |
Path src = base.resolve("src");
|
|
48 |
tb.writeJavaFiles(src, "module m { exports p1; }");
|
|
49 |
Path classes = base.resolve("classes");
|
|
50 |
Files.createDirectories(classes);
|
|
51 |
|
|
52 |
String log = tb.new JavacTask()
|
|
53 |
.options("-XDrawDiagnostics")
|
|
54 |
.outdir(classes)
|
|
55 |
.files(findJavaFiles(src))
|
|
56 |
.run(ToolBox.Expect.FAIL)
|
|
57 |
.writeAll()
|
|
58 |
.getOutput(ToolBox.OutputKind.DIRECT);
|
|
59 |
if (!log.contains("module-info.java:1:20: compiler.err.package.empty.or.not.found: p1"))
|
|
60 |
throw new Exception("expected output not found");
|
|
61 |
}
|
|
62 |
|
|
63 |
@Test
|
|
64 |
void testExportEmptyPackage(Path base) throws Exception {
|
|
65 |
Path src = base.resolve("src");
|
|
66 |
tb.writeJavaFiles(src,
|
|
67 |
"module m { exports p1; }",
|
|
68 |
"package p1;");
|
|
69 |
Path classes = base.resolve("classes");
|
|
70 |
Files.createDirectories(classes);
|
|
71 |
|
|
72 |
String log = tb.new JavacTask()
|
|
73 |
.options("-XDrawDiagnostics")
|
|
74 |
.outdir(classes)
|
|
75 |
.files(findJavaFiles(src))
|
|
76 |
.run(ToolBox.Expect.FAIL)
|
|
77 |
.writeAll()
|
|
78 |
.getOutput(ToolBox.OutputKind.DIRECT);
|
|
79 |
if (!log.contains("module-info.java:1:20: compiler.err.package.empty.or.not.found: p1"))
|
|
80 |
throw new Exception("expected output not found");
|
|
81 |
}
|
|
82 |
|
|
83 |
@Test
|
|
84 |
void testPackageWithMemberWOPackageDeclaration(Path base) throws Exception {
|
|
85 |
Path src = base.resolve("src");
|
|
86 |
tb.writeJavaFiles(src, "module m { exports p1; }");
|
|
87 |
Path p1 = src.resolve("p1");
|
|
88 |
Path C = p1.resolve("C.java");
|
|
89 |
tb.writeFile(C, "// comment");
|
|
90 |
Path classes = base.resolve("classes");
|
|
91 |
Files.createDirectories(classes);
|
|
92 |
|
|
93 |
String log = tb.new JavacTask()
|
|
94 |
.options("-XDrawDiagnostics")
|
|
95 |
.outdir(classes)
|
|
96 |
.files(findJavaFiles(src))
|
|
97 |
.run(ToolBox.Expect.FAIL)
|
|
98 |
.writeAll()
|
|
99 |
.getOutput(ToolBox.OutputKind.DIRECT);
|
|
100 |
if (!log.contains("module-info.java:1:20: compiler.err.package.empty.or.not.found: p1"))
|
|
101 |
throw new Exception("expected output not found");
|
|
102 |
}
|
|
103 |
}
|