ModulesAndModuleSourcePathTest.java revision 4025:b552cece1f4a
1203945Sweongyo/*
2203945Sweongyo * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3203945Sweongyo * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4203945Sweongyo *
5203945Sweongyo * This code is free software; you can redistribute it and/or modify it
6203945Sweongyo * under the terms of the GNU General Public License version 2 only, as
7203945Sweongyo * published by the Free Software Foundation.
8203945Sweongyo *
9203945Sweongyo * This code is distributed in the hope that it will be useful, but WITHOUT
10203945Sweongyo * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11203945Sweongyo * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12203945Sweongyo * version 2 for more details (a copy is included in the LICENSE file that
13203945Sweongyo * accompanied this code).
14203945Sweongyo *
15203945Sweongyo * You should have received a copy of the GNU General Public License version
16203945Sweongyo * 2 along with this work; if not, write to the Free Software Foundation,
17203945Sweongyo * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18203945Sweongyo *
19203945Sweongyo * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20203945Sweongyo * or visit www.oracle.com if you need additional information or have any
21203945Sweongyo * questions.
22203945Sweongyo */
23203945Sweongyo
24203945Sweongyo/**
25203945Sweongyo * @test
26203945Sweongyo * @bug 8165102 8175560
27203945Sweongyo * @summary incorrect message from javac
28203945Sweongyo * @library /tools/lib
29203945Sweongyo * @modules
30203945Sweongyo *      jdk.compiler/com.sun.tools.javac.api
31203945Sweongyo *      jdk.compiler/com.sun.tools.javac.main
32203945Sweongyo * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
33203945Sweongyo * @run main ModulesAndModuleSourcePathTest
34203945Sweongyo */
35203945Sweongyo
36203945Sweongyoimport java.nio.file.Files;
37203945Sweongyoimport java.nio.file.Path;
38203945Sweongyo
39203945Sweongyoimport toolbox.JavacTask;
40203945Sweongyoimport toolbox.Task;
41203945Sweongyoimport toolbox.ToolBox;
42203945Sweongyo
43203945Sweongyopublic class ModulesAndModuleSourcePathTest extends ModuleTestBase {
44203945Sweongyo    public static void main(String... args) throws Exception {
45203945Sweongyo        ModulesAndModuleSourcePathTest t = new ModulesAndModuleSourcePathTest();
46203945Sweongyo        t.runTests();
47203945Sweongyo    }
48203945Sweongyo
49203945Sweongyo    @Test
50203945Sweongyo    public void testModuleNotInModuleSrcPath(Path base) throws Exception {
51203945Sweongyo        Path src = base.resolve("src");
52203945Sweongyo        Path m = src.resolve("m");
53203945Sweongyo        Files.createDirectories(m);
54203945Sweongyo        Path extra = base.resolve("m");
55203945Sweongyo        tb.writeJavaFiles(extra, "module m {}");
56203945Sweongyo        Path classes = base.resolve("classes");
57203945Sweongyo        Files.createDirectories(classes);
58203945Sweongyo
59203945Sweongyo        String log = new JavacTask(tb)
60203945Sweongyo                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
61203945Sweongyo                .outdir(classes)
62203945Sweongyo                .files(findJavaFiles(extra))
63203945Sweongyo                .run(Task.Expect.FAIL)
64203945Sweongyo                .writeAll()
65203945Sweongyo                .getOutput(Task.OutputKind.DIRECT);
66203945Sweongyo        if (!log.contains("module-info.java:1:1: compiler.err.module.not.found.on.module.source.path"))
67203945Sweongyo            throw new Exception("expected output not found");
68203945Sweongyo    }
69203945Sweongyo
70203945Sweongyo    @Test
71203945Sweongyo    public void testModuleNotInPackageHierarchy(Path base) throws Exception {
72203945Sweongyo        Path src = base.resolve("src");
73203945Sweongyo        Path m = src.resolve("m");
74203945Sweongyo        Path extra = m.resolve("extra");
75203945Sweongyo        tb.writeJavaFiles(extra, "module m {}");
76203945Sweongyo        Path classes = base.resolve("classes");
77203945Sweongyo        Files.createDirectories(classes);
78203945Sweongyo
79203945Sweongyo        String log = new JavacTask(tb)
80203945Sweongyo                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
81203945Sweongyo                .outdir(classes)
82203945Sweongyo                .files(findJavaFiles(src))
83203945Sweongyo                .run(Task.Expect.FAIL)
84203945Sweongyo                .writeAll()
85203945Sweongyo                .getOutput(Task.OutputKind.DIRECT);
86203945Sweongyo        if (!log.contains("module-info.java:1:1: compiler.err.module.not.found.on.module.source.path"))
87203945Sweongyo            throw new Exception("expected output not found");
88203945Sweongyo    }
89203945Sweongyo}
90203945Sweongyo