langtools/test/tools/javac/modules/ProvidesTest.java
author jjg
Wed, 10 Aug 2016 15:47:46 -0700
changeset 40308 274367a99f98
parent 38827 884d32899770
child 41942 260c724e5614
permissions -rw-r--r--
8136930: Simplify use of module-system options by custom launchers 8160489: Multiple -Xpatch lines ignored by javac 8156998: javac should support new option -XinheritRuntimeEnvironment Reviewed-by: jlahoda, ksrini
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 provides
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 ProvidesTest
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.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    40
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    41
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    42
import toolbox.ToolBox;
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 ProvidesTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
        ProvidesTest t = new ProvidesTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    51
    public void testSimple(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
                "module m { provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
                "package p2; public class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    60
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    63
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    68
    public void testMulti(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        tb.writeJavaFiles(src.resolve("m1"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
                "module m1 { exports p1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
                "package p1; public class C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        tb.writeJavaFiles(src.resolve("m2"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
                "module m2 { requires m1; provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
                "package p2; public class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    79
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38827
diff changeset
    80
                .options("--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    83
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    89
    public void testMissingWith(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
                "module m { provides p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    97
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   101
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   103
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        if (!log.contains("module-info.java:1:24: compiler.err.expected: 'with'"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   111
    public void testDuplicateProvides(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                "module m { provides p1.C1 with p2.C2; provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                "package p2; public class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   120
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                .options("-XDrawDiagnostic")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   124
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   129
    public void testMissingService(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                "module m { provides p.Missing with p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                "package p; public class C extends p.Missing { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   135
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   139
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   141
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
                "C.java:1:36: compiler.err.cant.resolve.location: kindname.class, Missing, , , (compiler.misc.location: kindname.package, p, null)",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
                "module-info.java:1:22: compiler.err.cant.resolve.location: kindname.class, Missing, , , (compiler.misc.location: kindname.package, p, null)",
38827
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 37758
diff changeset
   146
                "2 errors");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   153
    public void testProvidesFromAnotherModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        tb.writeJavaFiles(modules.resolve("M"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                "module M { exports p; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                "package p; public class Service { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        tb.writeJavaFiles(modules.resolve("L"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                "module L { requires M; provides p.Service with p.Service; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   161
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38827
diff changeset
   163
                        "--module-source-path", modules.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
                .files(findJavaFiles(modules))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   166
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   168
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
                "module-info.java:1:24: compiler.err.service.implementation.not.in.right.module: M",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   179
    public void testServiceIsNotImplemented(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
                "module m { provides p.A with p.B; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
                "package p; public class A { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
                "package p; public class B { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   186
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   190
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   192
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
38827
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 37758
diff changeset
   194
        List<String> expected = Arrays.asList(
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 37758
diff changeset
   195
                "module-info.java:1:31: compiler.err.service.implementation.must.be.subtype.of.service.interface",
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 37758
diff changeset
   196
                "module-info.java:1:12: compiler.warn.service.provided.but.not.exported.or.used: p.A",
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 37758
diff changeset
   197
                "1 error",
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 37758
diff changeset
   198
                "1 warning");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
        }
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 testMissingImplementation(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,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
                "module m { provides p.C with p.Impl; }",
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
        List<String> expected = Arrays.asList("module-info.java:1:31: compiler.err.cant.resolve.location: kindname.class, Impl, , , (compiler.misc.location: kindname.package, p, null)",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
            throw new Exception("Expected output not found");
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   227
    public void testSeveralImplementations(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                "module m { provides p.C with p.Impl1; provides p.C with p.Impl2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                "package p; public class C { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                "package p; public class Impl1 extends p.C { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
                "package p; public class Impl2 extends p.C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   235
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   238
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   243
    public void testOneImplementationsForServices(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
                "module m { provides p.Service1 with p.Impl; provides p.Service2 with p.Impl; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
                "package p; public interface Service1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                "package p; public abstract class Service2 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                "package p; public class Impl extends p.Service2 implements p.Service1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   251
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   254
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   259
    public void testAbstractImplementation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
                "module m { provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
                "package p2; public abstract class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   266
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   270
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   272
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
                "module-info.java:1:34: compiler.err.service.implementation.is.abstract: p2.C2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
        }
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
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   282
    public void testInterfaceImplementation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
                "module m { provides p1.Service with p2.Impl; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
                "package p1; public interface Service { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
                "package p2; public interface Impl extends p1.Service { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   289
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   293
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   295
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
                "module-info.java:1:39: compiler.err.service.implementation.is.abstract: p2.Impl");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   303
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   305
    public void testProtectedImplementation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
                "module m { provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
                "package p2; class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   312
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   315
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   316
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   318
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
        List<String> expected = Arrays.asList("module-info.java:1:34: compiler.err.not.def.public.cant.access: p2.C2, p2",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   323
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   328
    public void testNoNoArgConstructor(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   331
                "module m { uses p1.C1; provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   332
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
                "package p2; public class C2 extends p1.C1 { public C2(String str) { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   335
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   337
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   338
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   339
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   340
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   341
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   342
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   343
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   344
                "module-info.java:1:46: compiler.err.service.implementation.doesnt.have.a.no.args.constructor: p2.C2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   345
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   346
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   347
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   348
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   349
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   350
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   351
    public void testPrivateNoArgConstructor(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   352
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   353
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   354
                "module m { uses p1.C1; provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   355
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   356
                "package p2; public class C2 extends p1.C1 { private C2() { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   357
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   358
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   359
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   360
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   362
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   363
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   364
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   365
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   366
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   367
                "module-info.java:1:46: compiler.err.service.implementation.no.args.constructor.not.public: p2.C2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   368
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   369
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   370
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   371
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   372
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   374
    public void testServiceIndirectlyImplemented(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   375
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   376
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   377
                "module m { provides p1.C1 with p2.C3; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   378
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   379
                "package p2; public class C2 extends p1.C1 {  }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   380
                "package p2; public class C3 extends p2.C2 {  }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   381
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   382
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   383
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   384
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   385
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   386
                .writeAll();
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
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   390
    public void testServiceImplementationInnerClass(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   391
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   392
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   393
                "module m { provides p1.C1 with p2.C2.Inner; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   394
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   395
                "package p2; public class C2  { public class Inner extends p1.C1 { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   396
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   397
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   398
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   399
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   400
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   401
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   402
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   403
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   404
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   405
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   406
                "module-info.java:1:37: compiler.err.service.implementation.is.inner: p2.C2.Inner");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   407
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   408
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   409
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   410
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   411
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   412
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   413
    public void testServiceDefinitionInnerClass(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   414
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   415
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   416
                "module m { provides p1.C1.InnerDefinition with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   417
                "package p1; public class C1 { public class InnerDefinition { } }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   418
                "package p2; public class C2 extends p1.C1.InnerDefinition { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   419
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   420
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   421
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   422
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   423
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   424
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   425
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   426
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   427
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   428
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   429
                "module-info.java:1:26: compiler.err.service.definition.is.inner: p1.C1.InnerDefinition",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   430
                "module-info.java:1:12: compiler.warn.service.provided.but.not.exported.or.used: p1.C1.InnerDefinition",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   431
                "C2.java:1:20: compiler.err.encl.class.required: p1.C1.InnerDefinition",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   432
                "2 errors",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   433
                "1 warning");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   434
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   435
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   436
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   437
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   438
}