langtools/test/tools/javac/modules/ModuleInfoTest.java
author vromero
Wed, 08 Feb 2017 06:43:34 -0800
changeset 43756 118221d3960d
parent 42822 a84956e7ee4d
child 43864 fc233ac29255
permissions -rw-r--r--
8174027: error message should adapt to the corresponding top level element Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
43756
118221d3960d 8174027: error message should adapt to the corresponding top level element
vromero
parents: 42822
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
36526
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
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
    26
 * @bug 8158123 8161906 8162713
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    27
 * @summary tests for module declarations
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @library /tools/lib
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @modules
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 *      jdk.compiler/com.sun.tools.javac.api
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *      jdk.compiler/com.sun.tools.javac.main
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 *      jdk.jdeps/com.sun.tools.javap
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    33
 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 * @run main ModuleInfoTest
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.nio.file.Path;
38916
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
    39
import java.util.Arrays;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    41
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    42
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    43
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
public class ModuleInfoTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        ModuleInfoTest t = new ModuleInfoTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
        t.runTests();
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
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
     * Check error message if module declaration not in module-info.java.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    55
    public void testModuleDeclNotInModuleJava(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        tb.writeFile(src.resolve("M.java"), "module M { }");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    58
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    61
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    63
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
        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
    66
            throw new Exception("expected output not found");
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
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
     * Verify that a package private class can be put in module-info.java.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    73
    public void testNotModuleDeclInModuleJava_1(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        tb.writeFile(src.resolve("module-info.java"), "class C { }");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    76
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
                .writeAll();
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
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
     * Verify that a public class cannot be put in module-info.java.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    87
    public void testNotModuleDeclInModuleJava_2(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        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
    90
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    93
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    95
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
43756
118221d3960d 8174027: error message should adapt to the corresponding top level element
vromero
parents: 42822
diff changeset
    97
        if (!log.contains("module-info.java:1:8: compiler.err.class.public.should.be.in.file: kindname.class, C"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
            throw new Exception("expected output not found");
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
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
     * Verify that only one module decl can be put in module-info.java.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   105
    public void testSingleModuleDecl(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        tb.writeJavaFiles(src, "module M1 { } /*...*/ module M2 { }");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   108
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   111
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   113
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
        if (!log.contains("module-info.java:1:14: compiler.err.expected: token.end-of-input"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
            throw new Exception("expected output not found");
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
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
     * Verify that missing requires are reported.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   123
    public void testRequiresNotFound(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        tb.writeJavaFiles(src, "module M1 { requires M2; }");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   126
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   129
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   131
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        if (!log.contains("module-info.java:1:22: compiler.err.module.not.found: M2"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
            throw new Exception("expected output not found");
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
    /**
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   138
     * Verify that missing exports targets are reported.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   141
    public void testExportsNotFound(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   143
        tb.writeJavaFiles(src,
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   144
                          "module M { exports p to N; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   145
                          "package p; public class C {}");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   146
        String log = new JavacTask(tb)
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   147
                .options("-XDrawDiagnostics",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   148
                         "-Xlint:module")
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   149
                .files(findJavaFiles(src))
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   150
                .run()
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   151
                .writeAll()
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   152
                .getOutput(Task.OutputKind.DIRECT);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   153
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   154
        if (!log.contains("module-info.java:1:25: compiler.warn.module.not.found: N"))
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   155
            throw new Exception("expected output not found, actual output: " + log);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   156
    }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   157
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   158
    /**
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   159
     * Verify that duplicated qualified missing exports targets are reported.
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   160
     */
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   161
    @Test
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   162
    public void testExportsNotFoundDuplicated(Path base) throws Exception {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   163
        Path src = base.resolve("src");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   164
        tb.writeJavaFiles(src,
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   165
                          "module M { exports p to N, N; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   166
                          "package p; public class C {}");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   167
        String log = new JavacTask(tb)
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   168
                .options("-XDrawDiagnostics",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   169
                         "-Xlint:module")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   171
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   173
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   175
        if (!log.contains("module-info.java:1:28: compiler.err.conflicting.exports.to.module: N"))
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   176
            throw new Exception("expected output not found, actual output: " + log);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   177
    }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   178
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   179
    /**
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   180
     * Verify that missing exports target warning can be suppressed.
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   181
     */
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   182
    @Test
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   183
    public void testExportsNotFoundSuppress(Path base) throws Exception {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   184
        Path src = base.resolve("src");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   185
        tb.writeJavaFiles(src,
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   186
                          "@SuppressWarnings(\"module\") module M { exports p to N; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   187
                          "package p; public class C {}");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   188
        String log = new JavacTask(tb)
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   189
                .options("-XDrawDiagnostics",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   190
                         "-Xlint:module")
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   191
                .files(findJavaFiles(src))
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   192
                .run()
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   193
                .writeAll()
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   194
                .getOutput(Task.OutputKind.DIRECT);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   195
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   196
        if (!log.isEmpty())
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   197
            throw new Exception("expected output not found, actual output: " + log);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   198
    }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   199
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   200
    /**
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   201
     * Verify that missing opens targets are reported.
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   202
     */
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   203
    @Test
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   204
    public void testOpensNotFound(Path base) throws Exception {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   205
        Path src = base.resolve("src");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   206
        tb.writeJavaFiles(src,
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   207
                          "module M { opens p to N; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   208
                          "package p; public class C {}");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   209
        String log = new JavacTask(tb)
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   210
                .options("-XDrawDiagnostics",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   211
                         "-Xlint:module")
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   212
                .files(findJavaFiles(src))
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   213
                .run()
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   214
                .writeAll()
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   215
                .getOutput(Task.OutputKind.DIRECT);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   216
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   217
        if (!log.contains("module-info.java:1:23: compiler.warn.module.not.found: N"))
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   218
            throw new Exception("expected output not found, actual output: " + log);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   219
    }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   220
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   221
    /**
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   222
     * Verify that duplicated qualified missing opens targets are reported.
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   223
     */
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   224
    @Test
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   225
    public void testOpensNotFoundDuplicated(Path base) throws Exception {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   226
        Path src = base.resolve("src");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   227
        tb.writeJavaFiles(src,
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   228
                          "module M { opens p to N, N; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   229
                          "package p; public class C {}");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   230
        String log = new JavacTask(tb)
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   231
                .options("-XDrawDiagnostics",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   232
                         "-Xlint:module")
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   233
                .files(findJavaFiles(src))
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   234
                .run(Task.Expect.FAIL)
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   235
                .writeAll()
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   236
                .getOutput(Task.OutputKind.DIRECT);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   237
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   238
        if (!log.contains("module-info.java:1:26: compiler.err.conflicting.opens.to.module: N"))
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   239
            throw new Exception("expected output not found, actual output: " + log);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   240
    }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   241
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   242
    /**
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   243
     * Verify that missing opens target warning can be suppressed.
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   244
     */
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   245
    @Test
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   246
    public void testOpensNotFoundSuppress(Path base) throws Exception {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   247
        Path src = base.resolve("src");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   248
        tb.writeJavaFiles(src,
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   249
                          "@SuppressWarnings(\"module\") module M { opens p to N; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   250
                          "package p; public class C {}");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   251
        String log = new JavacTask(tb)
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   252
                .options("-XDrawDiagnostics",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   253
                         "-Xlint:module")
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   254
                .files(findJavaFiles(src))
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   255
                .run()
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   256
                .writeAll()
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   257
                .getOutput(Task.OutputKind.DIRECT);
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   258
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   259
        if (!log.isEmpty())
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   260
            throw new Exception("expected output not found, actual output: " + log);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
     * Verify that a simple loop is detected.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   267
    public void testRequiresSelf(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        tb.writeJavaFiles(src, "module M { requires M; }");
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   270
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   273
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   275
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
        if (!log.contains("module-info.java:1:21: compiler.err.cyclic.requires: M"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
     * Verify that a multi-module loop is detected.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   285
    public void testRequiresLoop(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   287
        Path src_m1 = src.resolve("m1x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   288
        tb.writeFile(src_m1.resolve("module-info.java"), "module m1x { requires m2x; }");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   289
        Path src_m2 = src.resolve("m2x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   290
        tb.writeFile(src_m2.resolve("module-info.java"), "module m2x { requires m3x; }");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   291
        Path src_m3 = src.resolve("m3x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   292
        tb.writeFile(src_m3.resolve("module-info.java"), "module m3x { requires m1x; }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   297
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38916
diff changeset
   298
                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   301
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   303
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   305
        if (!log.contains("module-info.java:1:23: compiler.err.cyclic.requires: m3x"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
     * Verify that a multi-module loop is detected.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
    @Test
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   313
    public void testRequiresTransitiveLoop(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   315
        Path src_m1 = src.resolve("m1x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   316
        tb.writeFile(src_m1.resolve("module-info.java"), "module m1x { requires m2x; }");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   317
        Path src_m2 = src.resolve("m2x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   318
        tb.writeFile(src_m2.resolve("module-info.java"), "module m2x { requires transitive m3x; }");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   319
        Path src_m3 = src.resolve("m3x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   320
        tb.writeFile(src_m3.resolve("module-info.java"), "module m3x { requires m1x; }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   323
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   325
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38916
diff changeset
   326
                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   328
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   329
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   331
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   332
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   333
        if (!log.contains("module-info.java:1:34: compiler.err.cyclic.requires: m3x"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   337
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   338
     * Verify that duplicate requires are detected.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   339
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   340
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   341
    public void testDuplicateRequires(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   342
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   343
        Path src_m1 = src.resolve("m1x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   344
        tb.writeFile(src_m1.resolve("module-info.java"), "module m1x { }");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   345
        Path src_m2 = src.resolve("m2x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   346
        tb.writeFile(src_m2.resolve("module-info.java"), "module m2x { requires m1x; requires m1x; }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   347
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   348
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   349
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   350
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   351
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38916
diff changeset
   352
                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   353
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   354
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   355
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   356
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   357
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   358
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   359
        if (!log.contains("module-info.java:1:37: compiler.err.duplicate.requires: m1x"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   360
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   362
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   363
    /**
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   364
     * Verify that duplicate requires are detected.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   365
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   366
    @Test
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   367
    public void testDuplicateRequiresTransitiveStatic(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   368
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   369
        Path src_m1 = src.resolve("m1x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   370
        tb.writeFile(src_m1.resolve("module-info.java"), "module m1x { }");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   371
        Path src_m2 = src.resolve("m2x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   372
        tb.writeFile(src_m2.resolve("module-info.java"), "module m2x { requires transitive m1x; requires static m1x; }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   374
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   375
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   376
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   377
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38916
diff changeset
   378
                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   379
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   380
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   381
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   382
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   383
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   384
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   385
        if (!log.contains("module-info.java:1:55: compiler.err.duplicate.requires: m1x"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   386
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   387
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   388
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   389
    /**
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   390
     * Verify that duplicate exported packages are detected correctly.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   391
     */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   392
    @Test
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   393
    public void testConflictingExports_packages(Path base) throws Exception {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   394
        verifyConflictingExports_packages(base,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   395
                                          "exports p; exports q;",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   396
                                          null);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   397
        verifyConflictingExports_packages(base,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   398
                                          "exports p; exports p;",
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   399
                                          "module-info.java:1:33: compiler.err.conflicting.exports: p");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   400
        verifyConflictingExports_packages(base,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   401
                                          "exports p; opens p;",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   402
                                          null);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   403
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   404
                                          "exports p; exports p to m2x;",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   405
                                          "module-info.java:1:33: compiler.err.conflicting.exports: p");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   406
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   407
                                          "exports p; opens p to m2x;",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   408
                                          null);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   409
        verifyConflictingExports_packages(base,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   410
                                          "opens p; exports p;",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   411
                                          null);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   412
        verifyConflictingExports_packages(base,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   413
                                          "opens p; opens p;",
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   414
                                          "module-info.java:1:29: compiler.err.conflicting.opens: p");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   415
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   416
                                          "opens p; exports p to m2x;",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   417
                                          null);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   418
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   419
                                          "opens p; opens p to m2x;",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   420
                                          "module-info.java:1:29: compiler.err.conflicting.opens: p");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   421
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   422
                                          "exports p to m2x; exports p;",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   423
                                          "module-info.java:1:40: compiler.err.conflicting.exports: p");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   424
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   425
                                          "exports p to m2x; opens p;",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   426
                                          null);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   427
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   428
                                          "exports p to m2x; exports p to m2x;",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   429
                                          "module-info.java:1:45: compiler.err.conflicting.exports.to.module: m2x");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   430
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   431
                                          "exports p to m2x; opens p to m2x;",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   432
                                          null);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   433
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   434
                                          "opens p to m2x; exports p;",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   435
                                          null);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   436
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   437
                                          "opens p to m2x; opens p;",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   438
                                          "module-info.java:1:36: compiler.err.conflicting.opens: p");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   439
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   440
                                          "opens p to m2x; exports p to m2x;",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   441
                                          null);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   442
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   443
                                          "opens p to m2x; opens p to m2x;",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   444
                                          "module-info.java:1:36: compiler.err.conflicting.opens: p");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   445
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   446
                                          "exports p to m2x; exports p to m3x;",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   447
                                          "module-info.java:1:40: compiler.err.conflicting.exports: p");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   448
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   449
                                          "exports p to m2x; opens p to m3x;",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   450
                                          null);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   451
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   452
                                          "opens p to m2x; exports p to m3x;",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   453
                                          null);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   454
        verifyConflictingExports_packages(base,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   455
                                          "opens p to m2x; opens p to m3x;",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   456
                                          "module-info.java:1:36: compiler.err.conflicting.opens: p");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   457
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   458
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   459
    private void verifyConflictingExports_packages(Path base, String code, String expected) throws Exception {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   460
        Files.createDirectories(base);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   461
        tb.cleanDirectory(base);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   462
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   463
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   464
        tb.writeJavaFiles(src.resolve("m1x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   465
                          "module m1x { " + code + " }",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   466
                          "package p; public class P {}",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   467
                          "package q; public class Q {}");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   468
        tb.writeJavaFiles(src.resolve("m2x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   469
                          "module m2x { requires m1x; }");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   470
        tb.writeJavaFiles(src.resolve("m3x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   471
                          "module m3x { requires m1x; }");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   472
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   473
        Path classes = base.resolve("classes");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   474
        Files.createDirectories(classes);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   475
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   476
        String log = new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   477
                .options("-XDrawDiagnostics",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   478
                         "--module-source-path", src.toString())
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   479
                .outdir(classes)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   480
                .files(findJavaFiles(src))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   481
                .run(expected != null ? Task.Expect.FAIL : Task.Expect.SUCCESS)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   482
                .writeAll()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   483
                .getOutput(Task.OutputKind.DIRECT);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   484
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   485
        if (expected != null && !log.contains(expected))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   486
            throw new Exception("expected output not found, actual output: " + log);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   487
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   488
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   489
    /**
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   490
     * Verify that duplicate exported packages are detected.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   491
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   492
    @Test
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   493
    public void testConflictingExports_modules(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   494
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   495
        Path src_m1 = src.resolve("m1x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   496
        tb.writeFile(src_m1.resolve("module-info.java"), "module m1x { }");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   497
        Path src_m2 = src.resolve("m2x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   498
        tb.writeFile(src_m2.resolve("module-info.java"), "module m2x { exports p to m1x, m1x; }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   499
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   500
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   501
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   502
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   503
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38916
diff changeset
   504
                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   505
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   506
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   507
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   508
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   509
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   510
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   511
        if (!log.contains("module-info.java:1:32: compiler.err.conflicting.exports.to.module: m1x"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   512
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   513
    }
38916
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   514
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   515
    /**
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   516
     * Verify that annotations are not permitted at
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   517
     * any of the module names or the package names.
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   518
     */
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   519
    @Test
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   520
    public void testAnnotations(Path base) throws Exception {
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   521
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   522
        Path src_m1 = src.resolve("m1x.sub");
38916
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   523
        Path classes = base.resolve("classes");
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   524
        Files.createDirectories(classes);
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   525
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   526
        String code = "module @m1.@sub { " +
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   527
                "requires @p1.@p2; " +
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   528
                "exports @p1.@p2; " +
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   529
                "exports @p1.@p2 to @m2.@sub; " +
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   530
                "exports @p1.@p2 to @m2.@sub, @m3.@sub; " +
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   531
                "uses @p1.@Interface; " +
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   532
                "provides @p1.@Interface with @p2.@Concrete; " +
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   533
                "}";
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   534
        String[] splittedCode = code.split("@");
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   535
        int length = splittedCode.length;
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   536
        String anno = "@Anno ";
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   537
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   538
        for (int i = 1; i < length; i++) {
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   539
            String preAnno = String.join("", Arrays.copyOfRange(splittedCode, 0, i));
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   540
            String postAnno = String.join("", Arrays.copyOfRange(splittedCode, i, length));
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   541
            String moduleInfo = preAnno + anno + postAnno;
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   542
            tb.writeFile(src_m1.resolve("module-info.java"), moduleInfo);
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   543
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   544
            String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38916
diff changeset
   545
                    .options("-XDrawDiagnostics", "--module-source-path", src.toString())
38916
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   546
                    .outdir(classes)
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   547
                    .files(findJavaFiles(src))
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   548
                    .run(Task.Expect.FAIL)
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   549
                    .writeAll()
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   550
                    .getOutput(Task.OutputKind.DIRECT);
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   551
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   552
            String expect_prefix = "(?s)^module\\-info\\.java:\\d+:\\d+: ";
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   553
            String expect_message = "compiler\\.err\\.expected: token\\.identifier";
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   554
            String expect_suffix = ".*";
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   555
            String expect = expect_prefix + expect_message + expect_suffix;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   556
            if (!log.matches(expect))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40308
diff changeset
   557
                throw new Exception("expected output not found for: " + moduleInfo + "; actual: " + log);
38916
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   558
        }
d118cb2cffab 8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents: 37758
diff changeset
   559
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   560
}