< prev index next >

langtools/test/tools/javac/platform/PlatformProviderTest.java

Print this page




  80     void run() throws IOException {
  81         Path registration = Paths.get(System.getProperty("test.classes"),
  82                                       "META-INF",
  83                                       "services",
  84                                       "com.sun.tools.javac.platform.PlatformProvider");
  85         Files.createDirectories(registration.getParent());
  86         try (Writer metaInf = Files.newBufferedWriter(registration)) {
  87             metaInf.write(PlatformProviderTest.class.getName());
  88         }
  89 
  90         doTest("name", "");
  91         doTest("name:param", "param");
  92         doTestFailure();
  93     }
  94 
  95     void doTest(String platformSpec, String expectedParameter) {
  96         ToolBox tb = new ToolBox();
  97         Task.Result result =
  98                 new JavacTask(tb, Task.Mode.EXEC)
  99                   .outdir(".")
 100                   .options("-J-classpath",
 101                            "-J" + System.getProperty("test.classes"),
 102                            "-J-XaddExports:jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED",
 103                            "-J-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
 104                            "-XDrawDiagnostics",
 105                            "-release",
 106                            platformSpec,
 107                            System.getProperty("test.src") + "/PlatformProviderTestSource.java")
 108                   .run();
 109 
 110         List<String> expectedOutput =
 111                 Arrays.asList("getSupportedPlatformNames",
 112                               "getPlatform(name, " + expectedParameter + ")",
 113                               "getSourceVersion",
 114                               "getTargetVersion",
 115                               "getPlatformPath",
 116                               "testPlugin: [testPluginKey=testPluginValue]",
 117                               "process: {testAPKey=testAPValue}",
 118                               "process: {testAPKey=testAPValue}",
 119                               "PlatformProviderTestSource.java:4:49: compiler.warn.raw.class.use: java.util.ArrayList, java.util.ArrayList<E>",
 120                               "compiler.misc.count.warn",
 121                               "close");
 122         List<String> actualOutput = result.getOutputLines(Task.OutputKind.STDERR);
 123         result.writeAll();
 124         if (!expectedOutput.equals(actualOutput)) {
 125             throw new AssertionError(  "Expected output: " + expectedOutput +
 126                                      "; actual output: " + actualOutput);
 127         }
 128         result.writeAll();
 129     }
 130 
 131     void doTestFailure() {
 132         ToolBox tb = new ToolBox();
 133         Task.Result result =
 134                 new JavacTask(tb, Task.Mode.EXEC)
 135                   .outdir(".")
 136                   .options("-J-classpath",
 137                            "-J" + System.getProperty("test.classes"),
 138                            "-J-XaddExports:jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED",
 139                            "-J-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
 140                            "-release",
 141                            "fail",
 142                            System.getProperty("test.src") + "/PlatformProviderTestSource.java")
 143                   .run(Task.Expect.FAIL);
 144 
 145         List<String> expectedOutput =
 146                 Arrays.asList("getSupportedPlatformNames",
 147                               "getPlatform(fail, )",
 148                               "javac: javac.err.unsupported.release.version",
 149                               "javac.msg.usage");
 150         List<String> actualOutput = result.getOutputLines(Task.OutputKind.STDERR);
 151         result.writeAll();
 152         if (!expectedOutput.equals(actualOutput)) {
 153             throw new AssertionError(  "Expected output: " + expectedOutput +
 154                                      "; actual output: " + actualOutput);
 155         }
 156         result.writeAll();
 157     }
 158 
 159     @Override




  80     void run() throws IOException {
  81         Path registration = Paths.get(System.getProperty("test.classes"),
  82                                       "META-INF",
  83                                       "services",
  84                                       "com.sun.tools.javac.platform.PlatformProvider");
  85         Files.createDirectories(registration.getParent());
  86         try (Writer metaInf = Files.newBufferedWriter(registration)) {
  87             metaInf.write(PlatformProviderTest.class.getName());
  88         }
  89 
  90         doTest("name", "");
  91         doTest("name:param", "param");
  92         doTestFailure();
  93     }
  94 
  95     void doTest(String platformSpec, String expectedParameter) {
  96         ToolBox tb = new ToolBox();
  97         Task.Result result =
  98                 new JavacTask(tb, Task.Mode.EXEC)
  99                   .outdir(".")
 100                   .options("-J--class-path=" + System.getProperty("test.classes"),
 101                            "-J--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED",
 102                            "-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",

 103                            "-XDrawDiagnostics",
 104                            "-release",
 105                            platformSpec,
 106                            System.getProperty("test.src") + "/PlatformProviderTestSource.java")
 107                   .run();
 108 
 109         List<String> expectedOutput =
 110                 Arrays.asList("getSupportedPlatformNames",
 111                               "getPlatform(name, " + expectedParameter + ")",
 112                               "getSourceVersion",
 113                               "getTargetVersion",
 114                               "getPlatformPath",
 115                               "testPlugin: [testPluginKey=testPluginValue]",
 116                               "process: {testAPKey=testAPValue}",
 117                               "process: {testAPKey=testAPValue}",
 118                               "PlatformProviderTestSource.java:4:49: compiler.warn.raw.class.use: java.util.ArrayList, java.util.ArrayList<E>",
 119                               "compiler.misc.count.warn",
 120                               "close");
 121         List<String> actualOutput = result.getOutputLines(Task.OutputKind.STDERR);
 122         result.writeAll();
 123         if (!expectedOutput.equals(actualOutput)) {
 124             throw new AssertionError(  "Expected output: " + expectedOutput +
 125                                      "; actual output: " + actualOutput);
 126         }
 127         result.writeAll();
 128     }
 129 
 130     void doTestFailure() {
 131         ToolBox tb = new ToolBox();
 132         Task.Result result =
 133                 new JavacTask(tb, Task.Mode.EXEC)
 134                   .outdir(".")
 135                   .options("-J--class-path=" + System.getProperty("test.classes"),
 136                            "-J--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED",
 137                            "-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",

 138                            "-release",
 139                            "fail",
 140                            System.getProperty("test.src") + "/PlatformProviderTestSource.java")
 141                   .run(Task.Expect.FAIL);
 142 
 143         List<String> expectedOutput =
 144                 Arrays.asList("getSupportedPlatformNames",
 145                               "getPlatform(fail, )",
 146                               "javac: javac.err.unsupported.release.version",
 147                               "javac.msg.usage");
 148         List<String> actualOutput = result.getOutputLines(Task.OutputKind.STDERR);
 149         result.writeAll();
 150         if (!expectedOutput.equals(actualOutput)) {
 151             throw new AssertionError(  "Expected output: " + expectedOutput +
 152                                      "; actual output: " + actualOutput);
 153         }
 154         result.writeAll();
 155     }
 156 
 157     @Override


< prev index next >