test/langtools/tools/javac/modules/ProvidesTest.java
author vromero
Fri, 02 Feb 2018 07:43:54 -0500
changeset 48721 ef3557eb4306
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196403: remove the remaining use of string keys for errors and warnings in the compiler Reviewed-by: mcimadamore, jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
48721
ef3557eb4306 8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary simple tests of module provides
43577
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
    27
 * @bug 8168854 8172807
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
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
public class ProvidesTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        ProvidesTest t = new ProvidesTest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    52
    public void testSimple(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
                "module m { provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
                "package p2; public class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    61
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    64
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    69
    public void testMulti(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
    71
        tb.writeJavaFiles(src.resolve("m1x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
    72
                "module m1x { exports p1; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
                "package p1; public class C1 { }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
    74
        tb.writeJavaFiles(src.resolve("m2x"),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
    75
                "module m2x { requires m1x; provides p1.C1 with p2.C2; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
                "package p2; public class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        Files.createDirectories(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    80
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38827
diff changeset
    81
                .options("--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
                .outdir(modules)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    84
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
                .writeAll();
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    90
    public void testMissingWith(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
                "module m { provides p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    98
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   102
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   104
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
48721
ef3557eb4306 8196403: remove the remaining use of string keys for errors and warnings in the compiler
vromero
parents: 47216
diff changeset
   106
        if (!log.contains("module-info.java:1:24: compiler.err.expected.str: 'with'"))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
            throw new Exception("expected output not found");
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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
    @Test
43577
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   112
    public void testDuplicateImplementations1(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        tb.writeJavaFiles(src,
43577
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   115
                "module m { exports p1; exports p2; provides p1.C1 with p2.C2, p2.C2; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                "package p2; public class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
43577
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   121
        List<String> output = new JavacTask(tb)
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   122
                .options("-XDrawDiagnostics")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   125
                .run(Task.Expect.FAIL)
43577
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   126
                .writeAll()
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   127
                .getOutputLines(Task.OutputKind.DIRECT);
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   128
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   129
        List<String> expected = Arrays.asList(
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   130
                "module-info.java:1:65: compiler.err.duplicate.provides: p1.C1, p2.C2",
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   131
                "1 error");
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   132
        if (!output.containsAll(expected)) {
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   133
            throw new Exception("Expected output not found");
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   134
        }
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   135
    }
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   136
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   137
    @Test
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   138
    public void testDuplicateImplementations2(Path base) throws Exception {
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   139
        Path src = base.resolve("src");
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   140
        tb.writeJavaFiles(src,
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   141
                "module m { exports p1; provides p1.C1 with p2.C2; provides p1.C1 with p2.C2; }",
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   142
                "package p1; public class C1 { }",
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   143
                "package p2; public class C2 extends p1.C1 { }");
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   144
        Path classes = base.resolve("classes");
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   145
        Files.createDirectories(classes);
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   146
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   147
        List<String> output = new JavacTask(tb)
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   148
                .options("-XDrawDiagnostics")
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   149
                .outdir(classes)
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   150
                .files(findJavaFiles(src))
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   151
                .run(Task.Expect.FAIL)
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   152
                .writeAll()
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   153
                .getOutputLines(Task.OutputKind.DIRECT);
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   154
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   155
        List<String> expected = Arrays.asList(
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   156
                "module-info.java:1:62: compiler.err.repeated.provides.for.service: p1.C1",
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   157
                "module-info.java:1:73: compiler.err.duplicate.provides: p1.C1, p2.C2",
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   158
                "2 errors");
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   159
        if (!output.containsAll(expected)) {
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   160
            throw new Exception("Expected output not found");
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   161
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   165
    public void testMissingService(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
                "module m { provides p.Missing with p.C; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
                "package p; public class C extends p.Missing { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   171
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   175
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   177
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
                "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
   181
                "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
   182
                "2 errors");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   189
    public void testProvidesFromAnotherModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        Path modules = base.resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
        tb.writeJavaFiles(modules.resolve("M"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                "module M { exports p; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                "package p; public class Service { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
        tb.writeJavaFiles(modules.resolve("L"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                "module L { requires M; provides p.Service with p.Service; }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   197
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 38827
diff changeset
   199
                        "--module-source-path", modules.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
                .files(findJavaFiles(modules))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   202
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   204
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
                "module-info.java:1:24: compiler.err.service.implementation.not.in.right.module: M",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   215
    public void testServiceIsNotImplemented(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
                "module m { provides p.A with p.B; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                "package p; public class A { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                "package p; public class B { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   222
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   226
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   228
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
38827
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 37758
diff changeset
   230
        List<String> expected = Arrays.asList(
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 37758
diff changeset
   231
                "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
   232
                "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
   233
                "1 error",
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents: 37758
diff changeset
   234
                "1 warning");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   241
    public void testMissingImplementation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
                "module m { provides p.C with p.Impl; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                "package p; public class C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   247
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   251
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   253
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
        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
   256
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   263
    public void testSeveralImplementations(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
        tb.writeJavaFiles(src,
43577
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   266
                "module m { provides p.C with p.Impl1, p.Impl2; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                "package p; public class C { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                "package p; public class Impl1 extends p.C { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
                "package p; public class Impl2 extends p.C { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   271
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   274
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
    @Test
43577
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   279
    public void testRepeatedProvides(Path base) throws Exception {
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   280
        Path src = base.resolve("src");
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   281
        tb.writeJavaFiles(src,
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   282
                "module m { exports p; provides p.C with p.Impl1; provides p.C with p.Impl2; }",
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   283
                "package p; public class C { }",
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   284
                "package p; public class Impl1 extends p.C { }",
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   285
                "package p; public class Impl2 extends p.C { }");
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   286
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   287
        List<String> output = new JavacTask(tb)
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   288
                .options("-XDrawDiagnostics")
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   289
                .outdir(Files.createDirectories(base.resolve("classes")))
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   290
                .files(findJavaFiles(src))
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   291
                .run(Task.Expect.FAIL)
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   292
                .writeAll()
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   293
                .getOutputLines(Task.OutputKind.DIRECT);
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   294
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   295
        List<String> expected = Arrays.asList("module-info.java:1:60: compiler.err.repeated.provides.for.service: p.C",
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   296
                "1 error");
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   297
        if (!output.containsAll(expected)) {
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   298
            throw new Exception("Expected output not found");
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   299
        }
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   300
    }
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   301
1a1b1242f7aa 8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents: 42822
diff changeset
   302
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   303
    public void testOneImplementationsForServices(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
                "module m { provides p.Service1 with p.Impl; provides p.Service2 with p.Impl; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
                "package p; public interface Service1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
                "package p; public abstract class Service2 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
                "package p; public class Impl extends p.Service2 implements p.Service1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   311
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   314
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   315
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   319
    public void testAbstractImplementation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
                "module m { provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   323
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
                "package p2; public abstract class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   326
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   328
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   330
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   331
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   332
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
                "module-info.java:1:34: compiler.err.service.implementation.is.abstract: p2.C2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   337
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   338
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   339
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   340
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   341
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   342
    public void testInterfaceImplementation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   343
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   344
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   345
                "module m { provides p1.Service with p2.Impl; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   346
                "package p1; public interface Service { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   347
                "package p2; public interface Impl extends p1.Service { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   348
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   349
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   350
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   351
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   352
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   353
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   354
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   355
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   356
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   357
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   358
                "module-info.java:1:39: compiler.err.service.implementation.is.abstract: p2.Impl");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   359
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   360
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   362
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   363
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   364
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   365
    public void testProtectedImplementation(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   366
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   367
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   368
                "module m { provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   369
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   370
                "package p2; class C2 extends p1.C1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   371
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   372
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   374
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   375
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   376
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   377
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   378
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   379
43865
532c50fea155 8174243: incorrect error message for nested service provider
vromero
parents: 43577
diff changeset
   380
        List<String> expected = Arrays.asList("module-info.java:1:34: compiler.err.not.def.public: p2.C2, p2",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   381
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   382
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   383
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   384
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   385
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   386
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   387
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   388
    public void testNoNoArgConstructor(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   389
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   390
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   391
                "module m { uses p1.C1; provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   392
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   393
                "package p2; public class C2 extends p1.C1 { public C2(String str) { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   394
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   395
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   396
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   397
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   398
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   399
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   400
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   401
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   402
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   403
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   404
                "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
   405
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   406
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   407
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   408
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   409
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   410
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   411
    public void testPrivateNoArgConstructor(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   412
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   413
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   414
                "module m { uses p1.C1; provides p1.C1 with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   415
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   416
                "package p2; public class C2 extends p1.C1 { private C2() { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   417
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   418
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   419
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   420
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   421
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   422
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   423
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   424
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   425
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   426
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   427
                "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
   428
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   429
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   430
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   431
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   432
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   433
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   434
    public void testServiceIndirectlyImplemented(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   435
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   436
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   437
                "module m { provides p1.C1 with p2.C3; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   438
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   439
                "package p2; public class C2 extends p1.C1 {  }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   440
                "package p2; public class C3 extends p2.C2 {  }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   441
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   442
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   443
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   444
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   445
                .run(Task.Expect.SUCCESS)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   446
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   447
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   448
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   449
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   450
    public void testServiceImplementationInnerClass(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   451
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   452
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   453
                "module m { provides p1.C1 with p2.C2.Inner; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   454
                "package p1; public class C1 { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   455
                "package p2; public class C2  { public class Inner extends p1.C1 { } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   456
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   457
        List<String> output = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   458
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   459
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   460
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   461
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   462
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   463
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   464
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   465
        List<String> expected = Arrays.asList(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   466
                "module-info.java:1:37: compiler.err.service.implementation.is.inner: p2.C2.Inner");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   467
        if (!output.containsAll(expected)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   468
            throw new Exception("Expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   469
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   470
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   471
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   472
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   473
    public void testServiceDefinitionInnerClass(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   474
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   475
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   476
                "module m { provides p1.C1.InnerDefinition with p2.C2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   477
                "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
   478
                "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
   479
41942
260c724e5614 8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents: 40308
diff changeset
   480
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   481
                .options("-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   482
                .outdir(Files.createDirectories(base.resolve("classes")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   483
                .files(findJavaFiles(src))
41942
260c724e5614 8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents: 40308
diff changeset
   484
                .run(Expect.SUCCESS)
260c724e5614 8168854: javac erroneously reject a a service interface inner class in a provides clause
mcimadamore
parents: 40308
diff changeset
   485
                .writeAll();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   486
    }
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   487
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   488
    @Test
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   489
    public void testFactory(Path base) throws Exception {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   490
        Path src = base.resolve("src");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   491
        tb.writeJavaFiles(src,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   492
                "module m { exports p1; provides p1.C1 with p2.C2; }",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   493
                "package p1; public interface C1 { }",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   494
                "package p2; public class C2 { public static p1.C1 provider() { return null; } }");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   495
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   496
        new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   497
                .options("-XDrawDiagnostics")
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   498
                .outdir(Files.createDirectories(base.resolve("classes")))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   499
                .files(findJavaFiles(src))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   500
                .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   501
                .writeAll()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   502
                .getOutput(Task.OutputKind.DIRECT);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   503
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   504
        List<String> output;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   505
        List<String> expected;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   506
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   507
        tb.writeJavaFiles(src,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   508
                "package p2; public class C2 { public p1.C1 provider() { return null; } }");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   509
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   510
        output = new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   511
                .options("-XDrawDiagnostics")
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   512
                .outdir(Files.createDirectories(base.resolve("classes")))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   513
                .files(findJavaFiles(src))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   514
                .run(Task.Expect.FAIL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   515
                .writeAll()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   516
                .getOutputLines(Task.OutputKind.DIRECT);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   517
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   518
        expected = Arrays.asList("module-info.java:1:46: compiler.err.service.implementation.must.be.subtype.of.service.interface",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   519
                                 "1 error");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   520
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   521
        if (!expected.equals(output)) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   522
            throw new Exception("Expected output not found. Output: " + output);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   523
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   524
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   525
        tb.writeJavaFiles(src,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   526
                "package p2; public class C2 { static p1.C1 provider() { return null; } }");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   527
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   528
        output = new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   529
                .options("-XDrawDiagnostics")
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   530
                .outdir(Files.createDirectories(base.resolve("classes")))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   531
                .files(findJavaFiles(src))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   532
                .run(Task.Expect.FAIL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   533
                .writeAll()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   534
                .getOutputLines(Task.OutputKind.DIRECT);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   535
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   536
        expected = Arrays.asList("module-info.java:1:46: compiler.err.service.implementation.must.be.subtype.of.service.interface",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   537
                                 "1 error");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   538
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   539
        if (!expected.equals(output)) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   540
            throw new Exception("Expected output not found. Output: " + output);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   541
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   542
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   543
        tb.writeJavaFiles(src,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   544
                "package p2; public class C2 { public static Object provider() { return null; } }");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   545
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   546
        output = new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   547
                .options("-XDrawDiagnostics")
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   548
                .outdir(Files.createDirectories(base.resolve("classes")))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   549
                .files(findJavaFiles(src))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   550
                .run(Task.Expect.FAIL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   551
                .writeAll()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   552
                .getOutputLines(Task.OutputKind.DIRECT);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   553
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   554
        expected = Arrays.asList("module-info.java:1:46: compiler.err.service.implementation.provider.return.must.be.subtype.of.service.interface",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   555
                                 "1 error");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   556
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   557
        if (!expected.equals(output)) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   558
            throw new Exception("Expected output not found. Output: " + output);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   559
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   560
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   561
        tb.writeJavaFiles(src,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   562
                "package p2; public class C2 { public static p1.C1 provider = new p1.C1() {}; }");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   563
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   564
        output = new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   565
                .options("-XDrawDiagnostics")
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   566
                .outdir(Files.createDirectories(base.resolve("classes")))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   567
                .files(findJavaFiles(src))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   568
                .run(Task.Expect.FAIL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   569
                .writeAll()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   570
                .getOutputLines(Task.OutputKind.DIRECT);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   571
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   572
        expected = Arrays.asList("module-info.java:1:46: compiler.err.service.implementation.must.be.subtype.of.service.interface",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   573
                                 "1 error");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   574
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   575
        if (!expected.equals(output)) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   576
            throw new Exception("Expected output not found. Output: " + output);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   577
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41942
diff changeset
   578
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   579
}