langtools/test/tools/javac/modules/ProvidesTest.java
author mcimadamore
Mon, 07 Nov 2016 11:16:23 +0000
changeset 41942 260c724e5614
parent 40308 274367a99f98
child 42407 f3702cff2933
permissions -rw-r--r--
8168854: javac erroneously reject a a service interface inner class in a provides clause Summary: Java SE 9 proposed spec changes do not explicitly forbid a service interface to be an inner class - javac should follow 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 provides
41942
260c724e5614 8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents: 40308
diff changeset
    27
 * @bug 8168854
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @library /tools/lib
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @modules
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 *      jdk.compiler/com.sun.tools.javac.api
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *      jdk.compiler/com.sun.tools.javac.main
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    32
 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 * @run main ProvidesTest
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.Arrays;
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;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    42
import toolbox.Task;
41942
260c724e5614 8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents: 40308
diff changeset
    43
import toolbox.Task.Expect;
36778
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 ProvidesTest 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
        ProvidesTest t = new ProvidesTest();
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 { provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
                "package p2; public class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    62
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    65
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    70
    public void testMulti(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        tb.writeJavaFiles(src.resolve("m1"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
                "module m1 { exports p1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
                "package p1; public class C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        tb.writeJavaFiles(src.resolve("m2"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
                "module m2 { requires m1; provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
                "package p2; public class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    81
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38827
diff changeset
    82
                .options("--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    85
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    91
    public void testMissingWith(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
                "module m { provides p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    99
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   103
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   105
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        if (!log.contains("module-info.java:1:24: compiler.err.expected: 'with'"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   113
    public void testDuplicateProvides(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                "module m { provides p1.C1 with p2.C2; provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
                "package p2; public class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   122
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                .options("-XDrawDiagnostic")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   126
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   131
    public void testMissingService(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
                "module m { provides p.Missing with p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                "package p; public class C extends p.Missing { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   137
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   141
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   143
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
                "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
   147
                "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
   148
                "2 errors");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   155
    public void testProvidesFromAnotherModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        tb.writeJavaFiles(modules.resolve("M"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                "module M { exports p; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                "package p; public class Service { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        tb.writeJavaFiles(modules.resolve("L"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                "module L { requires M; provides p.Service with p.Service; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   163
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38827
diff changeset
   165
                        "--module-source-path", modules.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
                .files(findJavaFiles(modules))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   168
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   170
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                "module-info.java:1:24: compiler.err.service.implementation.not.in.right.module: M",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
            throw new Exception("Expected output not found");
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
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   181
    public void testServiceIsNotImplemented(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
                "module m { provides p.A with p.B; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
                "package p; public class A { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
                "package p; public class B { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   188
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   192
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   194
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
38827
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 37758
diff changeset
   196
        List<String> expected = Arrays.asList(
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 37758
diff changeset
   197
                "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
   198
                "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
   199
                "1 error",
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 37758
diff changeset
   200
                "1 warning");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   207
    public void testMissingImplementation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                "module m { provides p.C with p.Impl; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   213
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   217
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   219
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
        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
   222
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   229
    public void testSeveralImplementations(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                "module m { provides p.C with p.Impl1; provides p.C with p.Impl2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
                "package p; public class C { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
                "package p; public class Impl1 extends p.C { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
                "package p; public class Impl2 extends p.C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   237
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   240
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   245
    public void testOneImplementationsForServices(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                "module m { provides p.Service1 with p.Impl; provides p.Service2 with p.Impl; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                "package p; public interface Service1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
                "package p; public abstract class Service2 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
                "package p; public class Impl extends p.Service2 implements p.Service1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   253
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   256
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   261
    public void testAbstractImplementation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
                "module m { provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                "package p2; public abstract class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   268
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   272
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   274
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
                "module-info.java:1:34: compiler.err.service.implementation.is.abstract: p2.C2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   284
    public void testInterfaceImplementation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
                "module m { provides p1.Service with p2.Impl; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
                "package p1; public interface Service { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
                "package p2; public interface Impl extends p1.Service { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   291
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   295
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   297
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
                "module-info.java:1:39: compiler.err.service.implementation.is.abstract: p2.Impl");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   303
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   307
    public void testProtectedImplementation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
                "module m { provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
                "package p2; class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   314
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   315
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   318
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   320
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
        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
   323
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   328
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   330
    public void testNoNoArgConstructor(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   331
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   332
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
                "module m { uses p1.C1; provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
                "package p2; public class C2 extends p1.C1 { public C2(String str) { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   337
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   338
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   339
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   340
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   341
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   342
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   343
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   344
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   345
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   346
                "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
   347
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   348
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   349
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   350
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   351
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   352
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   353
    public void testPrivateNoArgConstructor(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   354
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   355
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   356
                "module m { uses p1.C1; provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   357
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   358
                "package p2; public class C2 extends p1.C1 { private C2() { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   359
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   360
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   362
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   363
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   364
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   365
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   366
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   367
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   368
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   369
                "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
   370
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   371
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   372
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   374
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   375
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   376
    public void testServiceIndirectlyImplemented(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   377
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   378
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   379
                "module m { provides p1.C1 with p2.C3; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   380
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   381
                "package p2; public class C2 extends p1.C1 {  }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   382
                "package p2; public class C3 extends p2.C2 {  }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   383
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   384
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   385
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   386
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   387
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   388
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   389
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   390
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   391
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   392
    public void testServiceImplementationInnerClass(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   393
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   394
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   395
                "module m { provides p1.C1 with p2.C2.Inner; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   396
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   397
                "package p2; public class C2  { public class Inner extends p1.C1 { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   398
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   399
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   400
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   401
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   402
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   403
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   404
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   405
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   406
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   407
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   408
                "module-info.java:1:37: compiler.err.service.implementation.is.inner: p2.C2.Inner");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   409
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   410
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   411
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   412
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   413
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   414
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   415
    public void testServiceDefinitionInnerClass(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   416
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   417
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   418
                "module m { provides p1.C1.InnerDefinition with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   419
                "package p1; public class C1 { public class InnerDefinition { } }",
41942
260c724e5614 8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents: 40308
diff changeset
   420
                "package p2; public class C2 extends p1.C1.InnerDefinition { public C2() { new p1.C1().super(); } }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   421
41942
260c724e5614 8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents: 40308
diff changeset
   422
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   423
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   424
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   425
                .files(findJavaFiles(src))
41942
260c724e5614 8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents: 40308
diff changeset
   426
                .run(Expect.SUCCESS)
260c724e5614 8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents: 40308
diff changeset
   427
                .writeAll();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   428
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   429
}