langtools/test/tools/javac/modules/ModuleInfoTest.java
author jjg
Thu, 31 Mar 2016 15:20:50 -0700
changeset 36778 e04318f39f92
parent 36526 3b41f1c69604
child 37758 3ecf9b414e05
permissions -rw-r--r--
8152897: refactor ToolBox to allow reduced documented dependencies Reviewed-by: vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    26
 * @summary tests for module declarations
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @library /tools/lib
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @modules
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 *      jdk.compiler/com.sun.tools.javac.api
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 *      jdk.compiler/com.sun.tools.javac.main
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *      jdk.jdeps/com.sun.tools.javap
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    32
 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 * @run main ModuleInfoTest
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    39
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    40
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    41
import toolbox.ToolBox;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    42
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
public class ModuleInfoTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
        ModuleInfoTest t = new ModuleInfoTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
     * Check error message if module declaration not in module-info.java.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    void testModuleDeclNotInModuleJava(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        tb.writeFile(src.resolve("M.java"), "module M { }");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    57
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    60
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    62
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
        if (!log.contains("M.java:1:1: compiler.err.module.decl.sb.in.module-info.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
     * Verify that a package private class can be put in module-info.java.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
    void testNotModuleDeclInModuleJava_1(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        tb.writeFile(src.resolve("module-info.java"), "class C { }");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    75
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
     * Verify that a public class cannot be put in module-info.java.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
    void testNotModuleDeclInModuleJava_2(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        tb.writeFile(src.resolve("module-info.java"), "public class C { }");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    89
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    92
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    94
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        if (!log.contains("module-info.java:1:8: compiler.err.class.public.should.be.in.file: C"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
     * Verify that only one module decl can be put in module-info.java.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
    void testSingleModuleDecl(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        tb.writeJavaFiles(src, "module M1 { } /*...*/ module M2 { }");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   107
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   110
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   112
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        if (!log.contains("module-info.java:1:14: compiler.err.expected: token.end-of-input"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
     * Verify that missing requires are reported.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
    void testRequiresNotFound(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        tb.writeJavaFiles(src, "module M1 { requires M2; }");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   125
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   128
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   130
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        if (!log.contains("module-info.java:1:22: compiler.err.module.not.found: M2"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
     * Verify that missing exports are reported.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
    void testExportsNotFound(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        tb.writeJavaFiles(src, "module M1 { exports p to M2; }");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   143
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   146
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   148
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        if (!log.contains("module-info.java:1:26: compiler.err.module.not.found: M2"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
     * Verify that a simple loop is detected.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
    void testRequiresSelf(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        tb.writeJavaFiles(src, "module M { requires M; }");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   161
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   164
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   166
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        if (!log.contains("module-info.java:1:21: compiler.err.cyclic.requires: M"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
     * Verify that a multi-module loop is detected.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
    void testRequiresLoop(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        Path src_m1 = src.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        tb.writeFile(src_m1.resolve("module-info.java"), "module m1 { requires m2; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        Path src_m2 = src.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        tb.writeFile(src_m2.resolve("module-info.java"), "module m2 { requires m3; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        Path src_m3 = src.resolve("m3");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        tb.writeFile(src_m3.resolve("module-info.java"), "module m3 { requires m1; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   188
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                .options("-XDrawDiagnostics", "-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   194
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        if (!log.contains("module-info.java:1:22: compiler.err.cyclic.requires: m3"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
     * Verify that a multi-module loop is detected.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
    void testRequiresPublicLoop(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        Path src_m1 = src.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        tb.writeFile(src_m1.resolve("module-info.java"), "module m1 { requires m2; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        Path src_m2 = src.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        tb.writeFile(src_m2.resolve("module-info.java"), "module m2 { requires public m3; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        Path src_m3 = src.resolve("m3");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        tb.writeFile(src_m3.resolve("module-info.java"), "module m3 { requires m1; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   216
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
                .options("-XDrawDiagnostics", "-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   220
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   222
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        if (!log.contains("module-info.java:1:29: compiler.err.cyclic.requires: m3"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
     * Verify that duplicate requires are detected.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
    void testDuplicateRequires(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
        Path src_m1 = src.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
        tb.writeFile(src_m1.resolve("module-info.java"), "module m1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
        Path src_m2 = src.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
        tb.writeFile(src_m2.resolve("module-info.java"), "module m2 { requires m1; requires m1; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   242
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                .options("-XDrawDiagnostics", "-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   246
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   248
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
        if (!log.contains("module-info.java:1:35: compiler.err.duplicate.requires: m1"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
     * Verify that duplicate exported packages are detected.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
    void testDuplicateExports_packages(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
        tb.writeJavaFiles(src, "module m1 { exports p; exports p; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   265
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   269
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   271
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
        if (!log.contains("module-info.java:1:32: compiler.err.duplicate.exports: p"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
     * Verify that duplicate exported packages are detected.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
    void testDuplicateExports_packages2(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
        tb.writeJavaFiles(src.resolve("m1"), "module m1 { exports p; exports p to m2; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        tb.writeJavaFiles(src.resolve("m2"), "module m2 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   289
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
                .options("-XDrawDiagnostics", "-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   293
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   295
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
        if (!log.contains("module-info.java:1:32: compiler.err.duplicate.exports: p"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
     * Verify that duplicate exported packages are detected.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   303
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
    void testDuplicateExports_modules(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
        Path src_m1 = src.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
        tb.writeFile(src_m1.resolve("module-info.java"), "module m1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
        Path src_m2 = src.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
        tb.writeFile(src_m2.resolve("module-info.java"), "module m2 { exports p to m1, m1; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   315
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
                .options("-XDrawDiagnostics", "-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   319
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   321
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   323
        if (!log.contains("module-info.java:1:30: compiler.err.duplicate.exports: m1"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
}