test/langtools/tools/javac/modules/ResolveTest.java
author darcy
Fri, 02 Feb 2018 10:29:25 -0800
changeset 48723 6cb86bf0b51e
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196623: Update JavaBaseTest.java to be version agnostic Reviewed-by: vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
     2
 * Copyright (c) 2013, 2016, 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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary tests for module resolution
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
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    31
 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @run main ResolveTest
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.nio.file.*;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    37
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    38
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    39
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
public class ResolveTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
        ResolveTest t = new ResolveTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    47
    public void testMissingSimpleTypeUnnamedModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        tb.writeJavaFiles(src, "class C { D d; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    51
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    54
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    56
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        if (!log.contains("C.java:1:11: compiler.err.cant.resolve.location: "
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
                + "kindname.class, D, , , (compiler.misc.location: kindname.class, C, null)"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    64
    public void testMissingSimpleTypeNamedModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
                "module m { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
                "class C { D d; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    70
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    73
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    75
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        if (!log.contains("C.java:1:11: compiler.err.cant.resolve.location: "
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
                + "kindname.class, D, , , (compiler.misc.location: kindname.class, C, null)"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
            throw new Exception("expected output not found");
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
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    83
    public void testUnexportedTypeUnreadableModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
    85
        tb.writeJavaFiles(src.resolve("m1x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
    86
                "module m1x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
                "package p1; public class C1 { }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
    88
        tb.writeJavaFiles(src.resolve("m2x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
    89
                "module m2x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
                "package p2; public class C2 { p1.C1 c; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    94
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
    95
                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    98
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   100
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
43138
680d378b9d64 8169197: Improve error reporting for compiling against unexported package
jlahoda
parents: 42822
diff changeset
   102
        if (!log.contains("C2.java:1:31: compiler.err.package.not.visible: p1, (compiler.misc.not.def.access.does.not.read: m2x, p1, m1x)"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   107
    public void testUnexportedTypeReadableModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   109
        tb.writeJavaFiles(src.resolve("m1x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   110
                "module m1x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                "package p1; public class C1 { }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   112
        tb.writeJavaFiles(src.resolve("m2x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   113
                "module m2x { requires m1x; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                "package p2; public class C2 { p1.C1 c; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   118
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   119
                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   122
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   124
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
43138
680d378b9d64 8169197: Improve error reporting for compiling against unexported package
jlahoda
parents: 42822
diff changeset
   126
        if (!log.contains("C2.java:1:31: compiler.err.package.not.visible: p1, (compiler.misc.not.def.access.not.exported: p1, m1x)"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   131
    public void testQualifiedExportedTypeReadableModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   133
        tb.writeJavaFiles(src.resolve("m1x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   134
                "module m1x { exports p1 to m3x; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                "package p1; public class C1 { }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   136
        tb.writeJavaFiles(src.resolve("m2x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   137
                "module m2x { requires m1x; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                "package p2; public class C2 { p1.C1 c; }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   139
        tb.writeJavaFiles(src.resolve("m3x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   140
                "module m3x { requires m1x; }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   144
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   145
                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   148
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   150
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
43138
680d378b9d64 8169197: Improve error reporting for compiling against unexported package
jlahoda
parents: 42822
diff changeset
   152
        if (!log.contains("C2.java:1:31: compiler.err.package.not.visible: p1, (compiler.misc.not.def.access.not.exported.to.module: p1, m1x, m2x)"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   157
    public void testExportedTypeUnreadableModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   159
        tb.writeJavaFiles(src.resolve("m1x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   160
                "module m1x { exports p1; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                "package p1; public class C1 { }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   162
        tb.writeJavaFiles(src.resolve("m2x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   163
                "module m2x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
                "package p2; public class C2 { p1.C1 c; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   168
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   169
                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   172
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   174
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
43138
680d378b9d64 8169197: Improve error reporting for compiling against unexported package
jlahoda
parents: 42822
diff changeset
   176
        if (!log.contains("C2.java:1:31: compiler.err.package.not.visible: p1, (compiler.misc.not.def.access.does.not.read: m2x, p1, m1x)"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   181
    public void testExportedTypeReadableModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   183
        tb.writeJavaFiles(src.resolve("m1x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   184
                "module m1x { exports p1; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
                "package p1; public class C1 { }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   186
        tb.writeJavaFiles(src.resolve("m2x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   187
                "module m2x { requires m1x; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
                "package p2; public class C2 { p1.C1 c; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   192
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   193
                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                .writeAll();
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
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   201
    public void testExportedTypeReadableModule2(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   203
        tb.writeJavaFiles(src.resolve("m1x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   204
                "module m1x { exports p1 to m2x; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
                "package p1; public class C1 { }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   206
        tb.writeJavaFiles(src.resolve("m2x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41932
diff changeset
   207
                "module m2x { requires m1x; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
                "package p2; public class C2 { p1.C1 c; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   212
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   213
                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
}