author | rfield |
Thu, 26 May 2016 07:58:01 -0700 | |
changeset 38608 | 691b607bbcd6 |
parent 38539 | 71874886920f |
child 38835 | 37280d52d723 |
permissions | -rw-r--r-- |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
1 |
/* |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
4 |
* |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
8 |
* |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
13 |
* accompanied this code). |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
14 |
* |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
18 |
* |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
21 |
* questions. |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
22 |
*/ |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
23 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
24 |
/* |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
25 |
* @test |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
26 |
* @bug 8153716 8143955 8151754 8150382 8153920 8156910 |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
27 |
* @summary Simple jshell tool tests |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.api |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
29 |
* jdk.compiler/com.sun.tools.javac.main |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
30 |
* jdk.jdeps/com.sun.tools.javap |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
31 |
* jdk.jshell/jdk.internal.jshell.tool |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
32 |
* @build KullaTesting TestingInputStream |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
33 |
* @run testng ToolSimpleTest |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
34 |
*/ |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
35 |
import java.util.Arrays; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
36 |
import java.util.ArrayList; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
37 |
import java.util.List; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
38 |
import java.util.function.Consumer; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
39 |
import java.util.stream.Collectors; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
40 |
import java.util.stream.Stream; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
41 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
42 |
import org.testng.annotations.Test; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
43 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
44 |
import static org.testng.Assert.assertEquals; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
45 |
import static org.testng.Assert.assertTrue; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
46 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
47 |
@Test |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
48 |
public class ToolSimpleTest extends ReplToolTesting { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
49 |
|
37389 | 50 |
public void testRemaining() { |
51 |
test( |
|
52 |
(a) -> assertCommand(a, "int z; z =", "z ==> 0"), |
|
53 |
(a) -> assertCommand(a, "5", "z ==> 5"), |
|
54 |
(a) -> assertCommand(a, "/*nada*/; int q =", ""), |
|
55 |
(a) -> assertCommand(a, "77", "q ==> 77"), |
|
56 |
(a) -> assertCommand(a, "//comment;", ""), |
|
57 |
(a) -> assertCommand(a, "int v;", "v ==> 0"), |
|
58 |
(a) -> assertCommand(a, "int v; int c", |
|
59 |
"v ==> 0\n" + |
|
60 |
"c ==> 0") |
|
61 |
); |
|
62 |
} |
|
63 |
||
64 |
public void oneLineOfError() { |
|
65 |
test( |
|
66 |
(a) -> assertCommand(a, "12+", null), |
|
67 |
(a) -> assertCommandCheckOutput(a, " true", (s) -> |
|
68 |
assertTrue(s.contains("12+") && !s.contains("true"), "Output: '" + s + "'")) |
|
69 |
); |
|
70 |
} |
|
71 |
||
72 |
public void defineVariables() { |
|
73 |
test( |
|
74 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
75 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
76 |
(a) -> assertVariable(a, "int", "a"), |
|
77 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
78 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
79 |
(a) -> assertVariable(a, "double", "a", "1", "1.0"), |
|
80 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
81 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
82 |
(a) -> evaluateExpression(a, "double", "2 * a", "2.0"), |
|
83 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
84 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()) |
|
85 |
); |
|
86 |
} |
|
87 |
||
88 |
public void defineMethods() { |
|
89 |
test( |
|
90 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
91 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
92 |
(a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"), |
|
93 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
94 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
95 |
(a) -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"), |
|
96 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
97 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
98 |
(a) -> assertMethod(a, "void g() {}", "()void", "g"), |
|
99 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
100 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
|
101 |
); |
|
102 |
} |
|
103 |
||
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
104 |
public void defineTypes() { |
37389 | 105 |
test( |
106 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
107 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 108 |
(a) -> assertClass(a, "class A { }", "class", "A"), |
109 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
110 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 111 |
(a) -> assertClass(a, "interface A { }", "interface", "A"), |
112 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
113 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 114 |
(a) -> assertClass(a, "enum A { }", "enum", "A"), |
115 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
116 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 117 |
(a) -> assertClass(a, "@interface A { }", "@interface", "A"), |
118 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
119 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()) |
37389 | 120 |
); |
121 |
} |
|
122 |
||
123 |
public void defineImports() { |
|
124 |
test( |
|
125 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
126 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
127 |
(a) -> assertImport(a, "import java.util.stream.Stream;", "", "java.util.stream.Stream"), |
|
128 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
129 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
130 |
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
|
131 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
132 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
133 |
(a) -> assertImport(a, "import static java.lang.Math.PI;", "static", "java.lang.Math.PI"), |
|
134 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
135 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
136 |
(a) -> assertImport(a, "import static java.lang.Math.*;", "static", "java.lang.Math.*"), |
|
137 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
138 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()) |
|
139 |
); |
|
140 |
} |
|
141 |
||
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
142 |
public void defineVar() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
143 |
test( |
37389 | 144 |
(a) -> assertCommand(a, "int x = 72", "x ==> 72"), |
145 |
(a) -> assertCommand(a, "x", "x ==> 72"), |
|
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
146 |
(a) -> assertCommand(a, "/vars", "| int x = 72") |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
147 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
148 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
149 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
150 |
@Test(enabled = false) // TODO 8153897 |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
151 |
public void defineUnresolvedVar() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
152 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
153 |
(a) -> assertCommand(a, "undefined x", |
37389 | 154 |
"| created variable x, however, it cannot be referenced until class undefined is declared"), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
155 |
(a) -> assertCommand(a, "/vars", "| undefined x = (not-active)") |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
156 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
157 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
158 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
159 |
public void testUnresolved() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
160 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
161 |
(a) -> assertCommand(a, "int f() { return g() + x + new A().a; }", |
37389 | 162 |
"| created method f(), however, it cannot be invoked until method g(), variable x, and class A are declared"), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
163 |
(a) -> assertCommand(a, "f()", |
37389 | 164 |
"| attempted to call method f() which cannot be invoked until method g(), variable x, and class A are declared"), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
165 |
(a) -> assertCommandOutputStartsWith(a, "int g() { return x; }", |
37389 | 166 |
"| created method g(), however, it cannot be invoked until variable x is declared"), |
167 |
(a) -> assertCommand(a, "g()", "| attempted to call method g() which cannot be invoked until variable x is declared") |
|
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
168 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
169 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
170 |
|
37389 | 171 |
public void testUnknownCommand() { |
172 |
test((a) -> assertCommand(a, "/unknown", |
|
173 |
"| No such command or snippet id: /unknown\n" + |
|
174 |
"| Type /help for help.")); |
|
175 |
} |
|
176 |
||
177 |
public void testEmptyClassPath() { |
|
178 |
test(after -> assertCommand(after, "/classpath", "| The /classpath command requires a path argument.")); |
|
179 |
} |
|
180 |
||
181 |
public void testNoArgument() { |
|
38539 | 182 |
test( |
183 |
(a) -> assertCommand(a, "/save", |
|
184 |
"| '/save' requires a filename argument."), |
|
185 |
(a) -> assertCommand(a, "/open", |
|
186 |
"| '/open' requires a filename argument."), |
|
187 |
(a) -> assertCommand(a, "/set start", |
|
188 |
"| Specify either one option or a startup file name -- /set start") |
|
189 |
); |
|
37389 | 190 |
} |
191 |
||
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
192 |
public void testDebug() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
193 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
194 |
(a) -> assertCommand(a, "/deb", "| Debugging on"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
195 |
(a) -> assertCommand(a, "/debug", "| Debugging off"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
196 |
(a) -> assertCommand(a, "/debug", "| Debugging on"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
197 |
(a) -> assertCommand(a, "/deb", "| Debugging off") |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
198 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
199 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
200 |
|
37389 | 201 |
public void testDrop() { |
202 |
test(false, new String[]{"-nostartup"}, |
|
203 |
a -> assertVariable(a, "int", "a"), |
|
204 |
a -> dropVariable(a, "/drop 1", "int a = 0", "| dropped variable a"), |
|
205 |
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), |
|
206 |
a -> dropMethod(a, "/drop 2", "b ()I", "| dropped method b()"), |
|
207 |
a -> assertClass(a, "class A {}", "class", "A"), |
|
208 |
a -> dropClass(a, "/drop 3", "class A", "| dropped class A"), |
|
209 |
a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
|
210 |
a -> dropImport(a, "/drop 4", "import java.util.stream.*", ""), |
|
211 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
212 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
213 |
a -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 214 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
215 |
); |
|
216 |
test(false, new String[]{"-nostartup"}, |
|
217 |
a -> assertVariable(a, "int", "a"), |
|
218 |
a -> dropVariable(a, "/drop a", "int a = 0", "| dropped variable a"), |
|
219 |
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), |
|
220 |
a -> dropMethod(a, "/drop b", "b ()I", "| dropped method b()"), |
|
221 |
a -> assertClass(a, "class A {}", "class", "A"), |
|
222 |
a -> dropClass(a, "/drop A", "class A", "| dropped class A"), |
|
223 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
224 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
225 |
a -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 226 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
227 |
); |
|
228 |
} |
|
229 |
||
230 |
public void testDropNegative() { |
|
231 |
test(false, new String[]{"-nostartup"}, |
|
38539 | 232 |
a -> assertCommandOutputStartsWith(a, "/drop 0", "| No such snippet: 0"), |
233 |
a -> assertCommandOutputStartsWith(a, "/drop a", "| No such snippet: a"), |
|
37389 | 234 |
a -> assertCommandCheckOutput(a, "/drop", |
235 |
assertStartsWith("| In the /drop argument, please specify an import, variable, method, or class to drop.")), |
|
236 |
a -> assertVariable(a, "int", "a"), |
|
237 |
a -> assertCommand(a, "a", "a ==> 0"), |
|
38539 | 238 |
a -> assertCommand(a, "/drop 2", |
239 |
"| This command does not accept the snippet '2' : a\n" + |
|
240 |
"| See /types, /methods, /vars, or /list") |
|
37389 | 241 |
); |
242 |
} |
|
243 |
||
244 |
public void testAmbiguousDrop() { |
|
245 |
Consumer<String> check = s -> { |
|
246 |
assertTrue(s.startsWith("| The argument references more than one import, variable, method, or class"), s); |
|
247 |
int lines = s.split("\n").length; |
|
248 |
assertEquals(lines, 5, "Expected 3 ambiguous keys, but found: " + (lines - 2) + "\n" + s); |
|
249 |
}; |
|
250 |
test( |
|
251 |
a -> assertVariable(a, "int", "a"), |
|
252 |
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), |
|
253 |
a -> assertClass(a, "class a {}", "class", "a"), |
|
254 |
a -> assertCommandCheckOutput(a, "/drop a", check), |
|
255 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
256 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
257 |
a -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 258 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
259 |
); |
|
260 |
test( |
|
261 |
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), |
|
262 |
a -> assertMethod(a, "double a(int a) { return 0; }", "(int)double", "a"), |
|
263 |
a -> assertMethod(a, "double a(double a) { return 0; }", "(double)double", "a"), |
|
264 |
a -> assertCommandCheckOutput(a, "/drop a", check), |
|
265 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
|
266 |
); |
|
267 |
} |
|
268 |
||
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
269 |
public void testHelpLength() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
270 |
Consumer<String> testOutput = (s) -> { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
271 |
List<String> ss = Stream.of(s.split("\n")) |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
272 |
.filter(l -> !l.isEmpty()) |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
273 |
.collect(Collectors.toList()); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
274 |
assertTrue(ss.size() >= 10, "Help does not print enough lines:" + s); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
275 |
}; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
276 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
277 |
(a) -> assertCommandCheckOutput(a, "/?", testOutput), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
278 |
(a) -> assertCommandCheckOutput(a, "/help", testOutput), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
279 |
(a) -> assertCommandCheckOutput(a, "/help /list", testOutput) |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
280 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
281 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
282 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
283 |
public void testHelp() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
284 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
285 |
(a) -> assertHelp(a, "/?", "/list", "/help", "/exit", "intro"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
286 |
(a) -> assertHelp(a, "/help", "/list", "/help", "/exit", "intro"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
287 |
(a) -> assertHelp(a, "/help short", "shortcuts", "<tab>"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
288 |
(a) -> assertHelp(a, "/? /li", "/list -all", "snippets"), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
289 |
(a) -> assertHelp(a, "/help /help", "/help <command>") |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
290 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
291 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
292 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
293 |
private void assertHelp(boolean a, String command, String... find) { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
294 |
assertCommandCheckOutput(a, command, s -> { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
295 |
for (String f : find) { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
296 |
assertTrue(s.contains(f), "Expected output of " + command + " to contain: " + f); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
297 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
298 |
}); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
299 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
300 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
301 |
// Check that each line of output contains the corresponding string from the list |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
302 |
private void checkLineToList(String in, List<String> match) { |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
303 |
String trimmed = in.trim(); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
304 |
String[] res = trimmed.isEmpty() |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
305 |
? new String[0] |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
306 |
: trimmed.split("\n"); |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
307 |
assertEquals(res.length, match.size(), "Got: " + Arrays.asList(res)); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
308 |
for (int i = 0; i < match.size(); ++i) { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
309 |
assertTrue(res[i].contains(match.get(i))); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
310 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
311 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
312 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
313 |
public void testListArgs() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
314 |
String arg = "qqqq"; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
315 |
List<String> startVarList = new ArrayList<>(START_UP); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
316 |
startVarList.add("int aardvark"); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
317 |
test( |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
318 |
a -> assertCommandCheckOutput(a, "/list -all", |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
319 |
s -> checkLineToList(s, START_UP)), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
320 |
a -> assertCommandOutputStartsWith(a, "/list " + arg, |
38539 | 321 |
"| No such snippet: " + arg), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
322 |
a -> assertVariable(a, "int", "aardvark"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
323 |
a -> assertCommandOutputContains(a, "/list aardvark", "aardvark"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
324 |
a -> assertCommandCheckOutput(a, "/list -start", |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
325 |
s -> checkLineToList(s, START_UP)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
326 |
a -> assertCommandCheckOutput(a, "/list -all", |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
327 |
s -> checkLineToList(s, startVarList)), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
328 |
a -> assertCommandCheckOutput(a, "/list printf", |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
329 |
s -> assertTrue(s.contains("void printf"))), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
330 |
a -> assertCommandOutputStartsWith(a, "/list " + arg, |
38539 | 331 |
"| No such snippet: " + arg) |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
332 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
333 |
} |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
334 |
|
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
335 |
public void testVarsArgs() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
336 |
String arg = "qqqq"; |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
337 |
List<String> startVarList = new ArrayList<>(); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
338 |
test( |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
339 |
a -> assertCommandCheckOutput(a, "/vars -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
340 |
s -> checkLineToList(s, startVarList)), |
38539 | 341 |
a -> assertCommand(a, "/vars " + arg, |
342 |
"| No such snippet: " + arg), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
343 |
a -> assertVariable(a, "int", "aardvark"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
344 |
a -> assertMethod(a, "int f() { return 0; }", "()int", "f"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
345 |
a -> assertVariable(a, "int", "a"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
346 |
a -> assertVariable(a, "double", "a", "1", "1.0"), |
38539 | 347 |
a -> assertCommandOutputStartsWith(a, "/vars aardvark", |
348 |
"| int aardvark = 0"), |
|
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
349 |
a -> assertCommandCheckOutput(a, "/vars -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
350 |
s -> checkLineToList(s, startVarList)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
351 |
a -> assertCommandOutputStartsWith(a, "/vars -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
352 |
"| int aardvark = 0\n| int a = "), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
353 |
a -> assertCommandOutputStartsWith(a, "/vars printf", |
38539 | 354 |
"| This command does not accept the snippet 'printf'"), |
355 |
a -> assertCommand(a, "/var " + arg, |
|
356 |
"| No such snippet: " + arg) |
|
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
357 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
358 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
359 |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
360 |
public void testMethodsArgs() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
361 |
String arg = "qqqq"; |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
362 |
List<String> startMethodList = new ArrayList<>(START_UP_CMD_METHOD); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
363 |
test( |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
364 |
a -> assertCommandCheckOutput(a, "/methods -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
365 |
s -> checkLineToList(s, startMethodList)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
366 |
a -> assertCommandCheckOutput(a, "/methods -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
367 |
s -> checkLineToList(s, startMethodList)), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
368 |
a -> assertCommandCheckOutput(a, "/methods printf", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
369 |
s -> checkLineToList(s, startMethodList)), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
370 |
a -> assertCommandCheckOutput(a, "/methods", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
371 |
s -> checkLineToList(s, startMethodList)), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
372 |
a -> assertCommandOutputStartsWith(a, "/methods " + arg, |
38539 | 373 |
"| No such snippet: " + arg), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
374 |
a -> assertMethod(a, "int f() { return 0; }", "()int", "f"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
375 |
a -> assertVariable(a, "int", "aardvark"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
376 |
a -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
377 |
a -> assertMethod(a, "void g() {}", "()void", "g"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
378 |
a -> assertCommandOutputStartsWith(a, "/methods " + arg, |
38539 | 379 |
"| No such snippet: " + arg), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
380 |
a -> assertCommandOutputStartsWith(a, "/methods aardvark", |
38539 | 381 |
"| This command does not accept the snippet 'aardvark' : int aardvark"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
382 |
a -> assertCommandCheckOutput(a, "/methods -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
383 |
s -> checkLineToList(s, startMethodList)), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
384 |
a -> assertCommandCheckOutput(a, "/methods printf", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
385 |
s -> checkLineToList(s, startMethodList)), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
386 |
a -> assertCommandOutputStartsWith(a, "/methods g", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
387 |
"| g ()void"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
388 |
a -> assertCommandOutputStartsWith(a, "/methods f", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
389 |
"| f ()int\n" + |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
390 |
"| f (int)void") |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
391 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
392 |
} |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
393 |
|
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
394 |
public void testTypesArgs() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
395 |
String arg = "qqqq"; |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
396 |
List<String> startTypeList = new ArrayList<>(); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
397 |
test( |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
398 |
a -> assertCommandCheckOutput(a, "/types -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
399 |
s -> checkLineToList(s, startTypeList)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
400 |
a -> assertCommandCheckOutput(a, "/types -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
401 |
s -> checkLineToList(s, startTypeList)), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
402 |
a -> assertCommandOutputStartsWith(a, "/types " + arg, |
38539 | 403 |
"| No such snippet: " + arg), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
404 |
a -> assertVariable(a, "int", "aardvark"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
405 |
(a) -> assertClass(a, "class A { }", "class", "A"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
406 |
(a) -> assertClass(a, "interface A { }", "interface", "A"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
407 |
a -> assertCommandOutputStartsWith(a, "/types -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
408 |
"| class A\n" + |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
409 |
"| interface A"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
410 |
(a) -> assertClass(a, "enum E { }", "enum", "E"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
411 |
(a) -> assertClass(a, "@interface B { }", "@interface", "B"), |
38539 | 412 |
a -> assertCommand(a, "/types aardvark", |
413 |
"| This command does not accept the snippet 'aardvark' : int aardvark;"), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
414 |
a -> assertCommandOutputStartsWith(a, "/types A", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
415 |
"| interface A"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
416 |
a -> assertCommandOutputStartsWith(a, "/types E", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
417 |
"| enum E"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
418 |
a -> assertCommandOutputStartsWith(a, "/types B", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
419 |
"| @interface B"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
420 |
a -> assertCommandOutputStartsWith(a, "/types " + arg, |
38539 | 421 |
"| No such snippet: " + arg), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
422 |
a -> assertCommandCheckOutput(a, "/types -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
423 |
s -> checkLineToList(s, startTypeList)) |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
424 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
425 |
} |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
426 |
public void defineClasses() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
427 |
test( |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
428 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
429 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
430 |
(a) -> assertClass(a, "class A { }", "class", "A"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
431 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
432 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
433 |
(a) -> assertClass(a, "interface A { }", "interface", "A"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
434 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
435 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
436 |
(a) -> assertClass(a, "enum A { }", "enum", "A"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
437 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
438 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
439 |
(a) -> assertClass(a, "@interface A { }", "@interface", "A"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
440 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
441 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()) |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
442 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
443 |
} |
37389 | 444 |
public void testCommandPrefix() { |
445 |
test(a -> assertCommandCheckOutput(a, "/s", |
|
446 |
assertStartsWith("| Command: '/s' is ambiguous: /save, /set")), |
|
447 |
a -> assertCommand(a, "int var", "var ==> 0"), |
|
448 |
a -> assertCommandCheckOutput(a, "/va", |
|
449 |
assertStartsWith("| int var = 0")), |
|
450 |
a -> assertCommandCheckOutput(a, "/save", |
|
451 |
assertStartsWith("| '/save' requires a filename argument."))); |
|
452 |
} |
|
453 |
||
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
454 |
public void testOptionQ() { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
455 |
test(new String[]{"-q", "-nostartup"}, |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
456 |
(a) -> assertCommand(a, "1+1", "$1 ==> 2"), |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
457 |
(a) -> assertCommand(a, "int x = 5", "") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
458 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
459 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
460 |
|
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
461 |
public void testOptionQq() { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
462 |
test(new String[]{"-qq", "-nostartup"}, |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
463 |
(a) -> assertCommand(a, "1+1", "") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
464 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
465 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
466 |
|
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
467 |
public void testOptionV() { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
468 |
test(new String[]{"-v", "-nostartup"}, |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
469 |
(a) -> assertCommand(a, "1+1", |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
470 |
"$1 ==> 2\n" + |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
471 |
"| created scratch variable $1 : int") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
472 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
473 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
474 |
|
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
475 |
public void testOptionFeedback() { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
476 |
test(new String[]{"-feedback", "concise", "-nostartup"}, |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
477 |
(a) -> assertCommand(a, "1+1", "$1 ==> 2"), |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
478 |
(a) -> assertCommand(a, "int x = 5", "") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
479 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
480 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
481 |
|
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
482 |
public void testOptionR() { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
483 |
test(new String[]{"-R-Dthe.sound=blorp", "-nostartup"}, |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
484 |
(a) -> assertCommand(a, "System.getProperty(\"the.sound\")", |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
485 |
"$1 ==> \"blorp\"") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
486 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
487 |
} |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
488 |
|
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
489 |
public void test8156910() { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
490 |
test( |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
491 |
(a) -> assertCommandOutputContains(a, "System.out.println(\"%5d\", 10);", "%5d"), |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
492 |
(a) -> assertCommandOutputContains(a, "1234", "==> 1234") |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
493 |
); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
494 |
} |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
495 |
} |