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