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 8165102 8175560
27 * @summary incorrect message from javac
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 ModuleTestBase
33 * @run main ModulesAndModuleSourcePathTest
34 */
35
36import java.nio.file.Files;
37import java.nio.file.Path;
38
39import toolbox.JavacTask;
40import toolbox.Task;
41import toolbox.ToolBox;
42
43public class ModulesAndModuleSourcePathTest extends ModuleTestBase {
44    public static void main(String... args) throws Exception {
45        ModulesAndModuleSourcePathTest t = new ModulesAndModuleSourcePathTest();
46        t.runTests();
47    }
48
49    @Test
50    public void testModuleNotInModuleSrcPath(Path base) throws Exception {
51        Path src = base.resolve("src");
52        Path m = src.resolve("m");
53        Files.createDirectories(m);
54        Path extra = base.resolve("m");
55        tb.writeJavaFiles(extra, "module m {}");
56        Path classes = base.resolve("classes");
57        Files.createDirectories(classes);
58
59        String log = new JavacTask(tb)
60                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
61                .outdir(classes)
62                .files(findJavaFiles(extra))
63                .run(Task.Expect.FAIL)
64                .writeAll()
65                .getOutput(Task.OutputKind.DIRECT);
66        if (!log.contains("module-info.java:1:1: compiler.err.module.not.found.on.module.source.path"))
67            throw new Exception("expected output not found");
68    }
69
70    @Test
71    public void testModuleNotInPackageHierarchy(Path base) throws Exception {
72        Path src = base.resolve("src");
73        Path m = src.resolve("m");
74        Path extra = m.resolve("extra");
75        tb.writeJavaFiles(extra, "module m {}");
76        Path classes = base.resolve("classes");
77        Files.createDirectories(classes);
78
79        String log = new JavacTask(tb)
80                .options("-XDrawDiagnostics", "--module-source-path", src.toString())
81                .outdir(classes)
82                .files(findJavaFiles(src))
83                .run(Task.Expect.FAIL)
84                .writeAll()
85                .getOutput(Task.OutputKind.DIRECT);
86        if (!log.contains("module-info.java:1:1: compiler.err.module.not.found.on.module.source.path"))
87            throw new Exception("expected output not found");
88    }
89}
90