38
import java.nio.file.Files;
39
import java.nio.file.Path;
40
import java.util.Arrays;
43
import toolbox.JavacTask;
45
import toolbox.Task.Expect;
47
public class MissingModuleTest extends ModuleTestBase {
49
public static void main(String... args) throws Exception {
50
new MissingModuleTest().runTests();
54
public void testMissingNotNeeded(Path base) throws Exception {
55
doTest(base, "m1x", new String[0]);
59
public void testMissingNeededTransitive(Path base) throws Exception {
60
doTest(base, "m2x", "- compiler.err.module.not.found: m2x", "1 error");
64
public void testMissingNeededDirect(Path base) throws Exception {
65
doTest(base, "m3x", "module-info.java:1:24: compiler.err.module.not.found: m3x", "1 error");
69
public void testMultipleErrors(Path base) throws Exception {
70
doTest(base, "m4x", "module-info.java:1:38: compiler.err.module.not.found: m4x", "1 error");
73
private void doTest(Path base, String toDelete, String... errors) throws Exception {
75
Path srcMP = base.resolve("src-mp");
76
Path m1x = srcMP.resolve("m1x");
77
tb.writeJavaFiles(m1x,
78
"module m1x { exports api1; }",
79
"package api1; public interface Api { }");
80
Path m2x = srcMP.resolve("m2x");
81
tb.writeJavaFiles(m2x,
82
"module m2x { requires m1x; exports api2; }",
83
"package api2; public interface Api { }");
84
Path m3x = srcMP.resolve("m3x");
85
tb.writeJavaFiles(m3x,
86
"module m3x { requires transitive m2x; }");
87
Path m4x = srcMP.resolve("m4x");
88
tb.writeJavaFiles(m4x,
89
"module m4x { requires transitive m2x; }");
90
Path m5x = srcMP.resolve("m5x");
91
tb.writeJavaFiles(m5x,
92
"module m5x { requires transitive m4x; }");
93
Path classesMP = base.resolve("classes-mp");
94
tb.createDirectories(classesMP);
97
.options("--module-source-path", srcMP.toString())
99
.files(findJavaFiles(srcMP))
103
tb.cleanDirectory(classesMP.resolve(toDelete));
104
Files.delete(classesMP.resolve(toDelete));
106
Path src = base.resolve("src");
107
tb.writeJavaFiles(src,
108
"module test { requires m3x; requires m4x; requires m5x; } ");
109
Path classes = base.resolve("classes");
110
tb.createDirectories(classes);
112
List<String> log = new JavacTask(tb)
113
.options("--module-path", classesMP.toString(),
116
.files(findJavaFiles(src))
117
.run(errors.length > 0 ? Expect.FAIL : Expect.SUCCESS)
119
.getOutputLines(Task.OutputKind.DIRECT);
121
if (errors.length == 0) {
122
errors = new String[] {""};
125
if (!log.equals(Arrays.asList(errors)))
126
throw new Exception("expected output not found: " + log);