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