author | ihse |
Tue, 09 May 2017 12:55:07 +0200 | |
changeset 45045 | 834233132ab1 |
parent 44568 | 3d870d326626 |
permissions | -rw-r--r-- |
42822 | 1 |
/* |
45045
834233132ab1
8179889: Fix typographic errors in copyright headers
ihse
parents:
44568
diff
changeset
|
2 |
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
42822 | 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 |
|
44568
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
26 |
* @bug 8160181 8176572 |
42822 | 27 |
* @summary Add lint warning for digits in module names |
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 |
|
33 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
|
34 |
* @run main PoorChoiceForModuleNameTest |
|
35 |
*/ |
|
36 |
||
37 |
||
38 |
import java.nio.file.Path; |
|
39 |
||
40 |
import toolbox.JavacTask; |
|
41 |
import toolbox.Task; |
|
42 |
||
43 |
public class PoorChoiceForModuleNameTest extends ModuleTestBase { |
|
44 |
||
45 |
public static void main(String... args) throws Exception { |
|
46 |
new PoorChoiceForModuleNameTest().runTests(); |
|
47 |
} |
|
48 |
||
49 |
@Test |
|
50 |
public void testDigitsInModuleNames(Path base) throws Exception { |
|
51 |
||
52 |
Path src = base.resolve("src"); |
|
53 |
||
54 |
// Nitpickable module name |
|
55 |
Path src_m1 = src.resolve("mango19"); |
|
56 |
tb.writeJavaFiles(src_m1, "module mango19 { }"); |
|
57 |
||
58 |
// Acceptable module name. |
|
59 |
Path src_m2 = src.resolve("mango20kg"); |
|
60 |
tb.writeJavaFiles(src_m2, "module mango20kg { }"); |
|
61 |
||
62 |
// Nitpickable, but should not due to annotation. |
|
63 |
Path src_m3 = src.resolve("mango100"); |
|
64 |
tb.writeJavaFiles(src_m3, "@SuppressWarnings(\"module\") module mango100 { }"); |
|
65 |
||
44568
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
66 |
// Check that there is no warning at use site. |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
67 |
Path src_m4 = src.resolve("mangouser"); |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
68 |
tb.writeJavaFiles(src_m4, "module mangouser { requires mango19; }"); |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
69 |
|
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
70 |
// Check that we warn about component names ending in digit also |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
71 |
Path src_m5 = src.resolve("mango1000.mangofruit.mangomodule"); |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
72 |
tb.writeJavaFiles(src_m5, "module mango1000.mangofruit.mangomodule { }"); |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
73 |
|
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
74 |
// Check that we warn about component names ending in digit also |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
75 |
Path src_m6 = src.resolve("mangofruit.mango1000.mangomodule"); |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
76 |
tb.writeJavaFiles(src_m6, "module mangofruit.mango1000.mangomodule { }"); |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
77 |
|
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
78 |
// Check that we warn about component names ending in digit also |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
79 |
Path src_m7 = src.resolve("mangomodule.mangofruit.mango1000"); |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
80 |
tb.writeJavaFiles(src_m7, "module mangomodule.mangofruit.mango1000 { }"); |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
81 |
|
42822 | 82 |
Path classes = base.resolve("classes"); |
83 |
tb.createDirectories(classes); |
|
84 |
||
85 |
String log = new JavacTask(tb) |
|
86 |
.options("-XDrawDiagnostics", |
|
87 |
"-Xlint:module", |
|
88 |
"-Werror", |
|
89 |
"--module-source-path", src.toString()) |
|
90 |
.outdir(classes) |
|
91 |
.files(findJavaFiles(src)) |
|
92 |
.run(Task.Expect.FAIL) |
|
93 |
.writeAll() |
|
94 |
.getOutput(Task.OutputKind.DIRECT); |
|
95 |
||
96 |
if (!log.contains("module-info.java:1:8: compiler.warn.poor.choice.for.module.name: mango19") || |
|
44568
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
97 |
!log.contains("module-info.java:1:8: compiler.warn.poor.choice.for.module.name: mango1000") || |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
98 |
!log.contains("module-info.java:1:18: compiler.warn.poor.choice.for.module.name: mango1000") || |
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
99 |
!log.contains("module-info.java:1:30: compiler.warn.poor.choice.for.module.name: mango1000") || |
42822 | 100 |
!log.contains("- compiler.err.warnings.and.werror") || |
101 |
!log.contains("1 error") || |
|
44568
3d870d326626
8176572: Javac does not enforce module name restrictions
sadayapalam
parents:
42822
diff
changeset
|
102 |
!log.contains("4 warning")) |
42822 | 103 |
throw new Exception("expected output not found: " + log); |
104 |
} |
|
105 |
} |