< prev index next >

langtools/test/tools/javac/modules/RequiresPublicTest.java

Print this page




  63                 .outdir(classes)
  64                 .run()
  65                 .writeAll();
  66     }
  67 
  68     @Test
  69     public void testJavaSE_Fail(Path base) throws Exception {
  70         Path src = base.resolve("src");
  71         tb.writeJavaFiles(src,
  72                 "module m { requires java.se; }",
  73                 "import com.sun.source.tree.Tree;\n" // not in java.se (in jdk.compiler)
  74                 + "class Test {\n"
  75                 + "    Tree t;\n"
  76                 + "}");
  77         Path classes = base.resolve("classes");
  78         Files.createDirectories(classes);
  79 
  80         String log = new JavacTask(tb, Task.Mode.CMDLINE)
  81                 .options("-XDrawDiagnostics")
  82                 .files(findJavaFiles(src))
  83                 .outdir(classes.toString()) // should allow Path here
  84                 .run(Task.Expect.FAIL)
  85                 .writeAll()
  86                 .getOutput(Task.OutputKind.DIRECT);
  87 
  88         if (!log.contains("Test.java:1:27: compiler.err.doesnt.exist: com.sun.source.tree"))
  89             throw new Exception("expected output not found");
  90     }
  91 
  92     @Test
  93     public void testComplex_OK(Path base) throws Exception {
  94         Path src = getComplexSrc(base, "", "");
  95         Path classes = base.resolve("classes");
  96         Files.createDirectories(classes);
  97 
  98         new JavacTask(tb, Task.Mode.CMDLINE)
  99                 .options("-modulesourcepath", src.toString())
 100                 .files(findJavaFiles(src))
 101                 .outdir(classes)
 102                 .run()
 103                 .writeAll();
 104     }
 105 
 106     @Test
 107     public void testComplex_Fail(Path base) throws Exception {
 108         Path src = getComplexSrc(base,
 109                 "import p5.C5; import p6.C6; import p7.C7;\n",
 110                 "C5 c5; C6 c6; C7 c7;\n");
 111         Path classes = base.resolve("classes");
 112         Files.createDirectories(classes);
 113 
 114         String log = new JavacTask(tb, Task.Mode.CMDLINE)
 115                 .options("-XDrawDiagnostics",
 116                         "-modulesourcepath", src.toString())
 117                 .files(findJavaFiles(src))
 118                 .outdir(classes)
 119                 .run(Task.Expect.FAIL)
 120                 .writeAll()
 121                 .getOutput(Task.OutputKind.DIRECT);
 122 
 123         String[] expect = {
 124             "C1.java:5:10: compiler.err.not.def.access.package.cant.access: p5.C5, p5",
 125             "C1.java:5:24: compiler.err.not.def.access.package.cant.access: p6.C6, p6",
 126             "C1.java:5:38: compiler.err.not.def.access.package.cant.access: p7.C7, p7",
 127             "C1.java:8:1: compiler.err.cant.resolve.location: kindname.class, C5, , , "
 128                 + "(compiler.misc.location: kindname.class, p1.C1, null)",
 129             "C1.java:8:8: compiler.err.cant.resolve.location: kindname.class, C6, , , "
 130                 + "(compiler.misc.location: kindname.class, p1.C1, null)",
 131             "C1.java:8:15: compiler.err.cant.resolve.location: kindname.class, C7, , , "
 132                 + "(compiler.misc.location: kindname.class, p1.C1, null)"
 133         };
 134 
 135         for (String e: expect) {
 136             if (!log.contains(e))




  63                 .outdir(classes)
  64                 .run()
  65                 .writeAll();
  66     }
  67 
  68     @Test
  69     public void testJavaSE_Fail(Path base) throws Exception {
  70         Path src = base.resolve("src");
  71         tb.writeJavaFiles(src,
  72                 "module m { requires java.se; }",
  73                 "import com.sun.source.tree.Tree;\n" // not in java.se (in jdk.compiler)
  74                 + "class Test {\n"
  75                 + "    Tree t;\n"
  76                 + "}");
  77         Path classes = base.resolve("classes");
  78         Files.createDirectories(classes);
  79 
  80         String log = new JavacTask(tb, Task.Mode.CMDLINE)
  81                 .options("-XDrawDiagnostics")
  82                 .files(findJavaFiles(src))
  83                 .outdir(classes)
  84                 .run(Task.Expect.FAIL)
  85                 .writeAll()
  86                 .getOutput(Task.OutputKind.DIRECT);
  87 
  88         if (!log.contains("Test.java:1:27: compiler.err.doesnt.exist: com.sun.source.tree"))
  89             throw new Exception("expected output not found");
  90     }
  91 
  92     @Test
  93     public void testComplex_OK(Path base) throws Exception {
  94         Path src = getComplexSrc(base, "", "");
  95         Path classes = base.resolve("classes");
  96         Files.createDirectories(classes);
  97 
  98         new JavacTask(tb, Task.Mode.CMDLINE)
  99                 .options("--module-source-path", src.toString())
 100                 .files(findJavaFiles(src))
 101                 .outdir(classes)
 102                 .run()
 103                 .writeAll();
 104     }
 105 
 106     @Test
 107     public void testComplex_Fail(Path base) throws Exception {
 108         Path src = getComplexSrc(base,
 109                 "import p5.C5; import p6.C6; import p7.C7;\n",
 110                 "C5 c5; C6 c6; C7 c7;\n");
 111         Path classes = base.resolve("classes");
 112         Files.createDirectories(classes);
 113 
 114         String log = new JavacTask(tb, Task.Mode.CMDLINE)
 115                 .options("-XDrawDiagnostics",
 116                         "--module-source-path", src.toString())
 117                 .files(findJavaFiles(src))
 118                 .outdir(classes)
 119                 .run(Task.Expect.FAIL)
 120                 .writeAll()
 121                 .getOutput(Task.OutputKind.DIRECT);
 122 
 123         String[] expect = {
 124             "C1.java:5:10: compiler.err.not.def.access.package.cant.access: p5.C5, p5",
 125             "C1.java:5:24: compiler.err.not.def.access.package.cant.access: p6.C6, p6",
 126             "C1.java:5:38: compiler.err.not.def.access.package.cant.access: p7.C7, p7",
 127             "C1.java:8:1: compiler.err.cant.resolve.location: kindname.class, C5, , , "
 128                 + "(compiler.misc.location: kindname.class, p1.C1, null)",
 129             "C1.java:8:8: compiler.err.cant.resolve.location: kindname.class, C6, , , "
 130                 + "(compiler.misc.location: kindname.class, p1.C1, null)",
 131             "C1.java:8:15: compiler.err.cant.resolve.location: kindname.class, C7, , , "
 132                 + "(compiler.misc.location: kindname.class, p1.C1, null)"
 133         };
 134 
 135         for (String e: expect) {
 136             if (!log.contains(e))


< prev index next >