langtools/test/tools/javac/importscope/CompletionFailureDuringImport.java
changeset 36778 e04318f39f92
parent 36526 3b41f1c69604
equal deleted inserted replaced
36777:28d33fb9097f 36778:e04318f39f92
     1 /*
     1 /*
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    25  * @test
    25  * @test
    26  * @bug 8131915
    26  * @bug 8131915
    27  * @summary Verify that CompletionFailure thrown during listing of import content is handled properly.
    27  * @summary Verify that CompletionFailure thrown during listing of import content is handled properly.
    28  * @library /tools/lib
    28  * @library /tools/lib
    29  * @modules jdk.compiler/com.sun.tools.javac.api
    29  * @modules jdk.compiler/com.sun.tools.javac.api
    30  *          jdk.compiler/com.sun.tools.javac.file
       
    31  *          jdk.compiler/com.sun.tools.javac.main
    30  *          jdk.compiler/com.sun.tools.javac.main
    32  *          jdk.jdeps/com.sun.tools.javap
    31  * @build toolbox.ToolBox toolbox.JavacTask
       
    32  * @run main CompletionFailureDuringImport
    33  */
    33  */
    34 
    34 
    35 import java.nio.file.Files;
    35 import java.nio.file.Files;
    36 import java.nio.file.Paths;
    36 import java.nio.file.Paths;
    37 import java.util.Arrays;
    37 import java.util.Arrays;
    38 import java.util.List;
    38 import java.util.List;
       
    39 
       
    40 import toolbox.JavacTask;
       
    41 import toolbox.Task;
       
    42 import toolbox.ToolBox;
    39 
    43 
    40 public class CompletionFailureDuringImport {
    44 public class CompletionFailureDuringImport {
    41     public static void main(String... args) throws Exception {
    45     public static void main(String... args) throws Exception {
    42         new CompletionFailureDuringImport().run();
    46         new CompletionFailureDuringImport().run();
    43     }
    47     }
    44 
    48 
    45     ToolBox tb = new ToolBox();
    49     ToolBox tb = new ToolBox();
    46 
    50 
    47     void run() throws Exception {
    51     void run() throws Exception {
    48         tb.new JavacTask()
    52         new JavacTask(tb)
    49           .outdir(".")
    53           .outdir(".")
    50           .sources("package p; public class Super { public static final int I = 0; }",
    54           .sources("package p; public class Super { public static final int I = 0; }",
    51                    "package p; public class Sub extends Super { }")
    55                    "package p; public class Sub extends Super { }")
    52           .run()
    56           .run()
    53           .writeAll();
    57           .writeAll();
    73                "Test.java:1:52: compiler.err.cant.resolve.location: kindname.variable, I, , , (compiler.misc.location: kindname.class, Test, null)",
    77                "Test.java:1:52: compiler.err.cant.resolve.location: kindname.variable, I, , , (compiler.misc.location: kindname.class, Test, null)",
    74                "2 errors");
    78                "2 errors");
    75     }
    79     }
    76 
    80 
    77     void doTest(String importText, String useText, String... expectedOutput) {
    81     void doTest(String importText, String useText, String... expectedOutput) {
    78         List<String> log = tb.new JavacTask()
    82         List<String> log = new JavacTask(tb)
    79                 .classpath(".")
    83                 .classpath(".")
    80                 .sources(importText + " public class Test { " + useText + " }")
    84                 .sources(importText + " public class Test { " + useText + " }")
    81                 .options("-XDrawDiagnostics")
    85                 .options("-XDrawDiagnostics")
    82                 .run(ToolBox.Expect.FAIL)
    86                 .run(Task.Expect.FAIL)
    83                 .writeAll()
    87                 .writeAll()
    84                 .getOutputLines(ToolBox.OutputKind.DIRECT);
    88                 .getOutputLines(Task.OutputKind.DIRECT);
    85 
    89 
    86         if (!log.equals(Arrays.asList(expectedOutput))) {
    90         if (!log.equals(Arrays.asList(expectedOutput))) {
    87             throw new AssertionError("Unexpected output: " + log);
    91             throw new AssertionError("Unexpected output: " + log);
    88         }
    92         }
    89     }
    93     }