< prev index next >
test/tools/javac/modules/OpenModulesTest.java
Print this page
*** 59,76 ****
new OpenModulesTest().runTests();
}
@Test
public void testStrongModule(Path base) throws Exception {
! Path m1 = base.resolve("m1");
tb.writeJavaFiles(m1,
! "module m1 { exports api1; opens api2; }",
"package api1; public class Api1 {}",
"package api2; public class Api2 {}",
"package impl; public class Impl {}");
Path classes = base.resolve("classes");
! Path m1Classes = classes.resolve("m1");
tb.createDirectories(m1Classes);
String log = new JavacTask(tb)
.outdir(m1Classes)
.files(findJavaFiles(m1))
--- 59,76 ----
new OpenModulesTest().runTests();
}
@Test
public void testStrongModule(Path base) throws Exception {
! Path m1 = base.resolve("m1x");
tb.writeJavaFiles(m1,
! "module m1x { exports api1; opens api2; }",
"package api1; public class Api1 {}",
"package api2; public class Api2 {}",
"package impl; public class Impl {}");
Path classes = base.resolve("classes");
! Path m1Classes = classes.resolve("m1x");
tb.createDirectories(m1Classes);
String log = new JavacTask(tb)
.outdir(m1Classes)
.files(findJavaFiles(m1))
*** 85,112 ****
.options("--system", "none", "-bootclasspath", "")
.classes(m1Classes.resolve("module-info.class").toString())
.run()
.writeAll()
.getOutput(OutputKind.DIRECT)
! .replace(System.getProperty("line.separator"), "\n");
! String expected = "module m1 {\n" +
" requires java.base;\n" +
" exports api1;\n" +
" opens api2;\n" +
"}";
if (!decompiled.contains(expected)) {
throw new Exception("expected output not found: " + decompiled);
}
//compiling against a strong module read from binary:
! Path m2 = base.resolve("m2");
tb.writeJavaFiles(m2,
! "module m2 { requires m1; }",
"package test; public class Test { api1.Api1 a1; api2.Api2 a2; }");
! Path m2Classes = classes.resolve("m2");
tb.createDirectories(m2Classes);
List<String> log2 = new JavacTask(tb)
.options("--module-path", m1Classes.toString(),
"-XDrawDiagnostics")
--- 85,113 ----
.options("--system", "none", "-bootclasspath", "")
.classes(m1Classes.resolve("module-info.class").toString())
.run()
.writeAll()
.getOutput(OutputKind.DIRECT)
! .replace(System.getProperty("line.separator"), "\n")
! .replaceAll("@[^;]*;", ";");
! String expected = "module m1x {\n" +
" requires java.base;\n" +
" exports api1;\n" +
" opens api2;\n" +
"}";
if (!decompiled.contains(expected)) {
throw new Exception("expected output not found: " + decompiled);
}
//compiling against a strong module read from binary:
! Path m2 = base.resolve("m2x");
tb.writeJavaFiles(m2,
! "module m2x { requires m1x; }",
"package test; public class Test { api1.Api1 a1; api2.Api2 a2; }");
! Path m2Classes = classes.resolve("m2x");
tb.createDirectories(m2Classes);
List<String> log2 = new JavacTask(tb)
.options("--module-path", m1Classes.toString(),
"-XDrawDiagnostics")
*** 122,139 ****
throw new Exception("expected output not found: " + log2);
}
@Test
public void testOpenModule(Path base) throws Exception {
! Path m1 = base.resolve("m1");
tb.writeJavaFiles(m1,
! "open module m1 { exports api1; }",
"package api1; public class Api1 {}",
"package api2; public class Api2 {}",
"package impl; public class Impl {}");
Path classes = base.resolve("classes");
! Path m1Classes = classes.resolve("m1");
tb.createDirectories(m1Classes);
String log = new JavacTask(tb)
.outdir(m1Classes)
.files(findJavaFiles(m1))
--- 123,140 ----
throw new Exception("expected output not found: " + log2);
}
@Test
public void testOpenModule(Path base) throws Exception {
! Path m1 = base.resolve("m1x");
tb.writeJavaFiles(m1,
! "open module m1x { exports api1; }",
"package api1; public class Api1 {}",
"package api2; public class Api2 {}",
"package impl; public class Impl {}");
Path classes = base.resolve("classes");
! Path m1Classes = classes.resolve("m1x");
tb.createDirectories(m1Classes);
String log = new JavacTask(tb)
.outdir(m1Classes)
.files(findJavaFiles(m1))
*** 148,174 ****
.options("--system", "none", "-bootclasspath", "")
.classes(m1Classes.resolve("module-info.class").toString())
.run()
.writeAll()
.getOutput(OutputKind.DIRECT)
! .replace(System.getProperty("line.separator"), "\n");
! String expected = "open module m1 {\n" +
" requires java.base;\n" +
" exports api1;\n" +
"}";
if (!decompiled.contains(expected)) {
throw new Exception("expected output not found: " + decompiled);
}
//compiling against a ordinary module read from binary:
! Path m2 = base.resolve("m2");
tb.writeJavaFiles(m2,
! "module m2 { requires m1; }",
"package test; public class Test { api1.Api1 a1; api2.Api2 a2; }");
! Path m2Classes = classes.resolve("m2");
tb.createDirectories(m2Classes);
List<String> log2 = new JavacTask(tb)
.options("--module-path", m1Classes.toString(),
"-XDrawDiagnostics")
--- 149,176 ----
.options("--system", "none", "-bootclasspath", "")
.classes(m1Classes.resolve("module-info.class").toString())
.run()
.writeAll()
.getOutput(OutputKind.DIRECT)
! .replace(System.getProperty("line.separator"), "\n")
! .replaceAll("@[^;]*;", ";");
! String expected = "open module m1x {\n" +
" requires java.base;\n" +
" exports api1;\n" +
"}";
if (!decompiled.contains(expected)) {
throw new Exception("expected output not found: " + decompiled);
}
//compiling against a ordinary module read from binary:
! Path m2 = base.resolve("m2x");
tb.writeJavaFiles(m2,
! "module m2x { requires m1x; }",
"package test; public class Test { api1.Api1 a1; api2.Api2 a2; }");
! Path m2Classes = classes.resolve("m2x");
tb.createDirectories(m2Classes);
List<String> log2 = new JavacTask(tb)
.options("--module-path", m1Classes.toString(),
"-XDrawDiagnostics")
*** 184,227 ****
throw new Exception("expected output not found: " + log2);
}
@Test
public void testOpenModuleNoOpens(Path base) throws Exception {
! Path m1 = base.resolve("m1");
tb.writeJavaFiles(m1,
! "open module m1 { exports api1; opens api2; }",
"package api1; public class Api1 {}",
"package api2; public class Api2 {}",
"package impl; public class Impl {}");
Path classes = base.resolve("classes");
! Path m1Classes = classes.resolve("m1");
tb.createDirectories(m1Classes);
List<String> log = new JavacTask(tb)
.options("-XDrawDiagnostics")
.outdir(m1Classes)
.files(findJavaFiles(m1))
.run(Expect.FAIL)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
! List<String> expected = Arrays.asList("module-info.java:1:32: compiler.err.no.opens.unless.strong",
"1 error");
if (!expected.equals(log))
throw new Exception("expected output not found: " + log);
}
@Test
public void testNonZeroOpensInOpen(Path base) throws Exception {
! Path m1 = base.resolve("m1");
tb.writeJavaFiles(m1,
! "module m1 { opens api; }",
"package api; public class Api {}");
Path classes = base.resolve("classes");
! Path m1Classes = classes.resolve("m1");
tb.createDirectories(m1Classes);
new JavacTask(tb)
.options("-XDrawDiagnostics")
.outdir(m1Classes)
--- 186,229 ----
throw new Exception("expected output not found: " + log2);
}
@Test
public void testOpenModuleNoOpens(Path base) throws Exception {
! Path m1 = base.resolve("m1x");
tb.writeJavaFiles(m1,
! "open module m1x { exports api1; opens api2; }",
"package api1; public class Api1 {}",
"package api2; public class Api2 {}",
"package impl; public class Impl {}");
Path classes = base.resolve("classes");
! Path m1Classes = classes.resolve("m1x");
tb.createDirectories(m1Classes);
List<String> log = new JavacTask(tb)
.options("-XDrawDiagnostics")
.outdir(m1Classes)
.files(findJavaFiles(m1))
.run(Expect.FAIL)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
! List<String> expected = Arrays.asList("module-info.java:1:33: compiler.err.no.opens.unless.strong",
"1 error");
if (!expected.equals(log))
throw new Exception("expected output not found: " + log);
}
@Test
public void testNonZeroOpensInOpen(Path base) throws Exception {
! Path m1 = base.resolve("m1x");
tb.writeJavaFiles(m1,
! "module m1x { opens api; }",
"package api; public class Api {}");
Path classes = base.resolve("classes");
! Path m1Classes = classes.resolve("m1x");
tb.createDirectories(m1Classes);
new JavacTask(tb)
.options("-XDrawDiagnostics")
.outdir(m1Classes)
*** 233,242 ****
--- 235,245 ----
ClassFile cf = ClassFile.read(miClass);
Module_attribute module = (Module_attribute) cf.attributes.map.get(Attribute.Module);
Module_attribute newModule = new Module_attribute(module.attribute_name_index,
module.module_name,
module.module_flags | Module_attribute.ACC_OPEN,
+ module.module_version_index,
module.requires,
module.exports,
module.opens,
module.uses_index,
module.provides);
*** 268,285 ****
tb.createDirectories(testClasses);
List<String> log = new JavacTask(tb)
.options("-XDrawDiagnostics",
"--module-path", classes.toString(),
! "--add-modules", "m1")
.outdir(testClasses)
.files(findJavaFiles(test))
.run(Expect.FAIL)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
! List<String> expected = Arrays.asList("- compiler.err.cant.access: m1.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.module.non.zero.opens: m1))",
"1 error");
if (!expected.equals(log))
throw new Exception("expected output not found: " + log);
}
--- 271,291 ----
tb.createDirectories(testClasses);
List<String> log = new JavacTask(tb)
.options("-XDrawDiagnostics",
"--module-path", classes.toString(),
! "--add-modules", "m1x")
.outdir(testClasses)
.files(findJavaFiles(test))
.run(Expect.FAIL)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
! List<String> expected = Arrays.asList(
! "- compiler.err.cant.access: m1x.module-info, "
! + "(compiler.misc.bad.class.file.header: module-info.class, "
! + "(compiler.misc.module.non.zero.opens: m1x))",
"1 error");
if (!expected.equals(log))
throw new Exception("expected output not found: " + log);
}
< prev index next >