langtools/test/tools/javac/modules/LegacyXModuleTest.java
changeset 45685 95526afc4e20
parent 45684 2c5f2779c3d1
child 45686 a423824381ae
equal deleted inserted replaced
45684:2c5f2779c3d1 45685:95526afc4e20
     1 /*
       
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 8178012
       
    27  * @summary tests for multi-module mode compilation
       
    28  * @library /tools/lib
       
    29  * @modules
       
    30  *      jdk.compiler/com.sun.tools.javac.api
       
    31  *      jdk.compiler/com.sun.tools.javac.main
       
    32  * @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder ModuleTestBase
       
    33  * @run main LegacyXModuleTest
       
    34  */
       
    35 
       
    36 import java.nio.file.Path;
       
    37 import java.util.Arrays;
       
    38 import java.util.List;
       
    39 import java.util.Objects;
       
    40 
       
    41 import toolbox.JavacTask;
       
    42 import toolbox.Task;
       
    43 
       
    44 public class LegacyXModuleTest extends ModuleTestBase {
       
    45 
       
    46     public static void main(String... args) throws Exception {
       
    47         new LegacyXModuleTest().runTests();
       
    48     }
       
    49 
       
    50     @Test
       
    51     public void testLegacyXModule(Path base) throws Exception {
       
    52         //note: avoiding use of java.base, as that gets special handling on some places:
       
    53         Path src = base.resolve("src");
       
    54         tb.writeJavaFiles(src, "package com.sun.tools.javac.comp; public class Extra { Modules modules; }");
       
    55         Path classes = base.resolve("classes");
       
    56         tb.createDirectories(classes);
       
    57 
       
    58         new JavacTask(tb)
       
    59             .options("-XD-Xmodule:jdk.compiler")
       
    60             .outdir(classes)
       
    61             .files(findJavaFiles(src))
       
    62             .run()
       
    63             .writeAll()
       
    64             .getOutput(Task.OutputKind.DIRECT);
       
    65 
       
    66         List<String> log = new JavacTask(tb)
       
    67                 .options("-XD-Xmodule:java.compiler",
       
    68                          "-XD-Xmodule:jdk.compiler",
       
    69                          "-XDrawDiagnostics")
       
    70                 .outdir(classes)
       
    71                 .files(findJavaFiles(src))
       
    72                 .run(Task.Expect.FAIL)
       
    73                 .writeAll()
       
    74                 .getOutputLines(Task.OutputKind.DIRECT);
       
    75 
       
    76         List<String> actual =
       
    77                 Arrays.asList("Extra.java:1:56: compiler.err.cant.resolve.location: kindname.class, Modules, , , " +
       
    78                                                 "(compiler.misc.location: kindname.class, com.sun.tools.javac.comp.Extra, null)",
       
    79                               "1 error");
       
    80 
       
    81         if (!Objects.equals(actual, log))
       
    82             throw new Exception("expected output not found: " + log);
       
    83     }
       
    84 
       
    85 }