author | jlahoda |
Thu, 09 May 2019 11:58:26 +0200 | |
changeset 54778 | d1d6e939803f |
parent 52938 | 5ff7480c9e28 |
permissions | -rw-r--r-- |
44459 | 1 |
/* |
50868 | 2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
44459 | 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 |
|
54778
d1d6e939803f
8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents:
52938
diff
changeset
|
26 |
* @bug 8177076 8185426 8189595 8188072 8221759 |
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 |
|
52938 | 56 |
public ToolTabSnippetTest() { |
57 |
super(true); |
|
58 |
} |
|
59 |
||
44459 | 60 |
public void testExpression() throws Exception { |
61 |
Path classes = prepareZip(); |
|
62 |
doRunTest((inputSink, out) -> { |
|
63 |
inputSink.write("/env -class-path " + classes.toString() + "\n"); |
|
52938 | 64 |
waitOutput(out, resource("jshell.msg.set.restore") + "\n\\u001B\\[\\?2004h" + PROMPT); |
44459 | 65 |
inputSink.write("import jshelltest.*;\n"); |
52938 | 66 |
waitOutput(out, "\n\\u001B\\[\\?2004l\\u001B\\[\\?2004h" + PROMPT); |
44459 | 67 |
|
68 |
//-> <tab> |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
69 |
inputSink.write(TAB); |
44459 | 70 |
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
|
71 |
inputSink.write(TAB); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
72 |
waitOutput(out, ".*String.*StringBuilder.*" + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
73 |
REDRAW_PROMPT + ""); |
44459 | 74 |
|
75 |
//new JShellTes<tab> |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
76 |
inputSink.write("new JShellTes" + TAB); |
52938 | 77 |
waitOutput(out, "\nJShellTest\\( JShellTestAux\\( " + |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
78 |
REDRAW_PROMPT + "new JShellTest"); |
44459 | 79 |
|
80 |
//new JShellTest<tab> |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
81 |
inputSink.write(TAB); |
44459 | 82 |
waitOutput(out, "JShellTest\\( JShellTestAux\\( \n" + |
83 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
84 |
resource("jshell.console.completion.current.signatures") + "\n" + |
44459 | 85 |
"jshelltest.JShellTest\n" + |
86 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
87 |
resource("jshell.console.see.documentation") + |
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); |
50338 | 90 |
waitOutput(out, "\\u001B\\[1mjshelltest.JShellTest\\u001B\\[0m\n" + |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
91 |
"JShellTest 0" + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
92 |
REDRAW_PROMPT + "new JShellTest"); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
93 |
inputSink.write(TAB); |
44459 | 94 |
waitOutput(out, "JShellTest\\( JShellTestAux\\( \n" + |
95 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
96 |
resource("jshell.console.completion.current.signatures") + "\n" + |
44459 | 97 |
"jshelltest.JShellTest\n" + |
98 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
99 |
resource("jshell.console.see.documentation") + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
100 |
REDRAW_PROMPT + "new JShellTest"); |
44459 | 101 |
|
102 |
//new JShellTest(<tab> |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
103 |
inputSink.write("(" + TAB); |
44459 | 104 |
waitOutput(out, "\\(\n" + |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
105 |
resource("jshell.console.completion.current.signatures") + "\n" + |
44459 | 106 |
"JShellTest\\(String str\\)\n" + |
107 |
"JShellTest\\(String str, int i\\)\n" + |
|
108 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
109 |
resource("jshell.console.see.documentation") + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
110 |
REDRAW_PROMPT + "new JShellTest\\("); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
111 |
inputSink.write(TAB); |
50338 | 112 |
waitOutput(out, "\\u001B\\[1mJShellTest\\(String str\\)\\u001B\\[0m\n" + |
44459 | 113 |
"JShellTest 1\n" + |
114 |
"1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" + |
|
115 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
116 |
resource("jshell.console.see.next.page") + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
117 |
REDRAW_PROMPT + "new JShellTest\\("); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
118 |
inputSink.write(TAB); |
44459 | 119 |
waitOutput(out, "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" + |
120 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
121 |
resource("jshell.console.see.next.javadoc") + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
122 |
REDRAW_PROMPT + "new JShellTest\\("); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
123 |
inputSink.write(TAB); |
50338 | 124 |
waitOutput(out, "\\u001B\\[1mJShellTest\\(String str, int i\\)\\u001B\\[0m\n" + |
44459 | 125 |
"JShellTest 2\n" + |
126 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
127 |
getMessage("jshell.console.completion.all.completions.number", "[0-9]+") + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
128 |
REDRAW_PROMPT + "new JShellTest\\("); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
129 |
inputSink.write(TAB); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
130 |
waitOutput(out, ".*String.*StringBuilder.*" + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
131 |
REDRAW_PROMPT + "new JShellTest\\("); |
44459 | 132 |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
133 |
inputSink.write(INTERRUPT + "String str = \"\";\nnew JShellTest("); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
134 |
waitOutput(out, PROMPT + "new JShellTest\\("); |
44459 | 135 |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
136 |
inputSink.write(TAB); |
44459 | 137 |
waitOutput(out, "\n" + |
138 |
"str \n" + |
|
139 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
140 |
resource("jshell.console.completion.current.signatures") + "\n" + |
44459 | 141 |
"JShellTest\\(String str\\)\n" + |
142 |
"JShellTest\\(String str, int i\\)\n" + |
|
143 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
144 |
resource("jshell.console.see.documentation") + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
145 |
REDRAW_PROMPT + "new JShellTest\\("); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
146 |
inputSink.write(TAB); |
50338 | 147 |
waitOutput(out, "\\u001B\\[1mJShellTest\\(String str\\)\\u001B\\[0m\n" + |
44459 | 148 |
"JShellTest 1\n" + |
149 |
"1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" + |
|
150 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
151 |
resource("jshell.console.see.next.page") + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
152 |
REDRAW_PROMPT + "new JShellTest\\("); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
153 |
inputSink.write(TAB); |
44459 | 154 |
waitOutput(out, "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" + |
155 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
156 |
resource("jshell.console.see.next.javadoc") + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
157 |
REDRAW_PROMPT + "new JShellTest\\("); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
158 |
inputSink.write(TAB); |
50338 | 159 |
waitOutput(out, "\\u001B\\[1mJShellTest\\(String str, int i\\)\\u001B\\[0m\n" + |
44459 | 160 |
"JShellTest 2\n" + |
161 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
162 |
getMessage("jshell.console.completion.all.completions.number", "[0-9]+") + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
163 |
REDRAW_PROMPT + "new JShellTest\\("); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
164 |
inputSink.write(TAB); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
165 |
waitOutput(out, ".*String.*StringBuilder.*" + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
166 |
REDRAW_PROMPT + "new JShellTest\\("); |
44459 | 167 |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
168 |
inputSink.write(INTERRUPT + "JShellTest t = new JShellTest" + TAB); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
169 |
waitOutput(out, PROMPT + "JShellTest t = new JShellTest\n" + |
44459 | 170 |
"JShellTest\\( \n" + |
171 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
172 |
resource("jshell.console.completion.current.signatures") + "\n" + |
44459 | 173 |
"jshelltest.JShellTest\n" + |
174 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
175 |
resource("jshell.console.completion.all.completions") + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
176 |
REDRAW_PROMPT + "JShellTest t = new JShellTest"); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
177 |
inputSink.write(TAB); |
44459 | 178 |
waitOutput(out, "JShellTest\\( JShellTestAux\\( \n" + |
179 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
180 |
resource("jshell.console.see.documentation") + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
181 |
REDRAW_PROMPT + "JShellTest t = new JShellTest"); |
44459 | 182 |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
183 |
inputSink.write(INTERRUPT + "JShellTest t = new " + TAB); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
184 |
waitOutput(out, PROMPT + "JShellTest t = new \n" + |
44459 | 185 |
"JShellTest\\( \n" + |
186 |
"\n" + |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
187 |
getMessage("jshell.console.completion.all.completions.number", "[0-9]+") + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
188 |
REDRAW_PROMPT + "JShellTest t = new "); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
189 |
inputSink.write(TAB); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
190 |
waitOutput(out, ".*String.*StringBuilder.*" + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
191 |
REDRAW_PROMPT + "JShellTest t = new "); |
44459 | 192 |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
193 |
inputSink.write(INTERRUPT + "class JShelX{}\n"); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
194 |
inputSink.write("new JShel" + TAB); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
195 |
waitOutput(out, PROMPT + "new JShel\n" + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
196 |
"JShelX\\(\\) JShellTest\\( JShellTestAux\\( " + |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
197 |
REDRAW_PROMPT + "new JShel"); |
44459 | 198 |
|
199 |
//no crash: |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
200 |
inputSink.write(INTERRUPT + "new Stringbuil" + TAB); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
201 |
waitOutput(out, PROMPT + "new Stringbuil" + BELL); |
47517
b5ad886110b3
8188072: JShell: NPE in SourceCodeAnalysis.completionSuggestions()
rfield
parents:
47216
diff
changeset
|
202 |
|
b5ad886110b3
8188072: JShell: NPE in SourceCodeAnalysis.completionSuggestions()
rfield
parents:
47216
diff
changeset
|
203 |
//no crash: 8188072 |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
204 |
inputSink.write(INTERRUPT + "for (int:" + TAB); |
50868 | 205 |
waitOutput(out, PROMPT + "for \\(int:\n" + |
206 |
getMessage("jshell.console.completion.all.completions.number", "[0-9]+") + |
|
207 |
REDRAW_PROMPT + "for \\(int:"); |
|
44459 | 208 |
}); |
209 |
} |
|
210 |
||
47050 | 211 |
public void testCleaningCompletionTODO() throws Exception { |
212 |
doRunTest((inputSink, out) -> { |
|
213 |
CountDownLatch testCompleteComputationStarted = new CountDownLatch(1); |
|
214 |
CountDownLatch testCompleteComputationContinue = new CountDownLatch(1); |
|
215 |
ConsoleIOContextTestSupport.IMPL = new ConsoleIOContextTestSupport() { |
|
216 |
@Override |
|
217 |
protected void willComputeCompletionCallback() { |
|
218 |
if (testCompleteComputationStarted != null) { |
|
219 |
testCompleteComputationStarted.countDown(); |
|
220 |
} |
|
221 |
if (testCompleteComputationContinue != null) { |
|
222 |
try { |
|
223 |
testCompleteComputationContinue.await(); |
|
224 |
} catch (InterruptedException ex) { |
|
225 |
throw new IllegalStateException(ex); |
|
226 |
} |
|
227 |
} |
|
228 |
} |
|
229 |
}; |
|
230 |
//-> <tab> |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
231 |
inputSink.write(TAB); |
47050 | 232 |
testCompleteComputationStarted.await(); |
233 |
//-> <tab><tab> |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
234 |
inputSink.write(TAB + TAB); |
47050 | 235 |
testCompleteComputationContinue.countDown(); |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
236 |
waitOutput(out, PROMPT); |
47050 | 237 |
//-> <tab> |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
238 |
inputSink.write(TAB); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
239 |
waitOutput(out, PROMPT); |
47050 | 240 |
ConsoleIOContextTestSupport.IMPL = null; |
241 |
}); |
|
242 |
} |
|
243 |
||
47484
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
244 |
public void testNoRepeat() throws Exception { |
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
245 |
doRunTest((inputSink, out) -> { |
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
246 |
inputSink.write("String xyzAA;\n"); |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
247 |
waitOutput(out, PROMPT); |
47484
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
248 |
|
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
249 |
//xyz<tab> |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
250 |
inputSink.write("String s = xyz" + TAB); |
47484
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
251 |
waitOutput(out, "^String s = xyzAA"); |
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
252 |
inputSink.write("."); |
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
253 |
waitOutput(out, "^\\."); |
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
254 |
|
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
255 |
inputSink.write(INTERRUPT); |
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
256 |
waitOutput(out, PROMPT); |
47484
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
257 |
|
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
258 |
inputSink.write("double xyzAB;\n"); |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
259 |
waitOutput(out, PROMPT); |
47484
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 |
//xyz<tab> |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
262 |
inputSink.write("String s = xyz" + TAB); |
47484
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
263 |
String allCompletions = |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47518
diff
changeset
|
264 |
resource("jshell.console.completion.all.completions"); |
47484
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
265 |
waitOutput(out, ".*xyzAA.*" + allCompletions + ".*\u0005String s = xyzA"); |
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
266 |
}); |
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
267 |
} |
d0cb66d8cbf1
8189595: jshell tool: line redrawn on each completion
jlahoda
parents:
47216
diff
changeset
|
268 |
|
54778
d1d6e939803f
8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents:
52938
diff
changeset
|
269 |
public void testCrash8221759() throws Exception { |
d1d6e939803f
8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents:
52938
diff
changeset
|
270 |
doRunTest((inputSink, out) -> { |
d1d6e939803f
8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents:
52938
diff
changeset
|
271 |
inputSink.write("java.io.File.path" + TAB); |
d1d6e939803f
8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents:
52938
diff
changeset
|
272 |
waitOutput(out, "java.io.File.path\n" + |
d1d6e939803f
8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents:
52938
diff
changeset
|
273 |
"pathSeparator pathSeparatorChar " + |
d1d6e939803f
8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents:
52938
diff
changeset
|
274 |
REDRAW_PROMPT + "java.io.File.pathSeparator"); |
d1d6e939803f
8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents:
52938
diff
changeset
|
275 |
}); |
d1d6e939803f
8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents:
52938
diff
changeset
|
276 |
} |
d1d6e939803f
8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents:
52938
diff
changeset
|
277 |
|
44459 | 278 |
private Path prepareZip() { |
279 |
String clazz1 = |
|
280 |
"package jshelltest;\n" + |
|
281 |
"/**JShellTest 0" + |
|
282 |
" */\n" + |
|
283 |
"public class JShellTest {\n" + |
|
284 |
" /**JShellTest 1\n" + |
|
285 |
" * <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1\n" + |
|
286 |
" * <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1\n" + |
|
287 |
" * <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1\n" + |
|
288 |
" */\n" + |
|
289 |
" public JShellTest(String str) {}\n" + |
|
290 |
" /**JShellTest 2" + |
|
291 |
" */\n" + |
|
292 |
" public JShellTest(String str, int i) {}\n" + |
|
293 |
"}\n"; |
|
294 |
||
295 |
String clazz2 = |
|
296 |
"package jshelltest;\n" + |
|
297 |
"/**JShellTestAux 0" + |
|
298 |
" */\n" + |
|
299 |
"public class JShellTestAux {\n" + |
|
300 |
" /**JShellTest 1" + |
|
301 |
" */\n" + |
|
302 |
" public JShellTestAux(String str) { }\n" + |
|
303 |
" /**JShellTest 2" + |
|
304 |
" */\n" + |
|
305 |
" public JShellTestAux(String str, int i) { }\n" + |
|
306 |
"}\n"; |
|
307 |
||
308 |
Path srcZip = Paths.get("src.zip"); |
|
309 |
||
310 |
try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) { |
|
311 |
out.putNextEntry(new JarEntry("jshelltest/JShellTest.java")); |
|
312 |
out.write(clazz1.getBytes()); |
|
313 |
out.putNextEntry(new JarEntry("jshelltest/JShellTestAux.java")); |
|
314 |
out.write(clazz2.getBytes()); |
|
315 |
} catch (IOException ex) { |
|
316 |
throw new IllegalStateException(ex); |
|
317 |
} |
|
318 |
||
319 |
compiler.compile(clazz1, clazz2); |
|
320 |
||
321 |
try { |
|
322 |
Field availableSources = Class.forName("jdk.jshell.SourceCodeAnalysisImpl").getDeclaredField("availableSourcesOverride"); |
|
323 |
availableSources.setAccessible(true); |
|
324 |
availableSources.set(null, Arrays.asList(srcZip)); |
|
325 |
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException | ClassNotFoundException ex) { |
|
326 |
throw new IllegalStateException(ex); |
|
327 |
} |
|
328 |
||
329 |
return compiler.getClassDir(); |
|
330 |
} |
|
331 |
//where: |
|
332 |
private final Compiler compiler = new Compiler(); |
|
333 |
||
334 |
} |