langtools/test/tools/javac/modules/XModuleTest.java
author jjg
Fri, 17 Jun 2016 17:40:01 -0700
changeset 39103 91a64ec5b970
parent 37758 3ecf9b414e05
child 40308 274367a99f98
permissions -rw-r--r--
8159749: Update toolbox ModuleBuilder for doc comments Reviewed-by: ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary tests for multi-module mode compilation
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @library /tools/lib
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @modules
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 *      jdk.compiler/com.sun.tools.javac.api
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 *      jdk.compiler/com.sun.tools.javac.main
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    31
 * @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @run main XModuleTest
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    39
import toolbox.JavacTask;
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    40
import toolbox.ModuleBuilder;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    41
import toolbox.Task;
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    42
import toolbox.TestRunner;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    43
import toolbox.ToolBox;
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 XModuleTest extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
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
        new XModuleTest().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 testCorrectXModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
        //note: avoiding use of java.base, as that gets special handling on some places:
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, "package javax.lang.model.element; public interface Extra extends Element { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    59
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
                .options("-Xmodule:java.compiler")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    65
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    72
    public void testSourcePath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, Other { }", "package javax.lang.model.element; interface Other { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    79
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
                .options("-Xmodule:java.compiler", "-sourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
                .files(src.resolve("javax/lang/model/element/Extra.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    85
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    92
    public void testClassPath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        Path cpSrc = base.resolve("cpSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        tb.writeJavaFiles(cpSrc, "package p; public interface Other { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        Path cpClasses = base.resolve("cpClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        tb.createDirectories(cpClasses);
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 cpLog = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
                .outdir(cpClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
                .files(findJavaFiles(cpSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   103
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        if (!cpLog.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
            throw new Exception("expected output not found: " + cpLog);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, p.Other { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   114
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                .options("-Xmodule:java.compiler", "-classpath", cpClasses.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                .files(src.resolve("javax/lang/model/element/Extra.java"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   120
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   127
    public void testNoModuleInfoOnSourcePath(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
                          "module java.compiler {}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                          "package javax.lang.model.element; public interface Extra { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   136
        List<String> log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                .options("-XDrawDiagnostics", "-Xmodule:java.compiler")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   140
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   142
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        List<String> expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.sourcepath",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
                                              "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   152
    public void testNoModuleInfoInClassOutput(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
        Path srcMod = base.resolve("src-mod");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        tb.writeJavaFiles(srcMod,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                          "module mod {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   160
        String logMod = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                .options()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
                .files(findJavaFiles(srcMod))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   166
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        if (!logMod.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
            throw new Exception("unexpected output found: " + logMod);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                          "package javax.lang.model.element; public interface Extra { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   176
        List<String> log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                .options("-XDrawDiagnostics", "-Xmodule:java.compiler")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   180
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   182
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
        List<String> expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.classpath",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
                                              "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   192
    public void testModuleSourcePathXModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
        tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   199
        List<String> log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
                .options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-modulesourcepath", src.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   203
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   205
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        List<String> expected = Arrays.asList("- compiler.err.xmodule.no.module.sourcepath",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
                                              "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
            throw new Exception("expected output not found: " + log);
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 testXModuleTooMany(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        //note: avoiding use of java.base, as that gets special handling on some places:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
        tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        tb.createDirectories(classes);
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> log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                .options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-Xmodule:java.compiler")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
                .outdir(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
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        List<String> expected = Arrays.asList("javac: option -Xmodule: can only be specified once",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                                              "Usage: javac <options> <source files>",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                                              "use -help for a list of possible options");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   239
    public void testWithModulePath(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   240
        Path modSrc = base.resolve("modSrc");
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   241
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   242
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                .classes("package pkg1; public interface E { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   244
                .build(modSrc, modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
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, "package p; interface A extends pkg1.E { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   249
        new JavacTask(tb, Task.Mode.CMDLINE)
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   250
                .options("-modulepath", modules.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
                        "-Xmodule:m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
        //checks module bounds still exist
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   257
        new ModuleBuilder(tb, "m2")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
                .classes("package pkg2; public interface D { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   259
                .build(modSrc, modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
        Path src2 = base.resolve("src2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
        tb.writeJavaFiles(src2, "package p; interface A extends pkg2.D { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   264
        List<String> log = new JavacTask(tb, Task.Mode.CMDLINE)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
                .options("-XDrawDiagnostics",
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   266
                        "-modulepath", modules.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                        "-Xmodule:m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                .files(findJavaFiles(src2))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   269
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   271
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
        List<String> expected = Arrays.asList("A.java:1:36: compiler.err.doesnt.exist: pkg2",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                "1 error");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   281
    public void testWithUpgradeModulePath(Path base) throws Exception {
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   282
        Path modSrc = base.resolve("modSrc");
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   283
        Path modules = base.resolve("modules");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   284
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
                .classes("package pkg1; public interface E { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   286
                .build(modSrc, modules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   288
        Path upgrSrc = base.resolve("upgradeSrc");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        Path upgrade = base.resolve("upgrade");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   290
        new ModuleBuilder(tb, "m1")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
                .classes("package pkg1; public interface D { }")
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   292
                .build(upgrSrc, upgrade);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
        tb.writeJavaFiles(src, "package p; interface A extends pkg1.D { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   297
        new JavacTask(tb, Task.Mode.CMDLINE)
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   298
                .options("-modulepath", modules.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
                        "-upgrademodulepath", upgrade.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
                        "-Xmodule:m1")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   303
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
}