< prev index next >

test/langtools/tools/javac/launcher/SourceLauncherTest.java

Print this page

 653             "    void deprecation() {\n" +
 654             "        Thread.currentThread().stop();\n" +
 655             "    }\n" +
 656             "    void preview(Object o) {\n" +
 657             "      if (o instanceof String s) {\n" +
 658             "          System.out.println(s);\n" +
 659             "      }\n" +
 660             "    }\n" +
 661             "}");
 662         Result r = run(base.resolve("NoRecompile.java"), Collections.emptyList(), Collections.emptyList());
 663         if (r.stdErr.contains("recompile with")) {
 664             error("Unexpected recompile suggestions in error output: " + r.stdErr);
 665         }
 666     }
 667 
 668     @Test
 669     public void testNoOptionsWarnings(Path base) throws IOException {
 670         tb.writeJavaFiles(base, "public class Main { public static void main(String... args) {}}");
 671         String log = new JavaTask(tb)
 672                 .vmOptions("--source", "21")

 673                 .className(base.resolve("Main.java").toString())
 674                 .run(Task.Expect.SUCCESS)
 675                 .getOutput(Task.OutputKind.STDERR);
 676 
 677         if (log.contains("warning: [options]")) {
 678             error("Unexpected options warning in error output: " + log);
 679         }
 680     }
 681 
 682     void testError(Path file, String expectStdErr, String expectFault) throws IOException {
 683         Result r = run(file, Collections.emptyList(), List.of("1", "2", "3"));
 684         checkEmpty("stdout", r.stdOut);
 685         checkEqual("stderr", r.stdErr, expectStdErr);
 686         checkFault("exception", r.exception, expectFault);
 687     }
 688 
 689     /*
 690      * Tests in which main throws an exception.
 691      */
 692     @Test

 653             "    void deprecation() {\n" +
 654             "        Thread.currentThread().stop();\n" +
 655             "    }\n" +
 656             "    void preview(Object o) {\n" +
 657             "      if (o instanceof String s) {\n" +
 658             "          System.out.println(s);\n" +
 659             "      }\n" +
 660             "    }\n" +
 661             "}");
 662         Result r = run(base.resolve("NoRecompile.java"), Collections.emptyList(), Collections.emptyList());
 663         if (r.stdErr.contains("recompile with")) {
 664             error("Unexpected recompile suggestions in error output: " + r.stdErr);
 665         }
 666     }
 667 
 668     @Test
 669     public void testNoOptionsWarnings(Path base) throws IOException {
 670         tb.writeJavaFiles(base, "public class Main { public static void main(String... args) {}}");
 671         String log = new JavaTask(tb)
 672                 .vmOptions("--source", "21")
 673                 .includeStandardOptions(false) // Do not inherit --enable-preview
 674                 .className(base.resolve("Main.java").toString())
 675                 .run(Task.Expect.SUCCESS)
 676                 .getOutput(Task.OutputKind.STDERR);
 677 
 678         if (log.contains("warning: [options]")) {
 679             error("Unexpected options warning in error output: " + log);
 680         }
 681     }
 682 
 683     void testError(Path file, String expectStdErr, String expectFault) throws IOException {
 684         Result r = run(file, Collections.emptyList(), List.of("1", "2", "3"));
 685         checkEmpty("stdout", r.stdOut);
 686         checkEqual("stderr", r.stdErr, expectStdErr);
 687         checkFault("exception", r.exception, expectFault);
 688     }
 689 
 690     /*
 691      * Tests in which main throws an exception.
 692      */
 693     @Test
< prev index next >