test/langtools/jdk/jshell/ToolTabSnippetTest.java
author jlahoda
Thu, 02 Nov 2017 10:09:34 +0100
changeset 47484 d0cb66d8cbf1
parent 47216 71c04702a3d5
child 47518 783d04ecccc3
permissions -rw-r--r--
8189595: jshell tool: line redrawn on each completion Reviewed-by: rfield
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     1
/*
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     4
 *
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     8
 *
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    14
 *
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    18
 *
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    21
 * questions.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    22
 */
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    23
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    24
/**
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    25
 * @test
47484
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
    26
 * @bug 8177076 8185426 8189595
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    27
 * @modules
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    28
 *     jdk.compiler/com.sun.tools.javac.api
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    29
 *     jdk.compiler/com.sun.tools.javac.main
47050
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
    30
 *     jdk.jshell/jdk.internal.jshell.tool
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    31
 *     jdk.jshell/jdk.internal.jshell.tool.resources:open
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    32
 *     jdk.jshell/jdk.jshell:open
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    33
 * @library /tools/lib
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    34
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
44570
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents: 44459
diff changeset
    35
 * @build Compiler UITesting
46185
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 44811
diff changeset
    36
 * @build ToolTabSnippetTest
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 44811
diff changeset
    37
 * @run testng/timeout=300 ToolTabSnippetTest
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    38
 */
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    39
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    40
import java.io.IOException;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    41
import java.lang.reflect.Field;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    42
import java.nio.file.Files;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    43
import java.nio.file.Path;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    44
import java.nio.file.Paths;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    45
import java.util.Arrays;
47050
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
    46
import java.util.concurrent.CountDownLatch;
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    47
import java.util.jar.JarEntry;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    48
import java.util.jar.JarOutputStream;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    49
import java.util.regex.Pattern;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    50
47050
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
    51
import jdk.internal.jshell.tool.ConsoleIOContextTestSupport;
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    52
import org.testng.annotations.Test;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    53
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    54
@Test
46185
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 44811
diff changeset
    55
public class ToolTabSnippetTest extends UITesting {
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    56
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    57
    public void testExpression() throws Exception {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    58
        Path classes = prepareZip();
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    59
        doRunTest((inputSink, out) -> {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    60
            inputSink.write("/env -class-path " + classes.toString() + "\n");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    61
            waitOutput(out, Pattern.quote(getResource("jshell.msg.set.restore")) + "\n\u0005");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    62
            inputSink.write("import jshelltest.*;\n");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    63
            waitOutput(out, "\n\u0005");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    64
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    65
            //-> <tab>
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    66
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    67
            waitOutput(out, getMessage("jshell.console.completion.all.completions.number", "[0-9]+"));
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    68
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    69
            waitOutput(out, ".*String.*StringBuilder.*\n\r\u0005");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    70
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    71
            //new JShellTes<tab>
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    72
            inputSink.write("new JShellTes\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    73
            waitOutput(out, "t\nJShellTest\\(      JShellTestAux\\(   \n\r\u0005new JShellTest");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    74
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    75
            //new JShellTest<tab>
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    76
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    77
            waitOutput(out, "JShellTest\\(      JShellTestAux\\(   \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    78
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    79
                            Pattern.quote(getResource("jshell.console.completion.current.signatures")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    80
                            "jshelltest.JShellTest\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    81
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    82
                            Pattern.quote(getResource("jshell.console.see.documentation")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    83
                            "\r\u0005new JShellTest");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    84
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    85
            waitOutput(out, "jshelltest.JShellTest\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    86
                            "JShellTest 0\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    87
                            "\r\u0005new JShellTest");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    88
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    89
            waitOutput(out, "JShellTest\\(      JShellTestAux\\(   \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    90
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    91
                            Pattern.quote(getResource("jshell.console.completion.current.signatures")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    92
                            "jshelltest.JShellTest\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    93
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    94
                            Pattern.quote(getResource("jshell.console.see.documentation")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    95
                            "\r\u0005new JShellTest");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    96
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    97
            //new JShellTest(<tab>
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    98
            inputSink.write("(\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    99
            waitOutput(out, "\\(\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   100
                            Pattern.quote(getResource("jshell.console.completion.current.signatures")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   101
                            "JShellTest\\(String str\\)\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   102
                            "JShellTest\\(String str, int i\\)\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   103
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   104
                            Pattern.quote(getResource("jshell.console.see.documentation")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   105
                            "\r\u0005new JShellTest\\(");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   106
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   107
            waitOutput(out, "JShellTest\\(String str\\)\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   108
                            "JShellTest 1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   109
                            "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   110
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   111
                            Pattern.quote(getResource("jshell.console.see.next.page")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   112
                            "\r\u0005new JShellTest\\(");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   113
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   114
            waitOutput(out, "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   115
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   116
                            Pattern.quote(getResource("jshell.console.see.next.javadoc")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   117
                            "\r\u0005new JShellTest\\(");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   118
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   119
            waitOutput(out, "JShellTest\\(String str, int i\\)\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   120
                            "JShellTest 2\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   121
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   122
                            getMessage("jshell.console.completion.all.completions.number", "[0-9]+") + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   123
                            "\r\u0005new JShellTest\\(");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   124
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   125
            waitOutput(out, ".*String.*StringBuilder.*\n\r\u0005new JShellTest\\(");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   126
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   127
            inputSink.write("\u0003String str = \"\";\nnew JShellTest(");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   128
            waitOutput(out, "\u0005new JShellTest\\(");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   129
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   130
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   131
            waitOutput(out, "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   132
                            "str   \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   133
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   134
                            Pattern.quote(getResource("jshell.console.completion.current.signatures")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   135
                            "JShellTest\\(String str\\)\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   136
                            "JShellTest\\(String str, int i\\)\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   137
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   138
                            Pattern.quote(getResource("jshell.console.see.documentation")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   139
                            "\r\u0005new JShellTest\\(");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   140
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   141
            waitOutput(out, "JShellTest\\(String str\\)\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   142
                            "JShellTest 1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   143
                            "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   144
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   145
                            Pattern.quote(getResource("jshell.console.see.next.page")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   146
                            "\r\u0005new JShellTest\\(");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   147
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   148
            waitOutput(out, "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   149
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   150
                            Pattern.quote(getResource("jshell.console.see.next.javadoc")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   151
                            "\r\u0005new JShellTest\\(");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   152
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   153
            waitOutput(out, "JShellTest\\(String str, int i\\)\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   154
                            "JShellTest 2\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   155
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   156
                            getMessage("jshell.console.completion.all.completions.number", "[0-9]+") + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   157
                            "\r\u0005new JShellTest\\(");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   158
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   159
            waitOutput(out, ".*String.*StringBuilder.*\n\r\u0005new JShellTest\\(");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   160
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   161
            inputSink.write("\u0003JShellTest t = new JShellTest\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   162
            waitOutput(out, "\u0005JShellTest t = new JShellTest\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   163
                            "JShellTest\\(   \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   164
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   165
                            Pattern.quote(getResource("jshell.console.completion.current.signatures")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   166
                            "jshelltest.JShellTest\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   167
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   168
                            Pattern.quote(getResource("jshell.console.completion.all.completions")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   169
                            "\r\u0005JShellTest t = new JShellTest");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   170
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   171
            waitOutput(out, "JShellTest\\(      JShellTestAux\\(   \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   172
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   173
                            Pattern.quote(getResource("jshell.console.see.documentation")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   174
                            "\r\u0005JShellTest t = new JShellTest");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   175
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   176
            inputSink.write("\u0003JShellTest t = new \011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   177
            waitOutput(out, "\u0005JShellTest t = new \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   178
                            "JShellTest\\(   \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   179
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   180
                            getMessage("jshell.console.completion.all.completions.number", "[0-9]+") + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   181
                            "\r\u0005JShellTest t = new ");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   182
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   183
            waitOutput(out, ".*String.*StringBuilder.*\n\r\u0005JShellTest t = new ");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   184
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   185
            inputSink.write("\u0003class JShelX{}\n");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   186
            inputSink.write("new JShel\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   187
            waitOutput(out, "\u0005new JShel\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   188
                            "JShelX\\(\\)         JShellTest\\(      JShellTestAux\\(   \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   189
                            "\r\u0005new JShel");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   190
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   191
            //no crash:
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   192
            inputSink.write("\u0003new Stringbuil\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   193
            waitOutput(out, "\u0005new Stringbuil\u0007");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   194
        });
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   195
    }
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   196
47050
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   197
    public void testCleaningCompletionTODO() throws Exception {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   198
        doRunTest((inputSink, out) -> {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   199
            CountDownLatch testCompleteComputationStarted = new CountDownLatch(1);
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   200
            CountDownLatch testCompleteComputationContinue = new CountDownLatch(1);
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   201
            ConsoleIOContextTestSupport.IMPL = new ConsoleIOContextTestSupport() {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   202
                @Override
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   203
                protected void willComputeCompletionCallback() {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   204
                    if (testCompleteComputationStarted != null) {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   205
                        testCompleteComputationStarted.countDown();
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   206
                    }
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   207
                    if (testCompleteComputationContinue != null) {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   208
                        try {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   209
                            testCompleteComputationContinue.await();
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   210
                        } catch (InterruptedException ex) {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   211
                            throw new IllegalStateException(ex);
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   212
                        }
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   213
                    }
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   214
                }
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   215
            };
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   216
            //-> <tab>
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   217
            inputSink.write("\011");
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   218
            testCompleteComputationStarted.await();
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   219
            //-> <tab><tab>
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   220
            inputSink.write("\011\011");
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   221
            testCompleteComputationContinue.countDown();
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   222
            waitOutput(out, "\u0005");
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   223
            //-> <tab>
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   224
            inputSink.write("\011");
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   225
            waitOutput(out, "\u0005");
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   226
            ConsoleIOContextTestSupport.IMPL = null;
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   227
        });
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   228
    }
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   229
47484
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   230
    public void testNoRepeat() throws Exception {
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   231
        doRunTest((inputSink, out) -> {
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   232
            inputSink.write("String xyzAA;\n");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   233
            waitOutput(out, "\u0005");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   234
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   235
            //xyz<tab>
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   236
            inputSink.write("String s = xyz\011");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   237
            waitOutput(out, "^String s = xyzAA");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   238
            inputSink.write(".");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   239
            waitOutput(out, "^\\.");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   240
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   241
            inputSink.write("\u0003");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   242
            waitOutput(out, "\u0005");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   243
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   244
            inputSink.write("double xyzAB;\n");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   245
            waitOutput(out, "\u0005");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   246
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   247
            //xyz<tab>
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   248
            inputSink.write("String s = xyz\011");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   249
            String allCompletions =
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   250
                    Pattern.quote(getResource("jshell.console.completion.all.completions"));
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   251
            waitOutput(out, ".*xyzAA.*" + allCompletions + ".*\u0005String s = xyzA");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   252
        });
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   253
    }
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   254
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   255
    private Path prepareZip() {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   256
        String clazz1 =
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   257
                "package jshelltest;\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   258
                "/**JShellTest 0" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   259
                " */\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   260
                "public class JShellTest {\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   261
                "    /**JShellTest 1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   262
                "     * <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   263
                "     * <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   264
                "     * <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   265
                "     */\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   266
                "    public JShellTest(String str) {}\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   267
                "    /**JShellTest 2" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   268
                "     */\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   269
                "    public JShellTest(String str, int i) {}\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   270
                "}\n";
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   271
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   272
        String clazz2 =
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   273
                "package jshelltest;\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   274
                "/**JShellTestAux 0" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   275
                " */\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   276
                "public class JShellTestAux {\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   277
                "    /**JShellTest 1" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   278
                "     */\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   279
                "    public JShellTestAux(String str) { }\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   280
                "    /**JShellTest 2" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   281
                "     */\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   282
                "    public JShellTestAux(String str, int i) { }\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   283
                "}\n";
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   284
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   285
        Path srcZip = Paths.get("src.zip");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   286
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   287
        try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   288
            out.putNextEntry(new JarEntry("jshelltest/JShellTest.java"));
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   289
            out.write(clazz1.getBytes());
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   290
            out.putNextEntry(new JarEntry("jshelltest/JShellTestAux.java"));
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   291
            out.write(clazz2.getBytes());
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   292
        } catch (IOException ex) {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   293
            throw new IllegalStateException(ex);
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   294
        }
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   295
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   296
        compiler.compile(clazz1, clazz2);
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   297
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   298
        try {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   299
            Field availableSources = Class.forName("jdk.jshell.SourceCodeAnalysisImpl").getDeclaredField("availableSourcesOverride");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   300
            availableSources.setAccessible(true);
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   301
            availableSources.set(null, Arrays.asList(srcZip));
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   302
        } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException | ClassNotFoundException ex) {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   303
            throw new IllegalStateException(ex);
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   304
        }
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   305
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   306
        return compiler.getClassDir();
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   307
    }
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   308
    //where:
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   309
        private final Compiler compiler = new Compiler();
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   310
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   311
}