author | rfield |
Mon, 07 Dec 2015 09:18:07 -0800 | |
changeset 34481 | e0ff9821f1e8 |
parent 34477 | 64001b0533a2 |
child 34570 | 8a8f52a733dd |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
2 |
* Copyright (c) 2015, 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 |
|
34481
e0ff9821f1e8
8144756: JShell: ToolBasicTest.java missing @bug tag for 8142447
rfield
parents:
34477
diff
changeset
|
26 |
* @bug 8143037 8142447 |
33362 | 27 |
* @summary Tests for Basic tests for REPL tool |
33918
6d7a40b2a54b
8143334: @ignore langtools/test/jdk/jshell/ToolBasicTest.java
jlahoda
parents:
33714
diff
changeset
|
28 |
* @ignore 8139873 |
33362 | 29 |
* @library /tools/lib |
30 |
* @build KullaTesting TestingInputStream ToolBox Compiler |
|
31 |
* @run testng ToolBasicTest |
|
32 |
*/ |
|
33 |
||
34 |
import java.io.IOException; |
|
35 |
import java.io.PrintWriter; |
|
36 |
import java.io.StringWriter; |
|
37 |
import java.nio.file.Files; |
|
38 |
import java.nio.file.Path; |
|
39 |
import java.nio.file.Paths; |
|
40 |
import java.util.ArrayList; |
|
41 |
import java.util.Arrays; |
|
42 |
import java.util.List; |
|
43 |
import java.util.Scanner; |
|
34477
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
44 |
import java.util.function.BiFunction; |
33362 | 45 |
import java.util.function.Consumer; |
34477
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
46 |
import java.util.function.Function; |
33362 | 47 |
import java.util.prefs.BackingStoreException; |
48 |
import java.util.prefs.Preferences; |
|
49 |
import java.util.stream.Collectors; |
|
50 |
import java.util.stream.Stream; |
|
51 |
||
52 |
import org.testng.annotations.Test; |
|
53 |
||
54 |
import static org.testng.Assert.assertEquals; |
|
55 |
import static org.testng.Assert.assertTrue; |
|
56 |
import static org.testng.Assert.fail; |
|
57 |
||
58 |
@Test |
|
59 |
public class ToolBasicTest extends ReplToolTesting { |
|
60 |
||
61 |
public void defineVar() { |
|
62 |
test( |
|
63 |
(a) -> assertCommand(a, "int x = 72", "| Added variable x of type int with initial value 72\n"), |
|
64 |
(a) -> assertCommand(a, "x", "| Variable x of type int has value 72\n"), |
|
65 |
(a) -> assertCommand(a, "/vars", "| int x = 72\n") |
|
66 |
); |
|
67 |
} |
|
68 |
||
69 |
public void defineUnresolvedVar() { |
|
70 |
test( |
|
71 |
(a) -> assertCommand(a, "undefined x", |
|
72 |
"| Added variable x, however, it cannot be referenced until class undefined is declared\n"), |
|
73 |
(a) -> assertCommand(a, "/vars", "| undefined x = (not-active)\n") |
|
74 |
); |
|
75 |
} |
|
76 |
||
77 |
public void testUnresolved() { |
|
78 |
test( |
|
79 |
(a) -> assertCommand(a, "int f() { return g() + x + new A().a; }", |
|
80 |
"| Added method f(), however, it cannot be invoked until method g(), variable x, and class A are declared\n"), |
|
81 |
(a) -> assertCommand(a, "f()", |
|
82 |
"| Attempted to call f which cannot be invoked until method g(), variable x, and class A are declared\n"), |
|
83 |
(a) -> assertCommand(a, "int g() { return x; }", |
|
84 |
"| Added method g(), however, it cannot be invoked until variable x is declared\n"), |
|
85 |
(a) -> assertCommand(a, "g()", "| Attempted to call g which cannot be invoked until variable x is declared\n") |
|
86 |
); |
|
87 |
} |
|
88 |
||
89 |
public void elideStartUpFromList() { |
|
90 |
test( |
|
91 |
(a) -> assertCommandCheckOutput(a, "123", (s) -> |
|
92 |
assertTrue(s.contains("type int"), s)), |
|
93 |
(a) -> assertCommandCheckOutput(a, "/list", (s) -> { |
|
94 |
int cnt; |
|
95 |
try (Scanner scanner = new Scanner(s)) { |
|
96 |
cnt = 0; |
|
97 |
while (scanner.hasNextLine()) { |
|
98 |
String line = scanner.nextLine(); |
|
99 |
if (!line.trim().isEmpty()) { |
|
100 |
++cnt; |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
assertEquals(cnt, 1, "Expected only one listed line"); |
|
105 |
}) |
|
106 |
); |
|
107 |
} |
|
108 |
||
109 |
public void elideStartUpFromSave() throws IOException { |
|
110 |
Compiler compiler = new Compiler(); |
|
111 |
Path path = compiler.getPath("myfile"); |
|
112 |
test( |
|
113 |
(a) -> assertCommandCheckOutput(a, "123", |
|
114 |
(s) -> assertTrue(s.contains("type int"), s)), |
|
115 |
(a) -> assertCommand(a, "/save " + path.toString(), "") |
|
116 |
); |
|
117 |
try (Stream<String> lines = Files.lines(path)) { |
|
118 |
assertEquals(lines.count(), 1, "Expected only one saved line"); |
|
119 |
} |
|
120 |
} |
|
121 |
||
122 |
public void testInterrupt() { |
|
123 |
ReplTest interrupt = (a) -> assertCommand(a, "\u0003", ""); |
|
124 |
for (String s : new String[] { "", "\u0003" }) { |
|
125 |
test(false, new String[]{"-nostartup"}, |
|
126 |
(a) -> assertCommand(a, "int a = 2 +" + s, ""), |
|
127 |
interrupt, |
|
128 |
(a) -> assertCommand(a, "int a\u0003", ""), |
|
129 |
(a) -> assertCommand(a, "int a = 2 + 2\u0003", ""), |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
130 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
33362 | 131 |
(a) -> evaluateExpression(a, "int", "2", "2"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
132 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
33362 | 133 |
(a) -> assertCommand(a, "void f() {", ""), |
134 |
(a) -> assertCommand(a, "int q = 10;" + s, ""), |
|
135 |
interrupt, |
|
136 |
(a) -> assertCommand(a, "void f() {}\u0003", ""), |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
137 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
33362 | 138 |
(a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
139 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
33362 | 140 |
(a) -> assertCommand(a, "class A {" + s, ""), |
141 |
interrupt, |
|
142 |
(a) -> assertCommand(a, "class A {}\u0003", ""), |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
143 |
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), |
33362 | 144 |
(a) -> assertClass(a, "interface A {}", "interface", "A"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
145 |
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), |
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
146 |
(a) -> assertCommand(a, "import java.util.stream." + s, ""), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
147 |
interrupt, |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
148 |
(a) -> assertCommand(a, "import java.util.stream.\u0003", ""), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
149 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
150 |
(a) -> assertImport(a, "import java.util.stream.Stream", "", "java.util.stream.Stream"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
151 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()) |
33362 | 152 |
); |
153 |
} |
|
154 |
} |
|
155 |
||
156 |
private final Object lock = new Object(); |
|
157 |
private PrintWriter out; |
|
158 |
private boolean isStopped; |
|
159 |
private Thread t; |
|
160 |
private void assertStop(boolean after, String cmd, String output) { |
|
161 |
if (!after) { |
|
162 |
isStopped = false; |
|
163 |
StringWriter writer = new StringWriter(); |
|
164 |
out = new PrintWriter(writer); |
|
165 |
setCommandInput(cmd + "\n"); |
|
166 |
t = new Thread(() -> { |
|
167 |
try { |
|
168 |
// no chance to know whether cmd is being evaluated |
|
169 |
Thread.sleep(5000); |
|
170 |
} catch (InterruptedException ignored) { |
|
171 |
} |
|
172 |
int i = 1; |
|
173 |
int n = 30; |
|
174 |
synchronized (lock) { |
|
175 |
do { |
|
176 |
setCommandInput("\u0003"); |
|
177 |
if (!isStopped) { |
|
178 |
out.println("Not stopped. Try again: " + i); |
|
179 |
try { |
|
180 |
lock.wait(1000); |
|
181 |
} catch (InterruptedException ignored) { |
|
182 |
} |
|
183 |
} |
|
184 |
} while (i++ < n && !isStopped); |
|
185 |
if (!isStopped) { |
|
186 |
System.err.println(writer.toString()); |
|
187 |
fail("Evaluation was not stopped: '" + cmd + "'"); |
|
188 |
} |
|
189 |
} |
|
190 |
}); |
|
191 |
t.start(); |
|
192 |
} else { |
|
193 |
synchronized (lock) { |
|
194 |
out.println("Evaluation was stopped successfully: '" + cmd + "'"); |
|
195 |
isStopped = true; |
|
196 |
lock.notify(); |
|
197 |
} |
|
198 |
try { |
|
199 |
t.join(); |
|
200 |
t = null; |
|
201 |
} catch (InterruptedException ignored) { |
|
202 |
} |
|
203 |
assertOutput(getCommandOutput(), "", "command"); |
|
204 |
assertOutput(getCommandErrorOutput(), "", "command error"); |
|
205 |
assertOutput(getUserOutput(), output, "user"); |
|
206 |
assertOutput(getUserErrorOutput(), "", "user error"); |
|
207 |
} |
|
208 |
} |
|
209 |
||
210 |
public void testStop() { |
|
211 |
test( |
|
212 |
(a) -> assertStop(a, "while (true) {}", "Killed.\n"), |
|
213 |
(a) -> assertStop(a, "while (true) { try { Thread.sleep(100); } catch (InterruptedException ex) { } }", "Killed.\n") |
|
214 |
); |
|
215 |
} |
|
216 |
||
217 |
@Test(enabled = false) // TODO 8130450 |
|
218 |
public void testRerun() { |
|
219 |
test(false, new String[] {"-nostartup"}, |
|
34477
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
220 |
(a) -> assertCommand(a, "/0", "| No such command or snippet id: /0\n| Type /help for help.\n"), |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
221 |
(a) -> assertCommand(a, "/5", "| No such command or snippet id: /5\n| Type /help for help.\n") |
33362 | 222 |
); |
223 |
String[] codes = new String[] { |
|
224 |
"int a = 0;", // var |
|
225 |
"class A {}", // class |
|
226 |
"void f() {}", // method |
|
227 |
"bool b;", // active failed |
|
228 |
"void g() { h(); }", // active corralled |
|
229 |
}; |
|
230 |
List<ReplTest> tests = new ArrayList<>(); |
|
231 |
for (String s : codes) { |
|
232 |
tests.add((a) -> assertCommand(a, s, null)); |
|
233 |
} |
|
234 |
for (int i = 0; i < codes.length; ++i) { |
|
235 |
final int finalI = i; |
|
236 |
Consumer<String> check = (s) -> { |
|
237 |
String[] ss = s.split("\n"); |
|
238 |
assertEquals(ss[0], codes[finalI]); |
|
239 |
assertTrue(ss.length > 1, s); |
|
240 |
}; |
|
241 |
tests.add((a) -> assertCommandCheckOutput(a, "/" + (finalI + 1), check)); |
|
242 |
} |
|
243 |
for (int i = 0; i < codes.length; ++i) { |
|
244 |
final int finalI = i; |
|
245 |
Consumer<String> check = (s) -> { |
|
246 |
String[] ss = s.split("\n"); |
|
247 |
assertEquals(ss[0], codes[codes.length - finalI - 1]); |
|
248 |
assertTrue(ss.length > 1, s); |
|
249 |
}; |
|
250 |
tests.add((a) -> assertCommandCheckOutput(a, "/-" + (finalI + 1), check)); |
|
251 |
} |
|
252 |
tests.add((a) -> assertCommandCheckOutput(a, "/!", assertStartsWith("void g() { h(); }"))); |
|
253 |
test(false, new String[]{"-nostartup"}, |
|
254 |
tests.toArray(new ReplTest[tests.size()])); |
|
255 |
} |
|
256 |
||
34477
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
257 |
public void test8142447() { |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
258 |
Function<String, BiFunction<String, Integer, ReplTest>> assertRerun = cmd -> (code, assertionCount) -> |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
259 |
(a) -> assertCommandCheckOutput(a, cmd, s -> { |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
260 |
String[] ss = s.split("\n"); |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
261 |
assertEquals(ss[0], code); |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
262 |
loadVariable(a, "int", "assertionCount", Integer.toString(assertionCount), Integer.toString(assertionCount)); |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
263 |
}); |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
264 |
ReplTest assertVariables = (a) -> assertCommandCheckOutput(a, "/v", assertVariables()); |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
265 |
|
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
266 |
Compiler compiler = new Compiler(); |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
267 |
Path startup = compiler.getPath("StartupFileOption/startup.txt"); |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
268 |
compiler.writeToFile(startup, "int assertionCount = 0;\n" + // id: s1 |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
269 |
"void add(int n) { assertionCount += n; }"); |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
270 |
test(new String[]{"-startup", startup.toString()}, |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
271 |
(a) -> assertCommand(a, "add(1)", ""), // id: 1 |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
272 |
(a) -> assertCommandCheckOutput(a, "add(ONE)", s -> assertEquals(s.split("\n")[0], "| Error:")), // id: e1 |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
273 |
(a) -> assertVariable(a, "int", "ONE", "1", "1"), |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
274 |
assertRerun.apply("/1").apply("add(1)", 2), assertVariables, |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
275 |
assertRerun.apply("/e1").apply("add(ONE)", 3), assertVariables, |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
276 |
assertRerun.apply("/s1").apply("int assertionCount = 0;", 0), assertVariables |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
277 |
); |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
278 |
|
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
279 |
test(false, new String[] {"-nostartup"}, |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
280 |
(a) -> assertCommand(a, "/s1", "| No such command or snippet id: /s1\n| Type /help for help.\n"), |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
281 |
(a) -> assertCommand(a, "/1", "| No such command or snippet id: /1\n| Type /help for help.\n"), |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
282 |
(a) -> assertCommand(a, "/e1", "| No such command or snippet id: /e1\n| Type /help for help.\n") |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
283 |
); |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
284 |
} |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
285 |
|
33362 | 286 |
public void testRemaining() { |
287 |
test( |
|
288 |
(a) -> assertCommand(a, "int z; z =", "| Added variable z of type int\n"), |
|
289 |
(a) -> assertCommand(a, "5", "| Variable z has been assigned the value 5\n"), |
|
290 |
(a) -> assertCommand(a, "/*nada*/; int q =", ""), |
|
291 |
(a) -> assertCommand(a, "77", "| Added variable q of type int with initial value 77\n"), |
|
292 |
(a) -> assertCommand(a, "//comment;", ""), |
|
293 |
(a) -> assertCommand(a, "int v;", "| Added variable v of type int\n"), |
|
294 |
(a) -> assertCommand(a, "int v; int c", "| Added variable c of type int\n") |
|
295 |
); |
|
296 |
} |
|
297 |
||
298 |
public void testDebug() { |
|
299 |
test( |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
300 |
(a) -> assertCommand(a, "/deb", "| Debugging on\n"), |
33362 | 301 |
(a) -> assertCommand(a, "/debug", "| Debugging off\n"), |
302 |
(a) -> assertCommand(a, "/debug", "| Debugging on\n"), |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
303 |
(a) -> assertCommand(a, "/deb", "| Debugging off\n") |
33362 | 304 |
); |
305 |
} |
|
306 |
||
307 |
public void testHelp() { |
|
308 |
Consumer<String> testOutput = (s) -> { |
|
309 |
List<String> ss = Stream.of(s.split("\n")) |
|
310 |
.filter(l -> !l.isEmpty()) |
|
311 |
.collect(Collectors.toList()); |
|
312 |
assertTrue(ss.size() >= 5, "Help does not print enough lines:\n" + s); |
|
313 |
}; |
|
314 |
test( |
|
315 |
(a) -> assertCommandCheckOutput(a, "/?", testOutput), |
|
316 |
(a) -> assertCommandCheckOutput(a, "/help", testOutput) |
|
317 |
); |
|
318 |
} |
|
319 |
||
320 |
public void oneLineOfError() { |
|
321 |
test( |
|
322 |
(a) -> assertCommand(a, "12+", null), |
|
323 |
(a) -> assertCommandCheckOutput(a, " true", (s) -> |
|
324 |
assertTrue(s.contains("12+") && !s.contains("true"), "Output: '" + s + "'")) |
|
325 |
); |
|
326 |
} |
|
327 |
||
328 |
public void defineVariables() { |
|
329 |
test( |
|
330 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
331 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
332 |
(a) -> assertVariable(a, "int", "a"), |
|
333 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
334 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
335 |
(a) -> assertVariable(a, "double", "a", "1", "1.0"), |
|
336 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
337 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
338 |
(a) -> evaluateExpression(a, "double", "2 * a", "2.0"), |
|
339 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
340 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()) |
|
341 |
); |
|
342 |
} |
|
343 |
||
344 |
public void defineMethods() { |
|
345 |
test( |
|
346 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
347 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
348 |
(a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"), |
|
349 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
350 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
351 |
(a) -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"), |
|
352 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
353 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
354 |
(a) -> assertMethod(a, "void g() {}", "()void", "g"), |
|
355 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
356 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
|
357 |
); |
|
358 |
} |
|
359 |
||
360 |
public void defineClasses() { |
|
361 |
test( |
|
362 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
363 |
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), |
|
364 |
(a) -> assertClass(a, "class A { }", "class", "A"), |
|
365 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
366 |
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), |
|
367 |
(a) -> assertClass(a, "interface A { }", "interface", "A"), |
|
368 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
369 |
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), |
|
370 |
(a) -> assertClass(a, "enum A { }", "enum", "A"), |
|
371 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
372 |
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), |
|
373 |
(a) -> assertClass(a, "@interface A { }", "@interface", "A"), |
|
374 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
375 |
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()) |
|
376 |
); |
|
377 |
} |
|
378 |
||
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
379 |
public void defineImports() { |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
380 |
test( |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
381 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
382 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
383 |
(a) -> assertImport(a, "import java.util.stream.Stream;", "", "java.util.stream.Stream"), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
384 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
385 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
386 |
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
387 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
388 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
389 |
(a) -> assertImport(a, "import static java.lang.Math.PI;", "static", "java.lang.Math.PI"), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
390 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
391 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
392 |
(a) -> assertImport(a, "import static java.lang.Math.*;", "static", "java.lang.Math.*"), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
393 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
394 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()) |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
395 |
); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
396 |
} |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
397 |
|
33362 | 398 |
public void testClasspathDirectory() { |
399 |
Compiler compiler = new Compiler(); |
|
400 |
Path outDir = Paths.get("testClasspathDirectory"); |
|
401 |
compiler.compile(outDir, "package pkg; public class A { public String toString() { return \"A\"; } }"); |
|
402 |
Path classpath = compiler.getPath(outDir); |
|
403 |
test( |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
404 |
(a) -> assertCommand(a, "/classpath " + classpath, String.format("| Path %s added to classpath\n", classpath)), |
33362 | 405 |
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "\"A\"") |
406 |
); |
|
407 |
test(new String[] { "-cp", classpath.toString() }, |
|
408 |
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "\"A\"") |
|
409 |
); |
|
410 |
test(new String[] { "-classpath", classpath.toString() }, |
|
411 |
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "\"A\"") |
|
412 |
); |
|
413 |
} |
|
414 |
||
415 |
public void testClasspathJar() { |
|
416 |
Compiler compiler = new Compiler(); |
|
417 |
Path outDir = Paths.get("testClasspathJar"); |
|
418 |
compiler.compile(outDir, "package pkg; public class A { public String toString() { return \"A\"; } }"); |
|
419 |
String jarName = "test.jar"; |
|
420 |
compiler.jar(outDir, jarName, "pkg/A.class"); |
|
421 |
Path jarPath = compiler.getPath(outDir).resolve(jarName); |
|
422 |
test( |
|
423 |
(a) -> assertCommand(a, "/classpath " + jarPath, String.format("| Path %s added to classpath\n", jarPath)), |
|
424 |
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "\"A\"") |
|
425 |
); |
|
426 |
test(new String[] { "-cp", jarPath.toString() }, |
|
427 |
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "\"A\"") |
|
428 |
); |
|
429 |
test(new String[] { "-classpath", jarPath.toString() }, |
|
430 |
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "\"A\"") |
|
431 |
); |
|
432 |
} |
|
433 |
||
434 |
public void testStartupFileOption() { |
|
435 |
try { |
|
436 |
Compiler compiler = new Compiler(); |
|
437 |
Path startup = compiler.getPath("StartupFileOption/startup.txt"); |
|
438 |
compiler.writeToFile(startup, "class A { public String toString() { return \"A\"; } }"); |
|
439 |
test(new String[]{"-startup", startup.toString()}, |
|
440 |
(a) -> evaluateExpression(a, "A", "new A()", "\"A\"\n") |
|
441 |
); |
|
442 |
test(new String[]{"-nostartup"}, |
|
443 |
(a) -> assertCommandCheckOutput(a, "printf(\"\")", assertStartsWith("| Error:\n| cannot find symbol")) |
|
444 |
); |
|
445 |
test((a) -> assertCommand(a, "printf(\"A\")", "", "", null, "A", "")); |
|
446 |
test(false, new String[]{"-startup", "UNKNOWN"}, "| File 'UNKNOWN' for start-up is not found."); |
|
447 |
} finally { |
|
448 |
removeStartup(); |
|
449 |
} |
|
450 |
} |
|
451 |
||
452 |
public void testLoadingFromArgs() { |
|
453 |
Compiler compiler = new Compiler(); |
|
454 |
Path path = compiler.getPath("loading.repl"); |
|
455 |
compiler.writeToFile(path, "int a = 10; double x = 20; double a = 10;"); |
|
456 |
test(new String[] { path.toString() }, |
|
457 |
(a) -> assertCommand(a, "x", "| Variable x of type double has value 20.0\n"), |
|
458 |
(a) -> assertCommand(a, "a", "| Variable a of type double has value 10.0\n") |
|
459 |
); |
|
460 |
Path unknown = compiler.getPath("UNKNOWN.jar"); |
|
461 |
test(true, new String[]{unknown.toString()}, |
|
462 |
"| File '" + unknown |
|
463 |
+ "' is not found: " + unknown |
|
464 |
+ " (No such file or directory)\n"); |
|
465 |
} |
|
466 |
||
467 |
public void testReset() { |
|
468 |
test( |
|
469 |
(a) -> assertReset(a, "/r"), |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
470 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
33362 | 471 |
(a) -> assertVariable(a, "int", "x"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
472 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
33362 | 473 |
(a) -> assertMethod(a, "void f() { }", "()void", "f"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
474 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
33362 | 475 |
(a) -> assertClass(a, "class A { }", "class", "A"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
476 |
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), |
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
477 |
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
478 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
33362 | 479 |
(a) -> assertReset(a, "/reset"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
480 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
481 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
482 |
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
483 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()) |
33362 | 484 |
); |
485 |
} |
|
486 |
||
487 |
public void testOpen() { |
|
488 |
Compiler compiler = new Compiler(); |
|
489 |
Path path = compiler.getPath("testOpen.repl"); |
|
490 |
compiler.writeToFile(path, |
|
491 |
"int a = 10;\ndouble x = 20;\ndouble a = 10;\n" + |
|
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
492 |
"class A { public String toString() { return \"A\"; } }\nimport java.util.stream.*;"); |
33362 | 493 |
for (String s : new String[]{"/o", "/open"}) { |
494 |
test( |
|
495 |
(a) -> assertCommand(a, s + " " + path.toString(), ""), |
|
496 |
(a) -> assertCommand(a, "a", "| Variable a of type double has value 10.0\n"), |
|
497 |
(a) -> evaluateExpression(a, "A", "new A();", "\"A\""), |
|
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
498 |
(a) -> evaluateExpression(a, "long", "Stream.of(\"A\").count();", "1"), |
33362 | 499 |
(a) -> { |
500 |
loadVariable(a, "double", "x", "20.0", "20.0"); |
|
501 |
loadVariable(a, "double", "a", "10.0", "10.0"); |
|
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
502 |
loadVariable(a, "A", "$7", "new A();", "A"); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
503 |
loadVariable(a, "long", "$8", "Stream.of(\"A\").count();", "1"); |
33362 | 504 |
loadClass(a, "class A { public String toString() { return \"A\"; } }", |
505 |
"class", "A"); |
|
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
506 |
loadImport(a, "import java.util.stream.*;", "", "java.util.stream.*"); |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
507 |
assertCommandCheckOutput(a, "/classes", assertClasses()); |
33362 | 508 |
}, |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
509 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
510 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
511 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()) |
33362 | 512 |
); |
513 |
Path unknown = compiler.getPath("UNKNOWN.repl"); |
|
514 |
test( |
|
515 |
(a) -> assertCommand(a, s + " " + unknown, |
|
516 |
"| File '" + unknown |
|
517 |
+ "' is not found: " + unknown |
|
518 |
+ " (No such file or directory)\n") |
|
519 |
); |
|
520 |
} |
|
521 |
} |
|
522 |
||
523 |
public void testSave() throws IOException { |
|
524 |
Compiler compiler = new Compiler(); |
|
525 |
Path path = compiler.getPath("testSave.repl"); |
|
526 |
List<String> list = Arrays.asList( |
|
527 |
"int a;", |
|
528 |
"class A { public String toString() { return \"A\"; } }" |
|
529 |
); |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
530 |
test( |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
531 |
(a) -> assertVariable(a, "int", "a"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
532 |
(a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
533 |
(a) -> assertCommand(a, "/save " + path.toString(), "") |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
534 |
); |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
535 |
assertEquals(Files.readAllLines(path), list); |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
536 |
{ |
33362 | 537 |
List<String> output = new ArrayList<>(); |
538 |
test( |
|
539 |
(a) -> assertCommand(a, "int a;", null), |
|
540 |
(a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"), |
|
541 |
(a) -> assertCommandCheckOutput(a, "/list all", (out) -> |
|
542 |
output.addAll(Stream.of(out.split("\n")) |
|
543 |
.filter(str -> !str.isEmpty()) |
|
544 |
.map(str -> str.substring(str.indexOf(':') + 2)) |
|
545 |
.filter(str -> !str.startsWith("/")) |
|
546 |
.collect(Collectors.toList()))), |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
547 |
(a) -> assertCommand(a, "/save all " + path.toString(), "") |
33362 | 548 |
); |
549 |
assertEquals(Files.readAllLines(path), output); |
|
550 |
} |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
551 |
List<String> output = new ArrayList<>(); |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
552 |
test( |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
553 |
(a) -> assertVariable(a, "int", "a"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
554 |
(a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
555 |
(a) -> assertCommandCheckOutput(a, "/history", (out) -> |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
556 |
output.addAll(Stream.of(out.split("\n")) |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
557 |
.filter(str -> !str.isEmpty()) |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
558 |
.collect(Collectors.toList()))), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
559 |
(a) -> assertCommand(a, "/save history " + path.toString(), "") |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
560 |
); |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
561 |
output.add("/save history " + path.toString()); |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
562 |
assertEquals(Files.readAllLines(path), output); |
33362 | 563 |
} |
564 |
||
565 |
public void testStartSet() throws BackingStoreException { |
|
566 |
try { |
|
567 |
Compiler compiler = new Compiler(); |
|
568 |
Path startUpFile = compiler.getPath("startUp.txt"); |
|
569 |
test( |
|
570 |
(a) -> assertVariable(a, "int", "a"), |
|
571 |
(a) -> assertVariable(a, "double", "b", "10", "10.0"), |
|
572 |
(a) -> assertMethod(a, "void f() {}", "()V", "f"), |
|
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
573 |
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
574 |
(a) -> assertCommand(a, "/save " + startUpFile.toString(), null), |
33362 | 575 |
(a) -> assertCommand(a, "/setstart " + startUpFile.toString(), null) |
576 |
); |
|
577 |
Path unknown = compiler.getPath("UNKNOWN"); |
|
578 |
test( |
|
579 |
(a) -> assertCommand(a, "/setstart " + unknown.toString(), |
|
580 |
"| File '" + unknown + "' for /setstart is not found.\n") |
|
581 |
); |
|
582 |
test(false, new String[0], |
|
583 |
(a) -> { |
|
584 |
loadVariable(a, "int", "a"); |
|
585 |
loadVariable(a, "double", "b", "10.0", "10.0"); |
|
586 |
loadMethod(a, "void f() {}", "()void", "f"); |
|
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
587 |
loadImport(a, "import java.util.stream.*;", "", "java.util.stream.*"); |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
588 |
assertCommandCheckOutput(a, "/classes", assertClasses()); |
33362 | 589 |
}, |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
590 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
591 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
592 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()) |
33362 | 593 |
); |
594 |
} finally { |
|
595 |
removeStartup(); |
|
596 |
} |
|
597 |
} |
|
598 |
||
599 |
private void removeStartup() { |
|
600 |
Preferences preferences = Preferences.userRoot().node("tool/REPL"); |
|
601 |
if (preferences != null) { |
|
602 |
preferences.remove("STARTUP"); |
|
603 |
} |
|
604 |
} |
|
605 |
||
606 |
public void testUnknownCommand() { |
|
607 |
test((a) -> assertCommand(a, "/unknown", |
|
34477
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
608 |
"| No such command or snippet id: /unknown\n" + |
33362 | 609 |
"| Type /help for help.\n")); |
610 |
} |
|
611 |
||
612 |
public void testEmptyClassPath() { |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
613 |
test(after -> assertCommand(after, "/classpath", "| /classpath requires a path argument\n")); |
33362 | 614 |
} |
615 |
||
616 |
public void testNoArgument() { |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
617 |
String[] commands = {"/save", "/open", "/setstart"}; |
33362 | 618 |
test(Stream.of(commands) |
619 |
.map(cmd -> { |
|
620 |
String c = cmd; |
|
621 |
final String finalC = c; |
|
622 |
return (ReplTest) after -> assertCommand(after, cmd, |
|
623 |
"| The " + finalC + " command requires a filename argument.\n"); |
|
624 |
}) |
|
625 |
.toArray(ReplTest[]::new)); |
|
626 |
} |
|
627 |
||
628 |
public void testStartSave() throws IOException { |
|
629 |
Compiler compiler = new Compiler(); |
|
630 |
Path startSave = compiler.getPath("startSave.txt"); |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
631 |
test(a -> assertCommand(a, "/save start " + startSave.toString(), null)); |
33362 | 632 |
List<String> lines = Files.lines(startSave) |
633 |
.filter(s -> !s.isEmpty()) |
|
634 |
.collect(Collectors.toList()); |
|
635 |
assertEquals(lines, Arrays.asList( |
|
636 |
"import java.util.*;", |
|
637 |
"import java.io.*;", |
|
638 |
"import java.math.*;", |
|
639 |
"import java.net.*;", |
|
640 |
"import java.util.concurrent.*;", |
|
641 |
"import java.util.prefs.*;", |
|
642 |
"import java.util.regex.*;", |
|
643 |
"void printf(String format, Object... args) { System.out.printf(format, args); }")); |
|
644 |
} |
|
645 |
||
646 |
public void testConstrainedUpdates() { |
|
647 |
test( |
|
648 |
a -> assertClass(a, "class XYZZY { }", "class", "XYZZY"), |
|
649 |
a -> assertVariable(a, "XYZZY", "xyzzy"), |
|
650 |
a -> assertCommandCheckOutput(a, "import java.util.stream.*", |
|
651 |
(out) -> assertTrue(out.trim().isEmpty(), "Expected no output, got: " + out)) |
|
652 |
); |
|
653 |
} |
|
654 |
||
655 |
public void testRemoteExit() { |
|
656 |
test( |
|
657 |
a -> assertVariable(a, "int", "x"), |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
658 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
33362 | 659 |
a -> assertCommandCheckOutput(a, "System.exit(5);", s -> |
660 |
assertTrue(s.contains("terminated"), s)), |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
661 |
a -> assertCommandCheckOutput(a, "/vars", s -> |
33362 | 662 |
assertTrue(s.trim().isEmpty(), s)), |
663 |
a -> assertMethod(a, "void f() { }", "()void", "f"), |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
664 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
33362 | 665 |
); |
666 |
} |
|
667 |
||
668 |
public void testListArgs() { |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
669 |
Consumer<String> assertList = s -> assertTrue(s.split("\n").length >= 4, s); |
33362 | 670 |
String arg = "qqqq"; |
671 |
Consumer<String> assertError = s -> assertEquals(s, "| Invalid /list argument: " + arg + "\n"); |
|
672 |
test( |
|
673 |
a -> assertCommandCheckOutput(a, "/list all", assertList), |
|
674 |
a -> assertCommandCheckOutput(a, "/list " + arg, assertError), |
|
675 |
a -> assertVariable(a, "int", "a"), |
|
676 |
a -> assertCommandCheckOutput(a, "/list history", assertList) |
|
677 |
); |
|
678 |
} |
|
679 |
||
680 |
public void testFeedbackNegative() { |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
681 |
test(a -> assertCommandCheckOutput(a, "/feedback aaaa", |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
682 |
assertStartsWith("| Follow /feedback with of the following"))); |
33362 | 683 |
} |
684 |
||
685 |
public void testFeedbackOff() { |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
686 |
for (String off : new String[]{"o", "off"}) { |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
687 |
test( |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
688 |
a -> assertCommand(a, "/feedback " + off, ""), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
689 |
a -> assertCommand(a, "int a", ""), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
690 |
a -> assertCommand(a, "void f() {}", ""), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
691 |
a -> assertCommandCheckOutput(a, "aaaa", assertStartsWith("| Error:")), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
692 |
a -> assertCommandCheckOutput(a, "public void f() {}", assertStartsWith("| Warning:")) |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
693 |
); |
33362 | 694 |
} |
695 |
} |
|
696 |
||
697 |
public void testFeedbackConcise() { |
|
698 |
Compiler compiler = new Compiler(); |
|
699 |
Path testConciseFile = compiler.getPath("testConciseFeedback"); |
|
700 |
String[] sources = new String[] {"int a", "void f() {}", "class A {}", "a = 10"}; |
|
701 |
compiler.writeToFile(testConciseFile, sources); |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
702 |
for (String concise : new String[]{"c", "concise"}) { |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
703 |
test( |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
704 |
a -> assertCommand(a, "/feedback " + concise, ""), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
705 |
a -> assertCommand(a, sources[0], ""), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
706 |
a -> assertCommand(a, sources[1], ""), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
707 |
a -> assertCommand(a, sources[2], ""), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
708 |
a -> assertCommand(a, sources[3], "| a : 10\n"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
709 |
a -> assertCommand(a, "/o " + testConciseFile.toString(), "| a : 10\n") |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
710 |
); |
33362 | 711 |
} |
712 |
} |
|
713 |
||
714 |
public void testFeedbackNormal() { |
|
715 |
Compiler compiler = new Compiler(); |
|
716 |
Path testNormalFile = compiler.getPath("testConciseNormal"); |
|
717 |
String[] sources = new String[] {"int a", "void f() {}", "class A {}", "a = 10"}; |
|
718 |
String[] sources2 = new String[] {"int a //again", "void f() {int y = 4;}", "class A {} //again", "a = 10"}; |
|
719 |
String[] output = new String[] { |
|
720 |
"| Added variable a of type int\n", |
|
721 |
"| Added method f()\n", |
|
722 |
"| Added class A\n", |
|
723 |
"| Variable a has been assigned the value 10\n" |
|
724 |
}; |
|
725 |
compiler.writeToFile(testNormalFile, sources2); |
|
726 |
for (String feedback : new String[]{"/f", "/feedback"}) { |
|
727 |
for (String feedbackState : new String[]{"n", "normal", "v", "verbose"}) { |
|
728 |
String f = null; |
|
729 |
if (feedbackState.startsWith("n")) { |
|
730 |
f = "normal"; |
|
731 |
} else if (feedbackState.startsWith("v")) { |
|
732 |
f = "verbose"; |
|
733 |
} |
|
734 |
final String finalF = f; |
|
735 |
test( |
|
736 |
a -> assertCommand(a, feedback + " " + feedbackState, "| Feedback mode: " + finalF +"\n"), |
|
737 |
a -> assertCommand(a, sources[0], output[0]), |
|
738 |
a -> assertCommand(a, sources[1], output[1]), |
|
739 |
a -> assertCommand(a, sources[2], output[2]), |
|
740 |
a -> assertCommand(a, sources[3], output[3]), |
|
741 |
a -> assertCommand(a, "/o " + testNormalFile.toString(), |
|
742 |
"| Modified variable a of type int\n" + |
|
743 |
"| Modified method f()\n" + |
|
744 |
"| Update overwrote method f()\n" + |
|
745 |
"| Modified class A\n" + |
|
746 |
"| Update overwrote class A\n" + |
|
747 |
"| Variable a has been assigned the value 10\n") |
|
748 |
); |
|
749 |
} |
|
750 |
} |
|
751 |
} |
|
752 |
||
753 |
public void testFeedbackDefault() { |
|
754 |
Compiler compiler = new Compiler(); |
|
755 |
Path testDefaultFile = compiler.getPath("testDefaultFeedback"); |
|
756 |
String[] sources = new String[] {"int a", "void f() {}", "class A {}", "a = 10"}; |
|
757 |
String[] output = new String[] { |
|
758 |
"| Added variable a of type int\n", |
|
759 |
"| Added method f()\n", |
|
760 |
"| Added class A\n", |
|
761 |
"| Variable a has been assigned the value 10\n" |
|
762 |
}; |
|
763 |
compiler.writeToFile(testDefaultFile, sources); |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
764 |
for (String defaultFeedback : new String[]{"", "d", "default"}) { |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
765 |
test( |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
766 |
a -> assertCommand(a, "/feedback o", ""), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
767 |
a -> assertCommand(a, "int x", ""), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
768 |
a -> assertCommand(a, "/feedback " + defaultFeedback, "| Feedback mode: default\n"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
769 |
a -> assertCommand(a, sources[0], output[0]), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
770 |
a -> assertCommand(a, sources[1], output[1]), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
771 |
a -> assertCommand(a, sources[2], output[2]), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
772 |
a -> assertCommand(a, sources[3], output[3]), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
773 |
a -> assertCommand(a, "/o " + testDefaultFile.toString(), "") |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
774 |
); |
33362 | 775 |
} |
776 |
} |
|
777 |
||
778 |
public void testDrop() { |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
779 |
test(false, new String[]{"-nostartup"}, |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
780 |
a -> assertVariable(a, "int", "a"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
781 |
a -> dropVariable(a, "/drop 1", "int a = 0"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
782 |
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
783 |
a -> dropMethod(a, "/drop 2", "b ()I"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
784 |
a -> assertClass(a, "class A {}", "class", "A"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
785 |
a -> dropClass(a, "/drop 3", "class A"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
786 |
a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
787 |
a -> dropImport(a, "/drop 4", "import java.util.stream.*"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
788 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
789 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
790 |
a -> assertCommandCheckOutput(a, "/classes", assertClasses()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
791 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
792 |
); |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
793 |
test(false, new String[]{"-nostartup"}, |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
794 |
a -> assertVariable(a, "int", "a"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
795 |
a -> dropVariable(a, "/drop a", "int a = 0"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
796 |
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
797 |
a -> dropMethod(a, "/drop b", "b ()I"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
798 |
a -> assertClass(a, "class A {}", "class", "A"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
799 |
a -> dropClass(a, "/drop A", "class A"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
800 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
801 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
802 |
a -> assertCommandCheckOutput(a, "/classes", assertClasses()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
803 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
804 |
); |
33362 | 805 |
} |
806 |
||
807 |
public void testDropNegative() { |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
808 |
test(false, new String[]{"-nostartup"}, |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
809 |
a -> assertCommand(a, "/drop 0", "| No definition or id named 0 found. See /classes /methods /vars or /list\n"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
810 |
a -> assertCommand(a, "/drop a", "| No definition or id named a found. See /classes /methods /vars or /list\n"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
811 |
a -> assertCommandCheckOutput(a, "/drop", |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
812 |
assertStartsWith("| In the /drop argument, please specify an import, variable, method, or class to drop.")), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
813 |
a -> assertVariable(a, "int", "a"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
814 |
a -> assertCommand(a, "a", "| Variable a of type int has value 0\n"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
815 |
a -> assertCommand(a, "/drop 2", "| The argument did not specify an import, variable, method, or class to drop.\n") |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
816 |
); |
33362 | 817 |
} |
818 |
||
819 |
public void testAmbiguousDrop() { |
|
820 |
Consumer<String> check = s -> { |
|
821 |
assertTrue(s.startsWith("| The argument references more than one import, variable, method, or class"), s); |
|
822 |
int lines = s.split("\n").length; |
|
823 |
assertEquals(lines, 5, "Expected 3 ambiguous keys, but found: " + (lines - 2) + "\n" + s); |
|
824 |
}; |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
825 |
test( |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
826 |
a -> assertVariable(a, "int", "a"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
827 |
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
828 |
a -> assertClass(a, "class a {}", "class", "a"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
829 |
a -> assertCommandCheckOutput(a, "/drop a", check), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
830 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
831 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
832 |
a -> assertCommandCheckOutput(a, "/classes", assertClasses()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
833 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
834 |
); |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
835 |
test( |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
836 |
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
837 |
a -> assertMethod(a, "double a(int a) { return 0; }", "(int)double", "a"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
838 |
a -> assertMethod(a, "double a(double a) { return 0; }", "(double)double", "a"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
839 |
a -> assertCommandCheckOutput(a, "/drop a", check), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
840 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
841 |
); |
33362 | 842 |
} |
843 |
||
844 |
public void testHistoryReference() { |
|
845 |
test(false, new String[]{"-nostartup"}, |
|
846 |
a -> assertCommand(a, "System.err.println(1)", "", "", null, "", "1\n"), |
|
847 |
a -> assertCommand(a, "System.err.println(2)", "", "", null, "", "2\n"), |
|
848 |
a -> assertCommand(a, "/-2", "System.err.println(1)\n", "", null, "", "1\n"), |
|
849 |
a -> assertCommand(a, "/history", "\n" + |
|
850 |
"/debug 0\n" + |
|
851 |
"System.err.println(1)\n" + |
|
852 |
"System.err.println(2)\n" + |
|
853 |
"System.err.println(1)\n" + |
|
854 |
"/history\n"), |
|
855 |
a -> assertCommand(a, "/-2", "System.err.println(2)\n", "", null, "", "2\n"), |
|
856 |
a -> assertCommand(a, "/!", "System.err.println(2)\n", "", null, "", "2\n"), |
|
857 |
a -> assertCommand(a, "/2", "System.err.println(2)\n", "", null, "", "2\n"), |
|
858 |
a -> assertCommand(a, "/1", "System.err.println(1)\n", "", null, "", "1\n") |
|
859 |
); |
|
860 |
} |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
861 |
|
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
862 |
public void testCommandPrefix() { |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
863 |
test(a -> assertCommandCheckOutput(a, "/s", |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
864 |
assertStartsWith("| Command: /s is ambiguous: /seteditor, /save, /setstart")), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
865 |
a -> assertCommand(a, "int var", "| Added variable var of type int\n"), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
866 |
a -> assertCommandCheckOutput(a, "/va", |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
867 |
assertStartsWith("| int var = 0")), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
868 |
a -> assertCommandCheckOutput(a, "/save", |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
869 |
assertStartsWith("| The /save command requires a filename argument."))); |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
870 |
} |
33362 | 871 |
} |