author | rfield |
Fri, 25 Mar 2016 18:36:19 -0700 | |
changeset 36718 | bf40906bf49d |
parent 36715 | ae6fa9280e0b |
child 36990 | ec0b843a7af5 |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
36494 | 2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33362 | 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 |
import java.io.ByteArrayOutputStream; |
|
25 |
import java.io.OutputStream; |
|
26 |
import java.io.PrintStream; |
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.Arrays; |
|
34570
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
29 |
import java.util.Collections; |
33362 | 30 |
import java.util.HashMap; |
31 |
import java.util.List; |
|
32 |
import java.util.Map; |
|
33 |
import java.util.function.Consumer; |
|
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
34 |
import java.util.function.Function; |
33362 | 35 |
import java.util.function.Predicate; |
36715
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
36 |
import java.util.prefs.AbstractPreferences; |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
37 |
import java.util.prefs.BackingStoreException; |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
38 |
import java.util.prefs.Preferences; |
33362 | 39 |
import java.util.regex.Matcher; |
40 |
import java.util.regex.Pattern; |
|
41 |
import java.util.stream.Collectors; |
|
42 |
import java.util.stream.Stream; |
|
43 |
||
44 |
import jdk.internal.jshell.tool.JShellTool; |
|
45 |
import jdk.jshell.SourceCodeAnalysis.Suggestion; |
|
46 |
||
36715
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
47 |
import org.testng.annotations.BeforeMethod; |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
48 |
|
34570
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
49 |
import static java.util.stream.Collectors.toList; |
33362 | 50 |
import static org.testng.Assert.assertEquals; |
51 |
import static org.testng.Assert.assertNotNull; |
|
52 |
import static org.testng.Assert.assertTrue; |
|
53 |
import static org.testng.Assert.fail; |
|
54 |
||
55 |
public class ReplToolTesting { |
|
56 |
||
57 |
private final static String DEFAULT_STARTUP_MESSAGE = "| Welcome to"; |
|
34570
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
58 |
final static List<ImportInfo> START_UP_IMPORTS = Stream.of( |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
59 |
"java.util.*", |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
60 |
"java.io.*", |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
61 |
"java.math.*", |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
62 |
"java.net.*", |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
63 |
"java.util.concurrent.*", |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
64 |
"java.util.prefs.*", |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
65 |
"java.util.regex.*") |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
66 |
.map(s -> new ImportInfo("import " + s + ";", "", s)) |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
67 |
.collect(toList()); |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
68 |
final static List<MethodInfo> START_UP_METHODS = Stream.of( |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
69 |
new MethodInfo("void printf(String format, Object... args) { System.out.printf(format, args); }", |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
70 |
"(String,Object...)void", "printf")) |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
71 |
.collect(toList()); |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
72 |
final static List<String> START_UP = Collections.unmodifiableList( |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
73 |
Stream.concat(START_UP_IMPORTS.stream(), START_UP_METHODS.stream()) |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
74 |
.map(s -> s.getSource()) |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
75 |
.collect(toList())); |
33362 | 76 |
|
77 |
private WaitingTestingInputStream cmdin = null; |
|
78 |
private ByteArrayOutputStream cmdout = null; |
|
79 |
private ByteArrayOutputStream cmderr = null; |
|
80 |
private PromptedCommandOutputStream console = null; |
|
81 |
private TestingInputStream userin = null; |
|
82 |
private ByteArrayOutputStream userout = null; |
|
83 |
private ByteArrayOutputStream usererr = null; |
|
84 |
||
85 |
private List<MemberInfo> keys; |
|
86 |
private Map<String, VariableInfo> variables; |
|
87 |
private Map<String, MethodInfo> methods; |
|
88 |
private Map<String, ClassInfo> classes; |
|
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
89 |
private Map<String, ImportInfo> imports; |
33362 | 90 |
private boolean isDefaultStartUp = true; |
36715
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
91 |
private Preferences prefs; |
33362 | 92 |
|
93 |
public JShellTool repl = null; |
|
94 |
||
95 |
public interface ReplTest { |
|
96 |
void run(boolean after); |
|
97 |
} |
|
98 |
||
99 |
public void setCommandInput(String s) { |
|
100 |
cmdin.setInput(s); |
|
101 |
} |
|
102 |
||
103 |
public final static Pattern idPattern = Pattern.compile("^\\s+(\\d+)"); |
|
104 |
public Consumer<String> assertList() { |
|
105 |
return s -> { |
|
106 |
List<String> lines = Stream.of(s.split("\n")) |
|
107 |
.filter(l -> !l.isEmpty()) |
|
108 |
.collect(Collectors.toList()); |
|
109 |
int previousId = Integer.MIN_VALUE; |
|
110 |
assertEquals(lines.size(), keys.size(), "Number of keys"); |
|
111 |
for (int i = 0; i < lines.size(); ++i) { |
|
112 |
String line = lines.get(i); |
|
113 |
Matcher matcher = idPattern.matcher(line); |
|
114 |
assertTrue(matcher.find(), "Snippet id not found: " + line); |
|
115 |
String src = keys.get(i).getSource(); |
|
116 |
assertTrue(line.endsWith(src), "Line '" + line + "' does not end with: " + src); |
|
117 |
int id = Integer.parseInt(matcher.group(1)); |
|
118 |
assertTrue(previousId < id, |
|
119 |
String.format("The previous id is not less than the next one: previous: %d, next: %d", |
|
120 |
previousId, id)); |
|
121 |
previousId = id; |
|
122 |
} |
|
123 |
}; |
|
124 |
} |
|
125 |
||
126 |
private final static Pattern extractPattern = Pattern.compile("^\\| *(.*)$"); |
|
127 |
private Consumer<String> assertMembers(String message, Map<String, ? extends MemberInfo> set) { |
|
128 |
return s -> { |
|
129 |
List<String> lines = Stream.of(s.split("\n")) |
|
130 |
.filter(l -> !l.isEmpty()) |
|
131 |
.collect(Collectors.toList()); |
|
132 |
assertEquals(lines.size(), set.size(), message + " : expected: " + set.keySet() + "\ngot:\n" + lines); |
|
133 |
for (String line : lines) { |
|
134 |
Matcher matcher = extractPattern.matcher(line); |
|
135 |
assertTrue(matcher.find(), line); |
|
136 |
String src = matcher.group(1); |
|
137 |
MemberInfo info = set.get(src); |
|
138 |
assertNotNull(info, "Not found snippet with signature: " + src + ", line: " |
|
139 |
+ line + ", keys: " + set.keySet() + "\n"); |
|
140 |
} |
|
141 |
}; |
|
142 |
} |
|
143 |
||
144 |
public Consumer<String> assertVariables() { |
|
145 |
return assertMembers("Variables", variables); |
|
146 |
} |
|
147 |
||
148 |
public Consumer<String> assertMethods() { |
|
149 |
return assertMembers("Methods", methods); |
|
150 |
} |
|
151 |
||
152 |
public Consumer<String> assertClasses() { |
|
153 |
return assertMembers("Classes", classes); |
|
154 |
} |
|
155 |
||
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
156 |
public Consumer<String> assertImports() { |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
157 |
return assertMembers("Imports", imports); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
158 |
} |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
159 |
|
33362 | 160 |
public String getCommandOutput() { |
35002 | 161 |
String s = normalizeLineEndings(cmdout.toString()); |
33362 | 162 |
cmdout.reset(); |
163 |
return s; |
|
164 |
} |
|
165 |
||
166 |
public String getCommandErrorOutput() { |
|
35002 | 167 |
String s = normalizeLineEndings(cmderr.toString()); |
33362 | 168 |
cmderr.reset(); |
169 |
return s; |
|
170 |
} |
|
171 |
||
172 |
public void setUserInput(String s) { |
|
173 |
userin.setInput(s); |
|
174 |
} |
|
175 |
||
176 |
public String getUserOutput() { |
|
35002 | 177 |
String s = normalizeLineEndings(userout.toString()); |
33362 | 178 |
userout.reset(); |
179 |
return s; |
|
180 |
} |
|
181 |
||
182 |
public String getUserErrorOutput() { |
|
35002 | 183 |
String s = normalizeLineEndings(usererr.toString()); |
33362 | 184 |
usererr.reset(); |
185 |
return s; |
|
186 |
} |
|
187 |
||
188 |
public void test(ReplTest... tests) { |
|
189 |
test(new String[0], tests); |
|
190 |
} |
|
191 |
||
192 |
public void test(String[] args, ReplTest... tests) { |
|
193 |
test(true, args, tests); |
|
194 |
} |
|
195 |
||
196 |
public void test(boolean isDefaultStartUp, String[] args, ReplTest... tests) { |
|
197 |
test(isDefaultStartUp, args, DEFAULT_STARTUP_MESSAGE, tests); |
|
198 |
} |
|
199 |
||
200 |
public void test(boolean isDefaultStartUp, String[] args, String startUpMessage, ReplTest... tests) { |
|
201 |
this.isDefaultStartUp = isDefaultStartUp; |
|
202 |
initSnippets(); |
|
203 |
ReplTest[] wtests = new ReplTest[tests.length + 3]; |
|
204 |
wtests[0] = a -> assertCommandCheckOutput(a, "<start>", |
|
205 |
s -> assertTrue(s.startsWith(startUpMessage), "Expected start-up message '" + startUpMessage + "' Got: " + s)); |
|
206 |
wtests[1] = a -> assertCommand(a, "/debug 0", null); |
|
207 |
System.arraycopy(tests, 0, wtests, 2, tests.length); |
|
208 |
wtests[tests.length + 2] = a -> assertCommand(a, "/exit", null); |
|
209 |
testRaw(args, wtests); |
|
210 |
} |
|
211 |
||
212 |
private void initSnippets() { |
|
213 |
keys = new ArrayList<>(); |
|
214 |
variables = new HashMap<>(); |
|
215 |
methods = new HashMap<>(); |
|
216 |
classes = new HashMap<>(); |
|
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
217 |
imports = new HashMap<>(); |
33362 | 218 |
if (isDefaultStartUp) { |
34570
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
219 |
methods.putAll( |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
220 |
START_UP_METHODS.stream() |
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
221 |
.collect(Collectors.toMap(Object::toString, Function.identity()))); |
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
222 |
imports.putAll( |
34570
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
33714
diff
changeset
|
223 |
START_UP_IMPORTS.stream() |
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
224 |
.collect(Collectors.toMap(Object::toString, Function.identity()))); |
33362 | 225 |
} |
226 |
} |
|
227 |
||
36715
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
228 |
@BeforeMethod |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
229 |
public void setUp() { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
230 |
prefs = new MemoryPreferences(); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
231 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
232 |
|
33362 | 233 |
public void testRaw(String[] args, ReplTest... tests) { |
234 |
cmdin = new WaitingTestingInputStream(); |
|
235 |
cmdout = new ByteArrayOutputStream(); |
|
236 |
cmderr = new ByteArrayOutputStream(); |
|
237 |
console = new PromptedCommandOutputStream(tests); |
|
238 |
userin = new TestingInputStream(); |
|
239 |
userout = new ByteArrayOutputStream(); |
|
240 |
usererr = new ByteArrayOutputStream(); |
|
241 |
repl = new JShellTool( |
|
242 |
cmdin, |
|
243 |
new PrintStream(cmdout), |
|
244 |
new PrintStream(cmderr), |
|
245 |
new PrintStream(console), |
|
246 |
userin, |
|
247 |
new PrintStream(userout), |
|
36715
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
248 |
new PrintStream(usererr), |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
249 |
prefs); |
33362 | 250 |
repl.testPrompt = true; |
251 |
try { |
|
252 |
repl.start(args); |
|
253 |
} catch (Exception ex) { |
|
254 |
fail("Repl tool died with exception", ex); |
|
255 |
} |
|
256 |
// perform internal consistency checks on state, if desired |
|
257 |
String cos = getCommandOutput(); |
|
258 |
String ceos = getCommandErrorOutput(); |
|
259 |
String uos = getUserOutput(); |
|
260 |
String ueos = getUserErrorOutput(); |
|
261 |
assertTrue((cos.isEmpty() || cos.startsWith("| Goodbye")), |
|
262 |
"Expected a goodbye, but got: " + cos); |
|
263 |
assertTrue(ceos.isEmpty(), "Expected empty error output, got: " + ceos); |
|
264 |
assertTrue(uos.isEmpty(), "Expected empty output, got: " + uos); |
|
265 |
assertTrue(ueos.isEmpty(), "Expected empty error output, got: " + ueos); |
|
266 |
} |
|
267 |
||
268 |
public void assertReset(boolean after, String cmd) { |
|
269 |
assertCommand(after, cmd, "| Resetting state.\n"); |
|
270 |
initSnippets(); |
|
271 |
} |
|
272 |
||
273 |
public void evaluateExpression(boolean after, String type, String expr, String value) { |
|
274 |
String output = String.format("\\| *Expression values is: %s\n|" + |
|
275 |
" *.*temporary variable (\\$\\d+) of type %s", value, type); |
|
276 |
Pattern outputPattern = Pattern.compile(output); |
|
277 |
assertCommandCheckOutput(after, expr, s -> { |
|
278 |
Matcher matcher = outputPattern.matcher(s); |
|
279 |
assertTrue(matcher.find(), "Output: '" + s + "' does not fit pattern: '" + output + "'"); |
|
280 |
String name = matcher.group(1); |
|
281 |
VariableInfo tempVar = new TempVariableInfo(expr, type, name, value); |
|
282 |
variables.put(tempVar.toString(), tempVar); |
|
283 |
addKey(after, tempVar); |
|
284 |
}); |
|
285 |
} |
|
286 |
||
287 |
public void loadVariable(boolean after, String type, String name) { |
|
288 |
loadVariable(after, type, name, null, null); |
|
289 |
} |
|
290 |
||
291 |
public void loadVariable(boolean after, String type, String name, String expr, String value) { |
|
292 |
String src = expr == null |
|
293 |
? String.format("%s %s", type, name) |
|
294 |
: String.format("%s %s = %s", type, name, expr); |
|
295 |
VariableInfo var = expr == null |
|
296 |
? new VariableInfo(src, type, name) |
|
297 |
: new VariableInfo(src, type, name, value); |
|
298 |
addKey(after, var, variables); |
|
299 |
addKey(after, var); |
|
300 |
} |
|
301 |
||
302 |
public void assertVariable(boolean after, String type, String name) { |
|
303 |
assertVariable(after, type, name, null, null); |
|
304 |
} |
|
305 |
||
306 |
public void assertVariable(boolean after, String type, String name, String expr, String value) { |
|
307 |
String src = expr == null |
|
308 |
? String.format("%s %s", type, name) |
|
309 |
: String.format("%s %s = %s", type, name, expr); |
|
310 |
VariableInfo var = expr == null |
|
311 |
? new VariableInfo(src, type, name) |
|
312 |
: new VariableInfo(src, type, name, value); |
|
313 |
assertCommandCheckOutput(after, src, var.checkOutput()); |
|
314 |
addKey(after, var, variables); |
|
315 |
addKey(after, var); |
|
316 |
} |
|
317 |
||
318 |
public void loadMethod(boolean after, String src, String signature, String name) { |
|
319 |
MethodInfo method = new MethodInfo(src, signature, name); |
|
320 |
addKey(after, method, methods); |
|
321 |
addKey(after, method); |
|
322 |
} |
|
323 |
||
324 |
public void assertMethod(boolean after, String src, String signature, String name) { |
|
325 |
MethodInfo method = new MethodInfo(src, signature, name); |
|
326 |
assertCommandCheckOutput(after, src, method.checkOutput()); |
|
327 |
addKey(after, method, methods); |
|
328 |
addKey(after, method); |
|
329 |
} |
|
330 |
||
331 |
public void loadClass(boolean after, String src, String type, String name) { |
|
332 |
ClassInfo clazz = new ClassInfo(src, type, name); |
|
333 |
addKey(after, clazz, classes); |
|
334 |
addKey(after, clazz); |
|
335 |
} |
|
336 |
||
337 |
public void assertClass(boolean after, String src, String type, String name) { |
|
338 |
ClassInfo clazz = new ClassInfo(src, type, name); |
|
339 |
assertCommandCheckOutput(after, src, clazz.checkOutput()); |
|
340 |
addKey(after, clazz, classes); |
|
341 |
addKey(after, clazz); |
|
342 |
} |
|
343 |
||
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
344 |
public void loadImport(boolean after, String src, String type, String name) { |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
345 |
ImportInfo i = new ImportInfo(src, type, name); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
346 |
addKey(after, i, imports); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
347 |
addKey(after, i); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
348 |
} |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
349 |
|
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
350 |
public void assertImport(boolean after, String src, String type, String name) { |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
351 |
ImportInfo i = new ImportInfo(src, type, name); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
352 |
assertCommandCheckOutput(after, src, i.checkOutput()); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
353 |
addKey(after, i, imports); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
354 |
addKey(after, i); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
355 |
} |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
356 |
|
33362 | 357 |
private <T extends MemberInfo> void addKey(boolean after, T memberInfo, Map<String, T> map) { |
358 |
if (after) { |
|
359 |
map.entrySet().removeIf(e -> e.getValue().equals(memberInfo)); |
|
360 |
map.put(memberInfo.toString(), memberInfo); |
|
361 |
} |
|
362 |
} |
|
363 |
||
364 |
private <T extends MemberInfo> void addKey(boolean after, T memberInfo) { |
|
365 |
if (after) { |
|
366 |
for (int i = 0; i < keys.size(); ++i) { |
|
367 |
MemberInfo m = keys.get(i); |
|
368 |
if (m.equals(memberInfo)) { |
|
369 |
keys.set(i, memberInfo); |
|
370 |
return; |
|
371 |
} |
|
372 |
} |
|
373 |
keys.add(memberInfo); |
|
374 |
} |
|
375 |
} |
|
376 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
377 |
private void dropKey(boolean after, String cmd, String name, Map<String, ? extends MemberInfo> map, String output) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
378 |
assertCommand(after, cmd, output); |
33362 | 379 |
if (after) { |
380 |
map.remove(name); |
|
381 |
for (int i = 0; i < keys.size(); ++i) { |
|
382 |
MemberInfo m = keys.get(i); |
|
383 |
if (m.toString().equals(name)) { |
|
384 |
keys.remove(i); |
|
385 |
return; |
|
386 |
} |
|
387 |
} |
|
388 |
throw new AssertionError("Key not found: " + name + ", keys: " + keys); |
|
389 |
} |
|
390 |
} |
|
391 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
392 |
public void dropVariable(boolean after, String cmd, String name, String output) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
393 |
dropKey(after, cmd, name, variables, output); |
33362 | 394 |
} |
395 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
396 |
public void dropMethod(boolean after, String cmd, String name, String output) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
397 |
dropKey(after, cmd, name, methods, output); |
33362 | 398 |
} |
399 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
400 |
public void dropClass(boolean after, String cmd, String name, String output) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
401 |
dropKey(after, cmd, name, classes, output); |
33362 | 402 |
} |
403 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
404 |
public void dropImport(boolean after, String cmd, String name, String output) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
405 |
dropKey(after, cmd, name, imports, output); |
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
406 |
} |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
407 |
|
33362 | 408 |
public void assertCommand(boolean after, String cmd, String out) { |
409 |
assertCommand(after, cmd, out, "", null, "", ""); |
|
410 |
} |
|
411 |
||
36494 | 412 |
public void assertCommandOutputContains(boolean after, String cmd, String has) { |
413 |
assertCommandCheckOutput(after, cmd, (s) -> |
|
414 |
assertTrue(s.contains(has), "Output: \'" + s + "' does not contain: " + has)); |
|
415 |
} |
|
416 |
||
417 |
public void assertCommandOutputStartsWith(boolean after, String cmd, String starts) { |
|
418 |
assertCommandCheckOutput(after, cmd, assertStartsWith(starts)); |
|
419 |
} |
|
420 |
||
33362 | 421 |
public void assertCommandCheckOutput(boolean after, String cmd, Consumer<String> check) { |
422 |
if (!after) { |
|
423 |
assertCommand(false, cmd, null); |
|
424 |
} else { |
|
425 |
String got = getCommandOutput(); |
|
426 |
check.accept(got); |
|
427 |
assertCommand(true, cmd, null); |
|
428 |
} |
|
429 |
} |
|
430 |
||
431 |
public void assertCommand(boolean after, String cmd, String out, String err, |
|
432 |
String userinput, String print, String usererr) { |
|
433 |
if (!after) { |
|
434 |
if (userinput != null) { |
|
435 |
setUserInput(userinput); |
|
436 |
} |
|
437 |
setCommandInput(cmd + "\n"); |
|
438 |
} else { |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
439 |
assertOutput(getCommandOutput(), out, "command output: " + cmd); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
440 |
assertOutput(getCommandErrorOutput(), err, "command error: " + cmd); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
441 |
assertOutput(getUserOutput(), print, "user output: " + cmd); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
442 |
assertOutput(getUserErrorOutput(), usererr, "user error: " + cmd); |
33362 | 443 |
} |
444 |
} |
|
445 |
||
446 |
public void assertCompletion(boolean after, String code, boolean isSmart, String... expected) { |
|
447 |
if (!after) { |
|
448 |
setCommandInput("\n"); |
|
449 |
} else { |
|
450 |
assertCompletion(code, isSmart, expected); |
|
451 |
} |
|
452 |
} |
|
453 |
||
454 |
public void assertCompletion(String code, boolean isSmart, String... expected) { |
|
455 |
List<String> completions = computeCompletions(code, isSmart); |
|
456 |
assertEquals(completions, Arrays.asList(expected), "Command: " + code + ", output: " + |
|
457 |
completions.toString()); |
|
458 |
} |
|
459 |
||
460 |
private List<String> computeCompletions(String code, boolean isSmart) { |
|
36494 | 461 |
JShellTool js = this.repl != null ? this.repl |
36715
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
462 |
: new JShellTool(null, null, null, null, null, null, null, prefs); |
33362 | 463 |
int cursor = code.indexOf('|'); |
464 |
code = code.replace("|", ""); |
|
465 |
assertTrue(cursor > -1, "'|' not found: " + code); |
|
466 |
List<Suggestion> completions = |
|
36494 | 467 |
js.commandCompletionSuggestions(code, cursor, new int[1]); //XXX: ignoring anchor for now |
33362 | 468 |
return completions.stream() |
469 |
.filter(s -> isSmart == s.isSmart) |
|
470 |
.map(s -> s.continuation) |
|
471 |
.distinct() |
|
472 |
.collect(Collectors.toList()); |
|
473 |
} |
|
474 |
||
475 |
public Consumer<String> assertStartsWith(String prefix) { |
|
476 |
return (output) -> assertTrue(output.startsWith(prefix), "Output: \'" + output + "' does not start with: " + prefix); |
|
477 |
} |
|
478 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
479 |
public void assertOutput(String got, String expected, String display) { |
33362 | 480 |
if (expected != null) { |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36715
diff
changeset
|
481 |
assertEquals(got, expected, display + ".\n"); |
33362 | 482 |
} |
483 |
} |
|
484 |
||
35002 | 485 |
private String normalizeLineEndings(String text) { |
486 |
return text.replace(System.getProperty("line.separator"), "\n"); |
|
487 |
} |
|
488 |
||
33362 | 489 |
public static abstract class MemberInfo { |
490 |
public final String source; |
|
491 |
public final String type; |
|
492 |
public final String name; |
|
493 |
||
494 |
public MemberInfo(String source, String type, String name) { |
|
495 |
this.source = source; |
|
496 |
this.type = type; |
|
497 |
this.name = name; |
|
498 |
} |
|
499 |
||
500 |
@Override |
|
501 |
public int hashCode() { |
|
502 |
return name.hashCode(); |
|
503 |
} |
|
504 |
||
36494 | 505 |
@Override |
506 |
public boolean equals(Object o) { |
|
507 |
if (o instanceof MemberInfo) { |
|
508 |
MemberInfo mi = (MemberInfo) o; |
|
509 |
return name.equals(mi.name); |
|
510 |
} |
|
511 |
return false; |
|
512 |
} |
|
513 |
||
33362 | 514 |
public abstract Consumer<String> checkOutput(); |
515 |
||
516 |
public String getSource() { |
|
517 |
return source; |
|
518 |
} |
|
519 |
} |
|
520 |
||
521 |
public static class VariableInfo extends MemberInfo { |
|
522 |
||
523 |
public final String value; |
|
524 |
public final String initialValue; |
|
525 |
||
526 |
public VariableInfo(String src, String type, String name) { |
|
527 |
super(src, type, name); |
|
528 |
this.initialValue = null; |
|
529 |
switch (type) { |
|
530 |
case "byte": |
|
531 |
case "short": |
|
532 |
case "int": |
|
533 |
case "long": |
|
534 |
value = "0"; |
|
535 |
break; |
|
536 |
case "boolean": |
|
537 |
value = "false"; |
|
538 |
break; |
|
539 |
case "char": |
|
540 |
value = "''"; |
|
541 |
break; |
|
542 |
case "float": |
|
543 |
case "double": |
|
544 |
value = "0.0"; |
|
545 |
break; |
|
546 |
default: |
|
547 |
value = "null"; |
|
548 |
} |
|
549 |
} |
|
550 |
||
551 |
public VariableInfo(String src, String type, String name, String value) { |
|
552 |
super(src, type, name); |
|
553 |
this.value = value; |
|
554 |
this.initialValue = value; |
|
555 |
} |
|
556 |
||
557 |
@Override |
|
558 |
public Consumer<String> checkOutput() { |
|
559 |
String pattern = String.format("\\| *\\w+ variable %s of type %s", name, type); |
|
560 |
if (initialValue != null) { |
|
561 |
pattern += " with initial value " + initialValue; |
|
562 |
} |
|
563 |
Predicate<String> checkOutput = Pattern.compile(pattern).asPredicate(); |
|
564 |
final String finalPattern = pattern; |
|
565 |
return output -> assertTrue(checkOutput.test(output), |
|
566 |
"Output: " + output + " does not fit pattern: " + finalPattern); |
|
567 |
} |
|
568 |
||
569 |
@Override |
|
36494 | 570 |
public int hashCode() { |
571 |
return name.hashCode(); |
|
572 |
} |
|
573 |
||
574 |
@Override |
|
33362 | 575 |
public boolean equals(Object o) { |
576 |
if (o instanceof VariableInfo) { |
|
577 |
VariableInfo v = (VariableInfo) o; |
|
578 |
return name.equals(v.name); |
|
579 |
} |
|
580 |
return false; |
|
581 |
} |
|
582 |
||
583 |
@Override |
|
584 |
public String toString() { |
|
585 |
return String.format("%s %s = %s", type, name, value); |
|
586 |
} |
|
587 |
||
588 |
@Override |
|
589 |
public String getSource() { |
|
590 |
String src = super.getSource(); |
|
591 |
return src.endsWith(";") ? src : src + ";"; |
|
592 |
} |
|
593 |
} |
|
594 |
||
595 |
public static class TempVariableInfo extends VariableInfo { |
|
596 |
||
597 |
public TempVariableInfo(String src, String type, String name, String value) { |
|
598 |
super(src, type, name, value); |
|
599 |
} |
|
600 |
||
601 |
@Override |
|
602 |
public String getSource() { |
|
603 |
return source; |
|
604 |
} |
|
605 |
} |
|
606 |
||
607 |
public static class MethodInfo extends MemberInfo { |
|
608 |
||
609 |
public final String signature; |
|
610 |
||
611 |
public MethodInfo(String source, String signature, String name) { |
|
612 |
super(source, signature.substring(0, signature.lastIndexOf(')') + 1), name); |
|
613 |
this.signature = signature; |
|
614 |
} |
|
615 |
||
616 |
@Override |
|
617 |
public Consumer<String> checkOutput() { |
|
618 |
String expectedOutput = String.format("\\| *\\w+ method %s", name); |
|
619 |
Predicate<String> checkOutput = Pattern.compile(expectedOutput).asPredicate(); |
|
620 |
return s -> assertTrue(checkOutput.test(s), "Expected: '" + expectedOutput + "', actual: " + s); |
|
621 |
} |
|
622 |
||
36494 | 623 |
@Override |
624 |
public int hashCode() { |
|
625 |
return (name.hashCode() << 2) ^ type.hashCode() ; |
|
626 |
} |
|
33362 | 627 |
|
628 |
@Override |
|
629 |
public boolean equals(Object o) { |
|
630 |
if (o instanceof MemberInfo) { |
|
631 |
MemberInfo m = (MemberInfo) o; |
|
632 |
return name.equals(m.name) && type.equals(m.type); |
|
633 |
} |
|
634 |
return false; |
|
635 |
} |
|
636 |
||
637 |
@Override |
|
638 |
public String toString() { |
|
639 |
return String.format("%s %s", name, signature); |
|
640 |
} |
|
641 |
} |
|
642 |
||
643 |
public static class ClassInfo extends MemberInfo { |
|
644 |
||
645 |
public ClassInfo(String source, String type, String name) { |
|
646 |
super(source, type, name); |
|
647 |
} |
|
648 |
||
649 |
@Override |
|
650 |
public Consumer<String> checkOutput() { |
|
651 |
String fullType = type.equals("@interface")? "annotation interface" : type; |
|
652 |
String expectedOutput = String.format("\\| *\\w+ %s %s", fullType, name); |
|
653 |
Predicate<String> checkOutput = Pattern.compile(expectedOutput).asPredicate(); |
|
654 |
return s -> assertTrue(checkOutput.test(s), "Expected: '" + expectedOutput + "', actual: " + s); |
|
655 |
} |
|
656 |
||
657 |
@Override |
|
36494 | 658 |
public int hashCode() { |
659 |
return name.hashCode() ; |
|
660 |
} |
|
661 |
||
662 |
@Override |
|
33362 | 663 |
public boolean equals(Object o) { |
664 |
if (o instanceof ClassInfo) { |
|
665 |
ClassInfo c = (ClassInfo) o; |
|
666 |
return name.equals(c.name); |
|
667 |
} |
|
668 |
return false; |
|
669 |
} |
|
670 |
||
671 |
@Override |
|
672 |
public String toString() { |
|
673 |
return String.format("%s %s", type, name); |
|
674 |
} |
|
675 |
} |
|
676 |
||
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
677 |
public static class ImportInfo extends MemberInfo { |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
678 |
public ImportInfo(String source, String type, String fullname) { |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
679 |
super(source, type, fullname); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
680 |
} |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
681 |
|
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
682 |
@Override |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
683 |
public Consumer<String> checkOutput() { |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
684 |
return s -> assertTrue("".equals(s), "Expected: '', actual: " + s); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
685 |
} |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
686 |
|
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
687 |
@Override |
36494 | 688 |
public int hashCode() { |
689 |
return (name.hashCode() << 2) ^ type.hashCode() ; |
|
690 |
} |
|
691 |
||
692 |
@Override |
|
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
693 |
public boolean equals(Object o) { |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
694 |
if (o instanceof ImportInfo) { |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
695 |
ImportInfo i = (ImportInfo) o; |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
696 |
return name.equals(i.name) && type.equals(i.type); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
697 |
} |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
698 |
return false; |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
699 |
} |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
700 |
|
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
701 |
@Override |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
702 |
public String toString() { |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
703 |
return String.format("import %s%s", type.equals("static") ? "static " : "", name); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
704 |
} |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
705 |
} |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
706 |
|
33362 | 707 |
class WaitingTestingInputStream extends TestingInputStream { |
708 |
||
709 |
@Override |
|
710 |
synchronized void setInput(String s) { |
|
711 |
super.setInput(s); |
|
712 |
notify(); |
|
713 |
} |
|
714 |
||
715 |
synchronized void waitForInput() { |
|
716 |
boolean interrupted = false; |
|
717 |
try { |
|
718 |
while (available() == 0) { |
|
719 |
try { |
|
720 |
wait(); |
|
721 |
} catch (InterruptedException e) { |
|
722 |
interrupted = true; |
|
723 |
// fall through and retry |
|
724 |
} |
|
725 |
} |
|
726 |
} finally { |
|
727 |
if (interrupted) { |
|
728 |
Thread.currentThread().interrupt(); |
|
729 |
} |
|
730 |
} |
|
731 |
} |
|
732 |
||
733 |
@Override |
|
734 |
public int read() { |
|
735 |
waitForInput(); |
|
736 |
return super.read(); |
|
737 |
} |
|
738 |
||
739 |
@Override |
|
740 |
public int read(byte b[], int off, int len) { |
|
741 |
waitForInput(); |
|
742 |
return super.read(b, off, len); |
|
743 |
} |
|
744 |
} |
|
745 |
||
746 |
class PromptedCommandOutputStream extends OutputStream { |
|
747 |
private final ReplTest[] tests; |
|
748 |
private int index = 0; |
|
749 |
PromptedCommandOutputStream(ReplTest[] tests) { |
|
750 |
this.tests = tests; |
|
751 |
} |
|
752 |
||
753 |
@Override |
|
754 |
public synchronized void write(int b) { |
|
755 |
if (b == 5 || b == 6) { |
|
756 |
if (index < (tests.length - 1)) { |
|
757 |
tests[index].run(true); |
|
758 |
tests[index + 1].run(false); |
|
759 |
} else { |
|
760 |
fail("Did not exit Repl tool after test"); |
|
761 |
} |
|
762 |
++index; |
|
763 |
} // For now, anything else is thrown away |
|
764 |
} |
|
765 |
||
766 |
@Override |
|
767 |
public synchronized void write(byte b[], int off, int len) { |
|
768 |
if ((off < 0) || (off > b.length) || (len < 0) |
|
769 |
|| ((off + len) - b.length > 0)) { |
|
770 |
throw new IndexOutOfBoundsException(); |
|
771 |
} |
|
772 |
for (int i = 0; i < len; ++i) { |
|
773 |
write(b[off + i]); |
|
774 |
} |
|
775 |
} |
|
776 |
} |
|
36715
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
777 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
778 |
public static final class MemoryPreferences extends AbstractPreferences { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
779 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
780 |
private final Map<String, String> values = new HashMap<>(); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
781 |
private final Map<String, MemoryPreferences> nodes = new HashMap<>(); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
782 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
783 |
public MemoryPreferences() { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
784 |
this(null, ""); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
785 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
786 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
787 |
public MemoryPreferences(MemoryPreferences parent, String name) { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
788 |
super(parent, name); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
789 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
790 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
791 |
@Override |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
792 |
protected void putSpi(String key, String value) { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
793 |
values.put(key, value); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
794 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
795 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
796 |
@Override |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
797 |
protected String getSpi(String key) { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
798 |
return values.get(key); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
799 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
800 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
801 |
@Override |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
802 |
protected void removeSpi(String key) { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
803 |
values.remove(key); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
804 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
805 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
806 |
@Override |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
807 |
protected void removeNodeSpi() throws BackingStoreException { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
808 |
((MemoryPreferences) parent()).nodes.remove(name()); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
809 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
810 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
811 |
@Override |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
812 |
protected String[] keysSpi() throws BackingStoreException { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
813 |
return values.keySet().toArray(new String[0]); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
814 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
815 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
816 |
@Override |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
817 |
protected String[] childrenNamesSpi() throws BackingStoreException { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
818 |
return nodes.keySet().toArray(new String[0]); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
819 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
820 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
821 |
@Override |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
822 |
protected AbstractPreferences childSpi(String name) { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
823 |
return nodes.computeIfAbsent(name, n -> new MemoryPreferences(this, name)); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
824 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
825 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
826 |
@Override |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
827 |
protected void syncSpi() throws BackingStoreException { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
828 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
829 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
830 |
@Override |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
831 |
protected void flushSpi() throws BackingStoreException { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
832 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
833 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36494
diff
changeset
|
834 |
} |
33362 | 835 |
} |