langtools/test/tools/javac/modules/UsesTest.java
author vromero
Fri, 06 May 2016 16:06:27 -0400
changeset 37854 a76a06106d02
parent 37758 3ecf9b414e05
child 39103 91a64ec5b970
permissions -rw-r--r--
8153268: javac accepts enums being referenced by 'uses' statement Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary simple tests of module uses
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
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    31
 * @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @run main UsesTest
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.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.Collection;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.util.List;
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;
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    42
import toolbox.ModuleBuilder;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    43
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    44
import toolbox.ToolBox;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    45
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
public class UsesTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
        UsesTest t = new UsesTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        t.runTests();
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
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    53
    public void testSimple(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
                "module m { uses p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    61
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    64
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    69
    public void testSimpleInner(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
                "module m { uses p.C.Inner; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
                "package p; public class C { public class Inner { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    77
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    80
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
                .writeAll();
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
    @Test
37854
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    85
    public void testEnumAsAService(Path base) throws Exception {
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    86
        Path src = base.resolve("src");
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    87
        tb.writeJavaFiles(src,
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    88
                "module m { uses pkg.EnumST; }",
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    89
                "package pkg; public enum EnumST {A, B}");
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    90
        Path classes = base.resolve("classes");
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    91
        Files.createDirectories(classes);
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    92
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    93
        List<String> output = new JavacTask(tb)
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    94
                .options("-XDrawDiagnostics")
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    95
                .outdir(classes)
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    96
                .files(tb.findJavaFiles(src))
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    97
                .run(Task.Expect.FAIL)
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    98
                .writeAll()
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
    99
                .getOutputLines(Task.OutputKind.DIRECT);
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   100
        List<String> expected = Arrays.asList("module-info.java:1:20: compiler.err.service.definition.is.enum: pkg.EnumST",
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   101
                "1 error");
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   102
        if (!output.containsAll(expected)) {
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   103
            throw new Exception("Expected output not found");
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   104
        }
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   105
    }
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   106
a76a06106d02 8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents: 37758
diff changeset
   107
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   108
    public void testSimpleAnnotation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
                "module m { uses p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
                "package p; public @interface C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   116
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   119
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   124
    public void testPrivateService(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
                "module m { uses p.C.A; uses p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
                "package p; public class C { protected class A { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   130
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   134
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   136
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
        List<String> expected = Arrays.asList("module-info.java:1:20: compiler.err.report.access: p.C.A, protected, p.C",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   146
    public void testMulti(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        tb.writeJavaFiles(src.resolve("m1"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                "module m1 { exports p; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        tb.writeJavaFiles(src.resolve("m2"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
                "module m2 { requires m1; uses p.C; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   156
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                .options("-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   160
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   165
    public void testMultiOnModulePath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   167
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
                .exports("p")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
                .classes("package p; public class C { }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
                .build(modules);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   171
        new ModuleBuilder(tb, "m2")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                .requires("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                .uses("p.C")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                .write(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   176
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                .options("-mp", modules.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
                .files(findJavaFiles(modules.resolve("m2")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   180
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   185
    public void testMultiOnModulePathInner(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   187
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
                .exports("p")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                .classes("package p; public class C { public class Inner { } }")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                .build(modules);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   191
        new ModuleBuilder(tb, "m2")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                .requires("m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                .uses("p.C.Inner")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
                .write(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   196
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                .options("-mp", modules.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
                .files(findJavaFiles(modules.resolve("m2")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   200
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   205
    public void testDuplicateUses(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        tb.writeJavaFiles(src.resolve("m"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
                "module m { uses p.C; uses p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   211
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   215
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   217
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
        if (!output.containsAll(Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                "module-info.java:1:22: compiler.err.duplicate.uses: p.C"))) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   226
    public void testServiceNotExist(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
                "module m { uses p.NotExist; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   232
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   236
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   238
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        Collection<?> expected = Arrays.asList("module-info.java:1:18: compiler.err.cant.resolve.location: kindname.class, NotExist, , , (compiler.misc.location: kindname.package, p, null)",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   247
    public void testUsesUnexportedService(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
        tb.writeJavaFiles(src.resolve("m1"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
                "module m1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
        tb.writeJavaFiles(src.resolve("m2"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
                "module m2 { requires m1; uses p.C; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   255
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
                .options("-XDrawDiagnostics", "-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
                .outdir(Files.createDirectories(base.resolve("modules")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   259
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   261
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        List<String> expected = Arrays.asList("module-info.java:1:32: compiler.err.not.def.access.package.cant.access: p.C, p",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   271
    public void testUsesUnexportedButProvidedService(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
        tb.writeJavaFiles(src.resolve("m1"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                "module m1 { provides p.C with p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        tb.writeJavaFiles(src.resolve("m2"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
                "module m2 { requires m1; uses p.C; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   279
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
                .options("-XDrawDiagnostics", "-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
                .outdir(Files.createDirectories(base.resolve("modules")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   283
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   285
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
        List<String> expected = Arrays.asList("module-info.java:1:32: compiler.err.not.def.access.package.cant.access: p.C, p",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
}