author | rfield |
Thu, 18 May 2017 14:16:25 -0700 | |
changeset 45215 | c9477e22877f |
parent 44065 | d0a8a4c41c85 |
child 45757 | 1017cd5d6506 |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
33362 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
26 |
* @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649 8167643 8170162 8172102 8165405 8174796 8174797 8175304 8167554 8180508 |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36718
diff
changeset
|
27 |
* @summary Tests for Basic tests for REPL tool |
37389 | 28 |
* @modules jdk.compiler/com.sun.tools.javac.api |
29 |
* jdk.compiler/com.sun.tools.javac.main |
|
30 |
* jdk.jdeps/com.sun.tools.javap |
|
31 |
* jdk.jshell/jdk.internal.jshell.tool |
|
34570
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
34481
diff
changeset
|
32 |
* @library /tools/lib |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36718
diff
changeset
|
33 |
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36718
diff
changeset
|
34 |
* @build KullaTesting TestingInputStream Compiler |
35002 | 35 |
* @run testng/timeout=600 ToolBasicTest |
33362 | 36 |
*/ |
37 |
||
43856
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
38 |
import java.io.File; |
33362 | 39 |
import java.io.IOException; |
40 |
import java.io.PrintWriter; |
|
41 |
import java.io.StringWriter; |
|
42 |
import java.nio.file.Files; |
|
43 |
import java.nio.file.Path; |
|
44 |
import java.nio.file.Paths; |
|
45 |
import java.util.ArrayList; |
|
46 |
import java.util.Arrays; |
|
47 |
import java.util.List; |
|
36990 | 48 |
import java.util.Locale; |
33362 | 49 |
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
|
50 |
import java.util.function.BiFunction; |
33362 | 51 |
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
|
52 |
import java.util.function.Function; |
33362 | 53 |
import java.util.stream.Collectors; |
54 |
import java.util.stream.Stream; |
|
55 |
||
56 |
import org.testng.annotations.Test; |
|
57 |
||
58 |
import static org.testng.Assert.assertEquals; |
|
59 |
import static org.testng.Assert.assertTrue; |
|
60 |
import static org.testng.Assert.fail; |
|
61 |
||
62 |
@Test |
|
63 |
public class ToolBasicTest extends ReplToolTesting { |
|
64 |
||
65 |
public void elideStartUpFromList() { |
|
66 |
test( |
|
38613 | 67 |
(a) -> assertCommandOutputContains(a, "123", "==> 123"), |
33362 | 68 |
(a) -> assertCommandCheckOutput(a, "/list", (s) -> { |
69 |
int cnt; |
|
70 |
try (Scanner scanner = new Scanner(s)) { |
|
71 |
cnt = 0; |
|
72 |
while (scanner.hasNextLine()) { |
|
73 |
String line = scanner.nextLine(); |
|
74 |
if (!line.trim().isEmpty()) { |
|
75 |
++cnt; |
|
76 |
} |
|
77 |
} |
|
78 |
} |
|
79 |
assertEquals(cnt, 1, "Expected only one listed line"); |
|
80 |
}) |
|
81 |
); |
|
82 |
} |
|
83 |
||
84 |
public void elideStartUpFromSave() throws IOException { |
|
85 |
Compiler compiler = new Compiler(); |
|
86 |
Path path = compiler.getPath("myfile"); |
|
87 |
test( |
|
38613 | 88 |
(a) -> assertCommandOutputContains(a, "123", "==> 123"), |
33362 | 89 |
(a) -> assertCommand(a, "/save " + path.toString(), "") |
90 |
); |
|
91 |
try (Stream<String> lines = Files.lines(path)) { |
|
92 |
assertEquals(lines.count(), 1, "Expected only one saved line"); |
|
93 |
} |
|
94 |
} |
|
95 |
||
96 |
public void testInterrupt() { |
|
97 |
ReplTest interrupt = (a) -> assertCommand(a, "\u0003", ""); |
|
98 |
for (String s : new String[] { "", "\u0003" }) { |
|
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
40516
diff
changeset
|
99 |
test(false, new String[]{"--no-startup"}, |
33362 | 100 |
(a) -> assertCommand(a, "int a = 2 +" + s, ""), |
101 |
interrupt, |
|
102 |
(a) -> assertCommand(a, "int a\u0003", ""), |
|
103 |
(a) -> assertCommand(a, "int a = 2 + 2\u0003", ""), |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
104 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
33362 | 105 |
(a) -> evaluateExpression(a, "int", "2", "2"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
106 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
33362 | 107 |
(a) -> assertCommand(a, "void f() {", ""), |
108 |
(a) -> assertCommand(a, "int q = 10;" + s, ""), |
|
109 |
interrupt, |
|
110 |
(a) -> assertCommand(a, "void f() {}\u0003", ""), |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
111 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
33362 | 112 |
(a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
113 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
33362 | 114 |
(a) -> assertCommand(a, "class A {" + s, ""), |
115 |
interrupt, |
|
116 |
(a) -> assertCommand(a, "class A {}\u0003", ""), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37389
diff
changeset
|
117 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
33362 | 118 |
(a) -> assertClass(a, "interface A {}", "interface", "A"), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37389
diff
changeset
|
119 |
(a) -> assertCommandCheckOutput(a, "/types", 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
|
120 |
(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
|
121 |
interrupt, |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
122 |
(a) -> assertCommand(a, "import java.util.stream.\u0003", ""), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
123 |
(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
|
124 |
(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
|
125 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()) |
33362 | 126 |
); |
127 |
} |
|
128 |
} |
|
129 |
||
130 |
private final Object lock = new Object(); |
|
131 |
private PrintWriter out; |
|
132 |
private boolean isStopped; |
|
133 |
private Thread t; |
|
134 |
private void assertStop(boolean after, String cmd, String output) { |
|
135 |
if (!after) { |
|
136 |
isStopped = false; |
|
137 |
StringWriter writer = new StringWriter(); |
|
138 |
out = new PrintWriter(writer); |
|
139 |
setCommandInput(cmd + "\n"); |
|
140 |
t = new Thread(() -> { |
|
141 |
try { |
|
142 |
// no chance to know whether cmd is being evaluated |
|
143 |
Thread.sleep(5000); |
|
144 |
} catch (InterruptedException ignored) { |
|
145 |
} |
|
146 |
int i = 1; |
|
147 |
int n = 30; |
|
148 |
synchronized (lock) { |
|
149 |
do { |
|
150 |
setCommandInput("\u0003"); |
|
151 |
if (!isStopped) { |
|
152 |
out.println("Not stopped. Try again: " + i); |
|
153 |
try { |
|
154 |
lock.wait(1000); |
|
155 |
} catch (InterruptedException ignored) { |
|
156 |
} |
|
157 |
} |
|
158 |
} while (i++ < n && !isStopped); |
|
159 |
if (!isStopped) { |
|
160 |
System.err.println(writer.toString()); |
|
161 |
fail("Evaluation was not stopped: '" + cmd + "'"); |
|
162 |
} |
|
163 |
} |
|
164 |
}); |
|
165 |
t.start(); |
|
166 |
} else { |
|
167 |
synchronized (lock) { |
|
168 |
out.println("Evaluation was stopped successfully: '" + cmd + "'"); |
|
169 |
isStopped = true; |
|
170 |
lock.notify(); |
|
171 |
} |
|
172 |
try { |
|
173 |
t.join(); |
|
174 |
t = null; |
|
175 |
} catch (InterruptedException ignored) { |
|
176 |
} |
|
177 |
assertOutput(getCommandOutput(), "", "command"); |
|
178 |
assertOutput(getCommandErrorOutput(), "", "command error"); |
|
37389 | 179 |
assertOutput(getUserOutput().trim(), output, "user"); |
33362 | 180 |
assertOutput(getUserErrorOutput(), "", "user error"); |
181 |
} |
|
182 |
} |
|
183 |
||
184 |
public void testStop() { |
|
185 |
test( |
|
38613 | 186 |
(a) -> assertStop(a, "while (true) {}", ""), |
187 |
(a) -> assertStop(a, "while (true) { try { Thread.sleep(100); } catch (InterruptedException ex) { } }", "") |
|
33362 | 188 |
); |
189 |
} |
|
190 |
||
191 |
public void testRerun() { |
|
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
40516
diff
changeset
|
192 |
test(false, new String[] {"--no-startup"}, |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
193 |
(a) -> assertCommand(a, "/0", "| No snippet with id: 0"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
194 |
(a) -> assertCommand(a, "/5", "| No snippet with id: 5") |
33362 | 195 |
); |
196 |
String[] codes = new String[] { |
|
197 |
"int a = 0;", // var |
|
198 |
"class A {}", // class |
|
199 |
"void f() {}", // method |
|
200 |
"bool b;", // active failed |
|
201 |
"void g() { h(); }", // active corralled |
|
202 |
}; |
|
203 |
List<ReplTest> tests = new ArrayList<>(); |
|
204 |
for (String s : codes) { |
|
205 |
tests.add((a) -> assertCommand(a, s, null)); |
|
206 |
} |
|
38613 | 207 |
// Test /1 through /5 -- assure references are correct |
33362 | 208 |
for (int i = 0; i < codes.length; ++i) { |
209 |
final int finalI = i; |
|
210 |
Consumer<String> check = (s) -> { |
|
211 |
String[] ss = s.split("\n"); |
|
212 |
assertEquals(ss[0], codes[finalI]); |
|
213 |
assertTrue(ss.length > 1, s); |
|
214 |
}; |
|
215 |
tests.add((a) -> assertCommandCheckOutput(a, "/" + (finalI + 1), check)); |
|
216 |
} |
|
38613 | 217 |
// Test /-1 ... note that the snippets added by history must be stepped over |
33362 | 218 |
for (int i = 0; i < codes.length; ++i) { |
219 |
final int finalI = i; |
|
220 |
Consumer<String> check = (s) -> { |
|
221 |
String[] ss = s.split("\n"); |
|
222 |
assertEquals(ss[0], codes[codes.length - finalI - 1]); |
|
223 |
assertTrue(ss.length > 1, s); |
|
224 |
}; |
|
38613 | 225 |
tests.add((a) -> assertCommandCheckOutput(a, "/-" + (2 * finalI + 1), check)); |
33362 | 226 |
} |
38613 | 227 |
tests.add((a) -> assertCommandCheckOutput(a, "/!", assertStartsWith("int a = 0;"))); |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
40516
diff
changeset
|
228 |
test(false, new String[]{"--no-startup"}, |
33362 | 229 |
tests.toArray(new ReplTest[tests.size()])); |
230 |
} |
|
231 |
||
34477
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
232 |
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
|
233 |
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
|
234 |
(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
|
235 |
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
|
236 |
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
|
237 |
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
|
238 |
}); |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
239 |
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
|
240 |
|
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
241 |
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
|
242 |
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
|
243 |
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
|
244 |
"void add(int n) { assertionCount += n; }"); |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
40516
diff
changeset
|
245 |
test(new String[]{"--startup", startup.toString()}, |
34477
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
246 |
(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
|
247 |
(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
|
248 |
(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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
); |
64001b0533a2
8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents:
34475
diff
changeset
|
253 |
|
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
40516
diff
changeset
|
254 |
test(false, new String[] {"--no-startup"}, |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
255 |
(a) -> assertCommand(a, "/s1", "| No snippet with id: s1"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
256 |
(a) -> assertCommand(a, "/1", "| No snippet with id: 1"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
257 |
(a) -> assertCommand(a, "/e1", "| No snippet with id: e1") |
33714
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
258 |
); |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
259 |
} |
8064f484590e
8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents:
33362
diff
changeset
|
260 |
|
33362 | 261 |
public void testClasspathDirectory() { |
262 |
Compiler compiler = new Compiler(); |
|
263 |
Path outDir = Paths.get("testClasspathDirectory"); |
|
264 |
compiler.compile(outDir, "package pkg; public class A { public String toString() { return \"A\"; } }"); |
|
265 |
Path classpath = compiler.getPath(outDir); |
|
266 |
test( |
|
43038 | 267 |
(a) -> assertCommand(a, "/env --class-path " + classpath, |
268 |
"| Setting new options and restoring state."), |
|
37389 | 269 |
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A") |
33362 | 270 |
); |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
40516
diff
changeset
|
271 |
test(new String[] { "--class-path", classpath.toString() }, |
37389 | 272 |
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A") |
33362 | 273 |
); |
274 |
} |
|
275 |
||
44065
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
276 |
public void testEnvInStartUp() { |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
277 |
Compiler compiler = new Compiler(); |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
278 |
Path outDir = Paths.get("testClasspathDirectory"); |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
279 |
compiler.compile(outDir, "package pkg; public class A { public String toString() { return \"A\"; } }"); |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
280 |
Path classpath = compiler.getPath(outDir); |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
281 |
Path sup = compiler.getPath("startup.jsh"); |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
282 |
compiler.writeToFile(sup, |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
283 |
"int xxx;\n" + |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
284 |
"/env -class-path " + classpath + "\n" + |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
285 |
"int aaa = 735;\n" |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
286 |
); |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
287 |
test( |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
288 |
(a) -> assertCommand(a, "/set start -retain " + sup, ""), |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
289 |
(a) -> assertCommand(a, "/reset", |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
290 |
"| Resetting state."), |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
291 |
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A"), |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
292 |
(a) -> assertCommand(a, "aaa", "aaa ==> 735") |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
293 |
); |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
294 |
test( |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
295 |
(a) -> assertCommandOutputContains(a, "/env", "--class-path"), |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
296 |
(a) -> assertCommandOutputContains(a, "xxx", "cannot find symbol", "variable xxx"), |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
297 |
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A"), |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
298 |
(a) -> assertCommand(a, "aaa", "aaa ==> 735") |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
299 |
); |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
300 |
} |
d0a8a4c41c85
8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents:
43856
diff
changeset
|
301 |
|
43856
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
302 |
private String makeSimpleJar() { |
33362 | 303 |
Compiler compiler = new Compiler(); |
304 |
Path outDir = Paths.get("testClasspathJar"); |
|
305 |
compiler.compile(outDir, "package pkg; public class A { public String toString() { return \"A\"; } }"); |
|
306 |
String jarName = "test.jar"; |
|
307 |
compiler.jar(outDir, jarName, "pkg/A.class"); |
|
43856
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
308 |
return compiler.getPath(outDir).resolve(jarName).toString(); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
309 |
} |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
310 |
|
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
311 |
public void testClasspathJar() { |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
312 |
String jarPath = makeSimpleJar(); |
33362 | 313 |
test( |
43038 | 314 |
(a) -> assertCommand(a, "/env --class-path " + jarPath, |
315 |
"| Setting new options and restoring state."), |
|
37389 | 316 |
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A") |
33362 | 317 |
); |
43856
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
318 |
test(new String[] { "--class-path", jarPath }, |
37389 | 319 |
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A") |
33362 | 320 |
); |
321 |
} |
|
322 |
||
43856
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
323 |
public void testClasspathUserHomeExpansion() { |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
324 |
String jarPath = makeSimpleJar(); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
325 |
String tilde = "~" + File.separator; |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
326 |
test( |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
327 |
(a) -> assertCommand(a, "/env --class-path " + tilde + "forblato", |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
328 |
"| File '" + System.getProperty("user.home") + File.separator |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
329 |
+ "forblato' for '--class-path' is not found."), |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
330 |
(a) -> assertCommand(a, "/env --class-path " + jarPath + File.pathSeparator |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
331 |
+ tilde + "forblato", |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
332 |
"| File '" + System.getProperty("user.home") + File.separator |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
333 |
+ "forblato' for '--class-path' is not found.") |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
334 |
); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
335 |
} |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
336 |
|
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
337 |
public void testBadClasspath() { |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
338 |
String jarPath = makeSimpleJar(); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
339 |
Compiler compiler = new Compiler(); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
340 |
Path t1 = compiler.getPath("whatever/thing.zip"); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
341 |
compiler.writeToFile(t1, ""); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
342 |
Path t2 = compiler.getPath("whatever/thing.jmod"); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
343 |
compiler.writeToFile(t2, ""); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
344 |
test( |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
345 |
(a) -> assertCommand(a, "/env --class-path " + t1.toString(), |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
346 |
"| Invalid '--class-path' argument: " + t1.toString()), |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
347 |
(a) -> assertCommand(a, "/env --class-path " + jarPath + File.pathSeparator + t1.toString(), |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
348 |
"| Invalid '--class-path' argument: " + t1.toString()), |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
349 |
(a) -> assertCommand(a, "/env --class-path " + t2.toString(), |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
350 |
"| Invalid '--class-path' argument: " + t2.toString()) |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
351 |
); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
352 |
} |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
353 |
|
41852
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
354 |
public void testModulePath() { |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
355 |
Compiler compiler = new Compiler(); |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
356 |
Path modsDir = Paths.get("mods"); |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
357 |
Path outDir = Paths.get("mods", "org.astro"); |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
358 |
compiler.compile(outDir, "package org.astro; public class World { public static String name() { return \"world\"; } }"); |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
359 |
compiler.compile(outDir, "module org.astro { exports org.astro; }"); |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
360 |
Path modsPath = compiler.getPath(modsDir); |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
361 |
test(new String[] { "--module-path", modsPath.toString(), "--add-modules", "org.astro" }, |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
362 |
(a) -> assertCommand(a, "import org.astro.World;", ""), |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
363 |
(a) -> evaluateExpression(a, "String", |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
364 |
"String.format(\"Greetings %s!\", World.name());", |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
365 |
"\"Greetings world!\"") |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
366 |
); |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
367 |
} |
448273b190ad
8166649: jshell tool: missing --add-modules and --module-path
rfield
parents:
41635
diff
changeset
|
368 |
|
43856
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
369 |
public void testModulePathUserHomeExpansion() { |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
370 |
String tilde = "~" + File.separatorChar; |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
371 |
test( |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
372 |
(a) -> assertCommand(a, "/env --module-path " + tilde + "snardugol", |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
373 |
"| File '" + System.getProperty("user.home") |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
374 |
+ File.separatorChar + "snardugol' for '--module-path' is not found.") |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
375 |
); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
376 |
} |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
377 |
|
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
378 |
public void testBadModulePath() { |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
379 |
Compiler compiler = new Compiler(); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
380 |
Path t1 = compiler.getPath("whatever/thing.zip"); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
381 |
compiler.writeToFile(t1, ""); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
382 |
test( |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
383 |
(a) -> assertCommand(a, "/env --module-path " + t1.toString(), |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
384 |
"| Invalid '--module-path' argument: " + t1.toString()) |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
385 |
); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
386 |
} |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43038
diff
changeset
|
387 |
|
33362 | 388 |
public void testStartupFileOption() { |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
389 |
Compiler compiler = new Compiler(); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
390 |
Path startup = compiler.getPath("StartupFileOption/startup.txt"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
391 |
compiler.writeToFile(startup, "class A { public String toString() { return \"A\"; } }"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
392 |
test(new String[]{"--startup", startup.toString()}, |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
393 |
(a) -> evaluateExpression(a, "A", "new A()", "A") |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
394 |
); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
395 |
test(new String[]{"--no-startup"}, |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42843
diff
changeset
|
396 |
(a) -> assertCommandCheckOutput(a, "Pattern.compile(\"x+\")", assertStartsWith("| Error:\n| cannot find symbol")) |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
397 |
); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
398 |
test( |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42843
diff
changeset
|
399 |
(a) -> assertCommand(a, "Pattern.compile(\"x+\")", "$1 ==> x+", "", null, "", "") |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
400 |
); |
33362 | 401 |
} |
402 |
||
403 |
public void testLoadingFromArgs() { |
|
404 |
Compiler compiler = new Compiler(); |
|
405 |
Path path = compiler.getPath("loading.repl"); |
|
406 |
compiler.writeToFile(path, "int a = 10; double x = 20; double a = 10;"); |
|
407 |
test(new String[] { path.toString() }, |
|
37389 | 408 |
(a) -> assertCommand(a, "x", "x ==> 20.0"), |
409 |
(a) -> assertCommand(a, "a", "a ==> 10.0") |
|
33362 | 410 |
); |
411 |
Path unknown = compiler.getPath("UNKNOWN.jar"); |
|
36990 | 412 |
test(Locale.ROOT, true, new String[]{unknown.toString()}, |
38613 | 413 |
"| File '" + unknown |
414 |
+ "' for 'jshell' is not found."); |
|
33362 | 415 |
} |
416 |
||
417 |
public void testReset() { |
|
418 |
test( |
|
37389 | 419 |
(a) -> assertReset(a, "/res"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
420 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
33362 | 421 |
(a) -> assertVariable(a, "int", "x"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
422 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
33362 | 423 |
(a) -> assertMethod(a, "void f() { }", "()void", "f"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
424 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
33362 | 425 |
(a) -> assertClass(a, "class A { }", "class", "A"), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37389
diff
changeset
|
426 |
(a) -> assertCommandCheckOutput(a, "/types", 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
|
427 |
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
428 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
33362 | 429 |
(a) -> assertReset(a, "/reset"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
430 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
431 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37389
diff
changeset
|
432 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
433 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()) |
33362 | 434 |
); |
435 |
} |
|
436 |
||
437 |
public void testOpen() { |
|
438 |
Compiler compiler = new Compiler(); |
|
439 |
Path path = compiler.getPath("testOpen.repl"); |
|
440 |
compiler.writeToFile(path, |
|
441 |
"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
|
442 |
"class A { public String toString() { return \"A\"; } }\nimport java.util.stream.*;"); |
33362 | 443 |
for (String s : new String[]{"/o", "/open"}) { |
444 |
test( |
|
445 |
(a) -> assertCommand(a, s + " " + path.toString(), ""), |
|
37389 | 446 |
(a) -> assertCommand(a, "a", "a ==> 10.0"), |
447 |
(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
|
448 |
(a) -> evaluateExpression(a, "long", "Stream.of(\"A\").count();", "1"), |
33362 | 449 |
(a) -> { |
450 |
loadVariable(a, "double", "x", "20.0", "20.0"); |
|
451 |
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
|
452 |
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
|
453 |
loadVariable(a, "long", "$8", "Stream.of(\"A\").count();", "1"); |
33362 | 454 |
loadClass(a, "class A { public String toString() { return \"A\"; } }", |
455 |
"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
|
456 |
loadImport(a, "import java.util.stream.*;", "", "java.util.stream.*"); |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37389
diff
changeset
|
457 |
assertCommandCheckOutput(a, "/types", assertClasses()); |
33362 | 458 |
}, |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
459 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
460 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
461 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()) |
33362 | 462 |
); |
463 |
Path unknown = compiler.getPath("UNKNOWN.repl"); |
|
464 |
test( |
|
465 |
(a) -> assertCommand(a, s + " " + unknown, |
|
37389 | 466 |
"| File '" + unknown + "' for '/open' is not found.") |
33362 | 467 |
); |
468 |
} |
|
469 |
} |
|
470 |
||
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42843
diff
changeset
|
471 |
public void testOpenResource() { |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42843
diff
changeset
|
472 |
test( |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42843
diff
changeset
|
473 |
(a) -> assertCommand(a, "/open PRINTING", ""), |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42843
diff
changeset
|
474 |
(a) -> assertCommandOutputContains(a, "/list", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42843
diff
changeset
|
475 |
"void println", "System.out.printf"), |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42843
diff
changeset
|
476 |
(a) -> assertCommand(a, "printf(\"%4.2f\", Math.PI)", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42843
diff
changeset
|
477 |
"", "", null, "3.14", "") |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42843
diff
changeset
|
478 |
); |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42843
diff
changeset
|
479 |
} |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42843
diff
changeset
|
480 |
|
33362 | 481 |
public void testSave() throws IOException { |
482 |
Compiler compiler = new Compiler(); |
|
483 |
Path path = compiler.getPath("testSave.repl"); |
|
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
484 |
{ |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
485 |
List<String> list = Arrays.asList( |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
486 |
"int a;", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
487 |
"class A { public String toString() { return \"A\"; } }" |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
488 |
); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
489 |
test( |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
490 |
(a) -> assertVariable(a, "int", "a"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
491 |
(a) -> assertCommand(a, "()", null, null, null, "", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
492 |
(a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
493 |
(a) -> assertCommand(a, "/save " + path.toString(), "") |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
494 |
); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
495 |
assertEquals(Files.readAllLines(path), list); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
496 |
} |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
497 |
{ |
33362 | 498 |
List<String> output = new ArrayList<>(); |
499 |
test( |
|
500 |
(a) -> assertCommand(a, "int a;", null), |
|
34570
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
34481
diff
changeset
|
501 |
(a) -> assertCommand(a, "()", null, null, null, "", ""), |
33362 | 502 |
(a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
503 |
(a) -> assertCommandCheckOutput(a, "/list -all", (out) -> |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
504 |
output.addAll(Stream.of(out.split("\n")) |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
505 |
.filter(str -> !str.isEmpty()) |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
506 |
.map(str -> str.substring(str.indexOf(':') + 2)) |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
507 |
.filter(str -> !str.startsWith("/")) |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
508 |
.collect(Collectors.toList()))), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
509 |
(a) -> assertCommand(a, "/save -all " + path.toString(), "") |
33362 | 510 |
); |
511 |
assertEquals(Files.readAllLines(path), output); |
|
512 |
} |
|
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
513 |
{ |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
514 |
List<String> output = new ArrayList<>(); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
515 |
test( |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
516 |
(a) -> assertCommand(a, "int a;", null), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
517 |
(a) -> assertCommand(a, "int b;", null), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
518 |
(a) -> assertCommand(a, "int c;", null), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
519 |
(a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
520 |
(a) -> assertCommandCheckOutput(a, "/list b c a A", (out) -> |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
521 |
output.addAll(Stream.of(out.split("\n")) |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
522 |
.filter(str -> !str.isEmpty()) |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
523 |
.map(str -> str.substring(str.indexOf(':') + 2)) |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
524 |
.filter(str -> !str.startsWith("/")) |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
525 |
.collect(Collectors.toList()))), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
526 |
(a) -> assertCommand(a, "/save 2-3 1 4 " + path.toString(), "") |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
527 |
); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
528 |
assertEquals(Files.readAllLines(path), output); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
529 |
} |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
530 |
{ |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
531 |
List<String> output = new ArrayList<>(); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
532 |
test( |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
533 |
(a) -> assertVariable(a, "int", "a"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
534 |
(a) -> assertCommand(a, "()", null, null, null, "", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
535 |
(a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
536 |
(a) -> assertCommandCheckOutput(a, "/history", (out) -> |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
537 |
output.addAll(Stream.of(out.split("\n")) |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
538 |
.filter(str -> !str.isEmpty()) |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
539 |
.collect(Collectors.toList()))), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
540 |
(a) -> assertCommand(a, "/save -history " + path.toString(), "") |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
541 |
); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
542 |
output.add("/save -history " + path.toString()); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
543 |
assertEquals(Files.readAllLines(path), output); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
544 |
} |
33362 | 545 |
} |
546 |
||
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
547 |
public void testStartRetain() { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
548 |
Compiler compiler = new Compiler(); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
549 |
Path startUpFile = compiler.getPath("startUp.txt"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
550 |
test( |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
551 |
(a) -> assertVariable(a, "int", "a"), |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
552 |
(a) -> assertVariable(a, "double", "b", "10", "10.0"), |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
553 |
(a) -> assertMethod(a, "void f() {}", "()V", "f"), |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
554 |
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
555 |
(a) -> assertCommand(a, "/save " + startUpFile.toString(), null), |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
556 |
(a) -> assertCommand(a, "/set start -retain " + startUpFile.toString(), null) |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
557 |
); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
558 |
Path unknown = compiler.getPath("UNKNOWN"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
559 |
test( |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
560 |
(a) -> assertCommandOutputStartsWith(a, "/set start -retain " + unknown.toString(), |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
561 |
"| File '" + unknown + "' for '/set start' is not found.") |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
562 |
); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
563 |
test(false, new String[0], |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
564 |
(a) -> { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
565 |
loadVariable(a, "int", "a"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
566 |
loadVariable(a, "double", "b", "10.0", "10.0"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
567 |
loadMethod(a, "void f() {}", "()void", "f"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
568 |
loadImport(a, "import java.util.stream.*;", "", "java.util.stream.*"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
569 |
assertCommandCheckOutput(a, "/types", assertClasses()); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
570 |
}, |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
571 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
572 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
573 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()) |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
41858
diff
changeset
|
574 |
); |
33362 | 575 |
} |
576 |
||
577 |
public void testStartSave() throws IOException { |
|
578 |
Compiler compiler = new Compiler(); |
|
579 |
Path startSave = compiler.getPath("startSave.txt"); |
|
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
580 |
test(a -> assertCommand(a, "/save -start " + startSave.toString(), null)); |
33362 | 581 |
List<String> lines = Files.lines(startSave) |
582 |
.filter(s -> !s.isEmpty()) |
|
583 |
.collect(Collectors.toList()); |
|
34570
8a8f52a733dd
8144095: jshell tool: normalize command parameter handling
rfield
parents:
34481
diff
changeset
|
584 |
assertEquals(lines, START_UP); |
33362 | 585 |
} |
586 |
||
587 |
public void testConstrainedUpdates() { |
|
588 |
test( |
|
589 |
a -> assertClass(a, "class XYZZY { }", "class", "XYZZY"), |
|
590 |
a -> assertVariable(a, "XYZZY", "xyzzy"), |
|
591 |
a -> assertCommandCheckOutput(a, "import java.util.stream.*", |
|
592 |
(out) -> assertTrue(out.trim().isEmpty(), "Expected no output, got: " + out)) |
|
593 |
); |
|
594 |
} |
|
595 |
||
596 |
public void testRemoteExit() { |
|
597 |
test( |
|
598 |
a -> assertVariable(a, "int", "x"), |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
599 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
36494 | 600 |
a -> assertCommandOutputContains(a, "System.exit(5);", "terminated"), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
601 |
a -> assertCommandCheckOutput(a, "/vars", s -> |
33362 | 602 |
assertTrue(s.trim().isEmpty(), s)), |
603 |
a -> assertMethod(a, "void f() { }", "()void", "f"), |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
604 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
33362 | 605 |
); |
606 |
} |
|
607 |
||
608 |
public void testFeedbackNegative() { |
|
36494 | 609 |
test(a -> assertCommandCheckOutput(a, "/set feedback aaaa", |
610 |
assertStartsWith("| Does not match any current feedback mode"))); |
|
33362 | 611 |
} |
612 |
||
37389 | 613 |
public void testFeedbackSilent() { |
614 |
for (String off : new String[]{"s", "silent"}) { |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
615 |
test( |
36494 | 616 |
a -> assertCommand(a, "/set feedback " + off, ""), |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
617 |
a -> assertCommand(a, "int a", ""), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
618 |
a -> assertCommand(a, "void f() {}", ""), |
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
619 |
a -> assertCommandCheckOutput(a, "aaaa", assertStartsWith("| Error:")), |
41858
5843b57ce3a6
8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents:
41852
diff
changeset
|
620 |
a -> assertCommandCheckOutput(a, "static void f() {}", assertStartsWith("| Warning:")) |
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
621 |
); |
33362 | 622 |
} |
623 |
} |
|
624 |
||
625 |
public void testFeedbackNormal() { |
|
626 |
Compiler compiler = new Compiler(); |
|
627 |
Path testNormalFile = compiler.getPath("testConciseNormal"); |
|
628 |
String[] sources = new String[] {"int a", "void f() {}", "class A {}", "a = 10"}; |
|
629 |
String[] sources2 = new String[] {"int a //again", "void f() {int y = 4;}", "class A {} //again", "a = 10"}; |
|
630 |
String[] output = new String[] { |
|
37389 | 631 |
"a ==> 0", |
632 |
"| created method f()", |
|
633 |
"| created class A", |
|
634 |
"a ==> 10" |
|
33362 | 635 |
}; |
636 |
compiler.writeToFile(testNormalFile, sources2); |
|
37389 | 637 |
for (String feedback : new String[]{"/set fe", "/set feedback"}) { |
638 |
for (String feedbackState : new String[]{"n", "normal"}) { |
|
33362 | 639 |
test( |
37389 | 640 |
a -> assertCommand(a, feedback + " " + feedbackState, "| Feedback mode: normal"), |
33362 | 641 |
a -> assertCommand(a, sources[0], output[0]), |
642 |
a -> assertCommand(a, sources[1], output[1]), |
|
643 |
a -> assertCommand(a, sources[2], output[2]), |
|
644 |
a -> assertCommand(a, sources[3], output[3]), |
|
36494 | 645 |
a -> assertCommand(a, "/o " + testNormalFile.toString(), "") |
33362 | 646 |
); |
647 |
} |
|
648 |
} |
|
649 |
} |
|
650 |
||
40516
9e0e107c39dd
8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents:
38836
diff
changeset
|
651 |
public void testVarsWithNotActive() { |
9e0e107c39dd
8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents:
38836
diff
changeset
|
652 |
test( |
9e0e107c39dd
8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents:
38836
diff
changeset
|
653 |
a -> assertVariable(a, "Blath", "x"), |
9e0e107c39dd
8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents:
38836
diff
changeset
|
654 |
a -> assertCommandOutputContains(a, "/var -all", "(not-active)") |
9e0e107c39dd
8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents:
38836
diff
changeset
|
655 |
); |
9e0e107c39dd
8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents:
38836
diff
changeset
|
656 |
} |
9e0e107c39dd
8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents:
38836
diff
changeset
|
657 |
|
33362 | 658 |
public void testHistoryReference() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
40516
diff
changeset
|
659 |
test(false, new String[]{"--no-startup"}, |
33362 | 660 |
a -> assertCommand(a, "System.err.println(1)", "", "", null, "", "1\n"), |
661 |
a -> assertCommand(a, "System.err.println(2)", "", "", null, "", "2\n"), |
|
37389 | 662 |
a -> assertCommand(a, "/-2", "System.err.println(1)", "", null, "", "1\n"), |
663 |
a -> assertCommand(a, "/history", |
|
33362 | 664 |
"/debug 0\n" + |
665 |
"System.err.println(1)\n" + |
|
666 |
"System.err.println(2)\n" + |
|
667 |
"System.err.println(1)\n" + |
|
668 |
"/history\n"), |
|
37389 | 669 |
a -> assertCommand(a, "/-2", "System.err.println(2)", "", null, "", "2\n"), |
670 |
a -> assertCommand(a, "/!", "System.err.println(2)", "", null, "", "2\n"), |
|
671 |
a -> assertCommand(a, "/2", "System.err.println(2)", "", null, "", "2\n"), |
|
672 |
a -> assertCommand(a, "/1", "System.err.println(1)", "", null, "", "1\n") |
|
33362 | 673 |
); |
674 |
} |
|
34475
7af94fd75ede
8143037: JShell should determine commands by prefix
jlahoda
parents:
33918
diff
changeset
|
675 |
|
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
676 |
public void testRerunIdRange() { |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
677 |
Compiler compiler = new Compiler(); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
678 |
Path startup = compiler.getPath("rangeStartup"); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
679 |
String[] startupSources = new String[] { |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
680 |
"boolean go = false", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
681 |
"void println(String s) { if (go) System.out.println(s); }", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
682 |
"void println(int i) { if (go) System.out.println(i); }", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
683 |
"println(\"s4\")", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
684 |
"println(\"s5\")", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
685 |
"println(\"s6\")" |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
686 |
}; |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
687 |
String[] sources = new String[] { |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
688 |
"frog", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
689 |
"go = true", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
690 |
"println(2)", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
691 |
"println(3)", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
692 |
"println(4)", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
693 |
"querty" |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
694 |
}; |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
695 |
compiler.writeToFile(startup, startupSources); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
696 |
test(false, new String[]{"--startup", startup.toString()}, |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
697 |
a -> assertCommandOutputStartsWith(a, sources[0], "| Error:"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
698 |
a -> assertCommand(a, sources[1], "go ==> true", "", null, "", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
699 |
a -> assertCommand(a, sources[2], "", "", null, "2\n", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
700 |
a -> assertCommand(a, sources[3], "", "", null, "3\n", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
701 |
a -> assertCommand(a, sources[4], "", "", null, "4\n", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
702 |
a -> assertCommandOutputStartsWith(a, sources[5], "| Error:"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
703 |
a -> assertCommand(a, "/3", "println(3)", "", null, "3\n", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
704 |
a -> assertCommand(a, "/s4", "println(\"s4\")", "", null, "s4\n", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
705 |
a -> assertCommandOutputStartsWith(a, "/e1", "frog\n| Error:"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
706 |
a -> assertCommand(a, "/2-4", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
707 |
"println(2)\nprintln(3)\nprintln(4)", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
708 |
"", null, "2\n3\n4\n", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
709 |
a -> assertCommand(a, "/s4-s6", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
710 |
startupSources[3] + "\n" +startupSources[4] + "\n" +startupSources[5], |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
711 |
"", null, "s4\ns5\ns6\n", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
712 |
a -> assertCommand(a, "/s4-4", null, |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
713 |
"", null, "s4\ns5\ns6\n2\n3\n4\n", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
714 |
a -> assertCommandCheckOutput(a, "/e1-e2", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
715 |
s -> { |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
716 |
assertTrue(s.trim().startsWith("frog\n| Error:"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
717 |
"Output: \'" + s + "' does not start with: " + "| Error:"); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
718 |
assertTrue(s.trim().lastIndexOf("| Error:") > 10, |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
719 |
"Output: \'" + s + "' does not have second: " + "| Error:"); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
720 |
}), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
721 |
a -> assertCommand(a, "/4 s4 2", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
722 |
"println(4)\nprintln(\"s4\")\nprintln(2)", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
723 |
"", null, "4\ns4\n2\n", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
724 |
a -> assertCommand(a, "/s5 2-4 3", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
725 |
"println(\"s5\")\nprintln(2)\nprintln(3)\nprintln(4)\nprintln(3)", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
726 |
"", null, "s5\n2\n3\n4\n3\n", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
727 |
a -> assertCommand(a, "/2 ff", "| No such snippet: ff"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
728 |
a -> assertCommand(a, "/4-2", "| End of snippet range less than start: 4 - 2"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
729 |
a -> assertCommand(a, "/s5-s3", "| End of snippet range less than start: s5 - s3"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
730 |
a -> assertCommand(a, "/4-s5", "| End of snippet range less than start: 4 - s5") |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
731 |
); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
732 |
} |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44065
diff
changeset
|
733 |
|
38836
b09d1cfbf28c
8131029: JShell: recover from VMConnection launch failure
rfield
parents:
38613
diff
changeset
|
734 |
@Test(enabled = false) // TODO 8158197 |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
735 |
public void testHeadlessEditPad() { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
736 |
String prevHeadless = System.getProperty("java.awt.headless"); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
737 |
try { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
738 |
System.setProperty("java.awt.headless", "true"); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
739 |
test( |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
740 |
(a) -> assertCommandOutputStartsWith(a, "/edit printf", "| Cannot launch editor -- unexpected exception:") |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
741 |
); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
742 |
} finally { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
743 |
System.setProperty("java.awt.headless", prevHeadless==null? "false" : prevHeadless); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
744 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
745 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
746 |
|
41248 | 747 |
public void testAddExports() { |
748 |
test(false, new String[]{"--no-startup"}, |
|
749 |
a -> assertCommandOutputStartsWith(a, "import jdk.internal.misc.VM;", "| Error:") |
|
750 |
); |
|
751 |
test(false, new String[]{"--no-startup", |
|
752 |
"-R--add-exports", "-Rjava.base/jdk.internal.misc=ALL-UNNAMED", |
|
753 |
"-C--add-exports", "-Cjava.base/jdk.internal.misc=ALL-UNNAMED"}, |
|
754 |
a -> assertImport(a, "import jdk.internal.misc.VM;", "", "jdk.internal.misc.VM"), |
|
755 |
a -> assertCommand(a, "System.err.println(VM.isBooted())", "", "", null, "", "true\n") |
|
756 |
); |
|
757 |
test(false, new String[]{"--no-startup", "--add-exports", "java.base/jdk.internal.misc"}, |
|
758 |
a -> assertImport(a, "import jdk.internal.misc.VM;", "", "jdk.internal.misc.VM"), |
|
759 |
a -> assertCommand(a, "System.err.println(VM.isBooted())", "", "", null, "", "true\n") |
|
760 |
); |
|
761 |
} |
|
762 |
||
33362 | 763 |
} |