author | rfield |
Mon, 02 Jan 2017 18:31:30 -0800 | |
changeset 42972 | 47ca49eee534 |
parent 42969 | a48d4f74d322 |
child 43038 | 7b8b8750a78e |
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 |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
26 |
* @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 |
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; |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
38 |
import java.util.Locale; |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
39 |
import java.util.function.Consumer; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
40 |
import java.util.stream.Collectors; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
41 |
import java.util.stream.Stream; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
42 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
43 |
import org.testng.annotations.Test; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
44 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
45 |
import static org.testng.Assert.assertEquals; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
46 |
import static org.testng.Assert.assertTrue; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
47 |
|
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 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
50 |
@Test |
37389 | 51 |
public void testRemaining() { |
52 |
test( |
|
53 |
(a) -> assertCommand(a, "int z; z =", "z ==> 0"), |
|
54 |
(a) -> assertCommand(a, "5", "z ==> 5"), |
|
55 |
(a) -> assertCommand(a, "/*nada*/; int q =", ""), |
|
56 |
(a) -> assertCommand(a, "77", "q ==> 77"), |
|
57 |
(a) -> assertCommand(a, "//comment;", ""), |
|
58 |
(a) -> assertCommand(a, "int v;", "v ==> 0"), |
|
59 |
(a) -> assertCommand(a, "int v; int c", |
|
60 |
"v ==> 0\n" + |
|
61 |
"c ==> 0") |
|
62 |
); |
|
63 |
} |
|
64 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
65 |
@Test |
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
66 |
public void testOpenComment() { |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
67 |
test( |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
68 |
(a) -> assertCommand(a, "int z = /* blah", ""), |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
69 |
(a) -> assertCommand(a, "baz */ 5", "z ==> 5"), |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
70 |
(a) -> assertCommand(a, "/** hoge ", ""), |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
71 |
(a) -> assertCommand(a, "baz **/", ""), |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
72 |
(a) -> assertCommand(a, "int v", "v ==> 0") |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
73 |
); |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
74 |
} |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
75 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
76 |
@Test |
37389 | 77 |
public void oneLineOfError() { |
78 |
test( |
|
79 |
(a) -> assertCommand(a, "12+", null), |
|
80 |
(a) -> assertCommandCheckOutput(a, " true", (s) -> |
|
81 |
assertTrue(s.contains("12+") && !s.contains("true"), "Output: '" + s + "'")) |
|
82 |
); |
|
83 |
} |
|
84 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
85 |
@Test |
37389 | 86 |
public void defineVariables() { |
87 |
test( |
|
88 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
89 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
90 |
(a) -> assertVariable(a, "int", "a"), |
|
91 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
92 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
93 |
(a) -> assertVariable(a, "double", "a", "1", "1.0"), |
|
94 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
95 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
96 |
(a) -> evaluateExpression(a, "double", "2 * a", "2.0"), |
|
97 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
98 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()) |
|
99 |
); |
|
100 |
} |
|
101 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
102 |
@Test |
37389 | 103 |
public void defineMethods() { |
104 |
test( |
|
105 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
106 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
107 |
(a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"), |
|
108 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
109 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
110 |
(a) -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"), |
|
111 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
112 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
113 |
(a) -> assertMethod(a, "void g() {}", "()void", "g"), |
|
114 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
115 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
|
116 |
); |
|
117 |
} |
|
118 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
119 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
120 |
public void defineTypes() { |
37389 | 121 |
test( |
122 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
123 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 124 |
(a) -> assertClass(a, "class A { }", "class", "A"), |
125 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
126 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 127 |
(a) -> assertClass(a, "interface A { }", "interface", "A"), |
128 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
129 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 130 |
(a) -> assertClass(a, "enum A { }", "enum", "A"), |
131 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
132 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 133 |
(a) -> assertClass(a, "@interface A { }", "@interface", "A"), |
134 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
135 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()) |
37389 | 136 |
); |
137 |
} |
|
138 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
139 |
@Test |
37389 | 140 |
public void defineImports() { |
141 |
test( |
|
142 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
143 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
144 |
(a) -> assertImport(a, "import java.util.stream.Stream;", "", "java.util.stream.Stream"), |
|
145 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
146 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
147 |
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
|
148 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
149 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
150 |
(a) -> assertImport(a, "import static java.lang.Math.PI;", "static", "java.lang.Math.PI"), |
|
151 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
152 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
153 |
(a) -> assertImport(a, "import static java.lang.Math.*;", "static", "java.lang.Math.*"), |
|
154 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
155 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()) |
|
156 |
); |
|
157 |
} |
|
158 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
159 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
160 |
public void defineVar() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
161 |
test( |
37389 | 162 |
(a) -> assertCommand(a, "int x = 72", "x ==> 72"), |
163 |
(a) -> assertCommand(a, "x", "x ==> 72"), |
|
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
164 |
(a) -> assertCommand(a, "/vars", "| int x = 72") |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
165 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
166 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
167 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
168 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
169 |
public void defineUnresolvedVar() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
170 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
171 |
(a) -> assertCommand(a, "undefined x", |
37389 | 172 |
"| 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
|
173 |
(a) -> assertCommand(a, "/vars", "| undefined x = (not-active)") |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
174 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
175 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
176 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
177 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
178 |
public void testUnresolved() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
179 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
180 |
(a) -> assertCommand(a, "int f() { return g() + x + new A().a; }", |
37389 | 181 |
"| 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
|
182 |
(a) -> assertCommand(a, "f()", |
37389 | 183 |
"| 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
|
184 |
(a) -> assertCommandOutputStartsWith(a, "int g() { return x; }", |
37389 | 185 |
"| created method g(), however, it cannot be invoked until variable x is declared"), |
186 |
(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
|
187 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
188 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
189 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
190 |
@Test |
37389 | 191 |
public void testUnknownCommand() { |
192 |
test((a) -> assertCommand(a, "/unknown", |
|
193 |
"| No such command or snippet id: /unknown\n" + |
|
194 |
"| Type /help for help.")); |
|
195 |
} |
|
196 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
197 |
@Test |
37389 | 198 |
public void testEmptyClassPath() { |
199 |
test(after -> assertCommand(after, "/classpath", "| The /classpath command requires a path argument.")); |
|
200 |
} |
|
201 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
202 |
@Test |
37389 | 203 |
public void testNoArgument() { |
38539 | 204 |
test( |
205 |
(a) -> assertCommand(a, "/save", |
|
206 |
"| '/save' requires a filename argument."), |
|
207 |
(a) -> assertCommand(a, "/open", |
|
208 |
"| '/open' requires a filename argument."), |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
41514
diff
changeset
|
209 |
(a) -> assertCommandOutputStartsWith(a, "/drop", |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
41514
diff
changeset
|
210 |
"| In the /drop argument, please specify an import, variable, method, or class to drop.") |
38539 | 211 |
); |
37389 | 212 |
} |
213 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
214 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
215 |
public void testDebug() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
216 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
217 |
(a) -> assertCommand(a, "/deb", "| Debugging on"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
218 |
(a) -> assertCommand(a, "/debug", "| Debugging off"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
219 |
(a) -> assertCommand(a, "/debug", "| Debugging on"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
220 |
(a) -> assertCommand(a, "/deb", "| Debugging off") |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
221 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
222 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
223 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
224 |
@Test |
37389 | 225 |
public void testDrop() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
226 |
test(false, new String[]{"--no-startup"}, |
37389 | 227 |
a -> assertVariable(a, "int", "a"), |
228 |
a -> dropVariable(a, "/drop 1", "int a = 0", "| dropped variable a"), |
|
229 |
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), |
|
230 |
a -> dropMethod(a, "/drop 2", "b ()I", "| dropped method b()"), |
|
231 |
a -> assertClass(a, "class A {}", "class", "A"), |
|
232 |
a -> dropClass(a, "/drop 3", "class A", "| dropped class A"), |
|
233 |
a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
|
234 |
a -> dropImport(a, "/drop 4", "import java.util.stream.*", ""), |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
40601
diff
changeset
|
235 |
a -> assertCommand(a, "for (int i = 0; i < 10; ++i) {}", ""), |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
40601
diff
changeset
|
236 |
a -> assertCommand(a, "/drop 5", ""), |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
40601
diff
changeset
|
237 |
a -> assertCommand(a, "/list", ""), |
37389 | 238 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
239 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
240 |
a -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 241 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
242 |
); |
|
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
243 |
test(false, new String[]{"--no-startup"}, |
37389 | 244 |
a -> assertVariable(a, "int", "a"), |
245 |
a -> dropVariable(a, "/drop a", "int a = 0", "| dropped variable a"), |
|
246 |
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), |
|
247 |
a -> dropMethod(a, "/drop b", "b ()I", "| dropped method b()"), |
|
248 |
a -> assertClass(a, "class A {}", "class", "A"), |
|
249 |
a -> dropClass(a, "/drop A", "class A", "| dropped class A"), |
|
250 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
251 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
252 |
a -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 253 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
254 |
); |
|
255 |
} |
|
256 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
257 |
@Test |
37389 | 258 |
public void testDropNegative() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
259 |
test(false, new String[]{"--no-startup"}, |
38539 | 260 |
a -> assertCommandOutputStartsWith(a, "/drop 0", "| No such snippet: 0"), |
261 |
a -> assertCommandOutputStartsWith(a, "/drop a", "| No such snippet: a"), |
|
37389 | 262 |
a -> assertCommandCheckOutput(a, "/drop", |
263 |
assertStartsWith("| In the /drop argument, please specify an import, variable, method, or class to drop.")), |
|
264 |
a -> assertVariable(a, "int", "a"), |
|
265 |
a -> assertCommand(a, "a", "a ==> 0"), |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
40601
diff
changeset
|
266 |
a -> assertCommand(a, "/drop 2", ""), |
38539 | 267 |
a -> assertCommand(a, "/drop 2", |
268 |
"| This command does not accept the snippet '2' : a\n" + |
|
269 |
"| See /types, /methods, /vars, or /list") |
|
37389 | 270 |
); |
271 |
} |
|
272 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
273 |
@Test |
37389 | 274 |
public void testAmbiguousDrop() { |
275 |
Consumer<String> check = s -> { |
|
276 |
assertTrue(s.startsWith("| The argument references more than one import, variable, method, or class"), s); |
|
277 |
int lines = s.split("\n").length; |
|
278 |
assertEquals(lines, 5, "Expected 3 ambiguous keys, but found: " + (lines - 2) + "\n" + s); |
|
279 |
}; |
|
280 |
test( |
|
281 |
a -> assertVariable(a, "int", "a"), |
|
282 |
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), |
|
283 |
a -> assertClass(a, "class a {}", "class", "a"), |
|
284 |
a -> assertCommandCheckOutput(a, "/drop a", check), |
|
285 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
286 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
287 |
a -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 288 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
289 |
); |
|
290 |
test( |
|
291 |
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), |
|
292 |
a -> assertMethod(a, "double a(int a) { return 0; }", "(int)double", "a"), |
|
293 |
a -> assertMethod(a, "double a(double a) { return 0; }", "(double)double", "a"), |
|
294 |
a -> assertCommandCheckOutput(a, "/drop a", check), |
|
295 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
|
296 |
); |
|
297 |
} |
|
298 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
299 |
@Test |
42412
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
300 |
public void testApplicationOfPost() { |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
301 |
test( |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
302 |
(a) -> assertCommand(a, "/set mode t normal -command", "| Created new feedback mode: t"), |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
303 |
(a) -> assertCommand(a, "/set feedback t", "| Feedback mode: t"), |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
304 |
(a) -> assertCommand(a, "/set format t post \"$%n\"", ""), |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
305 |
(a) -> assertCommand(a, "/set prompt t \"+\" \"-\"", ""), |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
306 |
(a) -> assertCommand(a, "/set prompt t", "| /set prompt t \"+\" \"-\"$") |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
307 |
); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
308 |
} |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
309 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
310 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
311 |
public void testHelpLength() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
312 |
Consumer<String> testOutput = (s) -> { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
313 |
List<String> ss = Stream.of(s.split("\n")) |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
314 |
.filter(l -> !l.isEmpty()) |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
315 |
.collect(Collectors.toList()); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
316 |
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
|
317 |
}; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
318 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
319 |
(a) -> assertCommandCheckOutput(a, "/?", testOutput), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
320 |
(a) -> assertCommandCheckOutput(a, "/help", testOutput), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
321 |
(a) -> assertCommandCheckOutput(a, "/help /list", testOutput) |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
322 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
323 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
324 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
325 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
326 |
public void testHelp() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
327 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
328 |
(a) -> assertHelp(a, "/?", "/list", "/help", "/exit", "intro"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
329 |
(a) -> assertHelp(a, "/help", "/list", "/help", "/exit", "intro"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
330 |
(a) -> assertHelp(a, "/help short", "shortcuts", "<tab>"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
331 |
(a) -> assertHelp(a, "/? /li", "/list -all", "snippets"), |
42412
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
332 |
(a) -> assertHelp(a, "/help /set prompt", "optionally contain '%s'", "quoted"), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
333 |
(a) -> assertHelp(a, "/help /help", "/help <command>") |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
334 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
335 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
336 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
337 |
@Test |
42412
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
338 |
public void testHelpFormat() { |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
339 |
test( |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
340 |
(a) -> assertCommandCheckOutput(a, "/help", s -> { |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
341 |
String[] lines = s.split("\\R"); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
342 |
assertTrue(lines.length > 20, |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
343 |
"Too few lines of /help output: " + lines.length |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
344 |
+ "\n" + s); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
345 |
for (int i = 0; i < lines.length; ++i) { |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
346 |
String l = lines[i]; |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
347 |
assertTrue(l.startsWith("| "), |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
348 |
"Expected /help line to start with | :\n" + l); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
349 |
assertTrue(l.length() <= 80, |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
350 |
"/help line too long: " + l.length() + "\n" + l); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
351 |
} |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
352 |
}) |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
353 |
); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
354 |
} |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
355 |
|
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
356 |
private void assertHelp(boolean a, String command, String... find) { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
357 |
assertCommandCheckOutput(a, command, s -> { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
358 |
for (String f : find) { |
42412
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
359 |
assertTrue(s.contains(f), |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
360 |
"Expected output of " + command + " to contain: " + f |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
361 |
+ "\n" + s); |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
362 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
363 |
}); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
364 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
365 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
366 |
// 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
|
367 |
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
|
368 |
String trimmed = in.trim(); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
369 |
String[] res = trimmed.isEmpty() |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
370 |
? new String[0] |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
371 |
: trimmed.split("\n"); |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
372 |
assertEquals(res.length, match.size(), "Got: " + Arrays.asList(res)); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
373 |
for (int i = 0; i < match.size(); ++i) { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
374 |
assertTrue(res[i].contains(match.get(i))); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
375 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
376 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
377 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
378 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
379 |
public void testListArgs() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
380 |
String arg = "qqqq"; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
381 |
List<String> startVarList = new ArrayList<>(START_UP); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
382 |
startVarList.add("int aardvark"); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
383 |
test( |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
384 |
a -> assertCommandCheckOutput(a, "/list -all", |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
385 |
s -> checkLineToList(s, START_UP)), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
386 |
a -> assertCommandOutputStartsWith(a, "/list " + arg, |
38539 | 387 |
"| No such snippet: " + arg), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
388 |
a -> assertVariable(a, "int", "aardvark"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
389 |
a -> assertCommandOutputContains(a, "/list aardvark", "aardvark"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
390 |
a -> assertCommandCheckOutput(a, "/list -start", |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
391 |
s -> checkLineToList(s, START_UP)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
392 |
a -> assertCommandCheckOutput(a, "/list -all", |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
393 |
s -> checkLineToList(s, startVarList)), |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
394 |
a -> assertCommandOutputStartsWith(a, "/list s3", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
395 |
"s3 : import"), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
396 |
a -> assertCommandOutputStartsWith(a, "/list " + arg, |
38539 | 397 |
"| No such snippet: " + arg) |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
398 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
399 |
} |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
400 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
401 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
402 |
public void testVarsArgs() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
403 |
String arg = "qqqq"; |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
404 |
List<String> startVarList = new ArrayList<>(); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
405 |
test( |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
406 |
a -> assertCommandCheckOutput(a, "/vars -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
407 |
s -> checkLineToList(s, startVarList)), |
38539 | 408 |
a -> assertCommand(a, "/vars " + arg, |
409 |
"| No such snippet: " + arg), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
410 |
a -> assertVariable(a, "int", "aardvark"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
411 |
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
|
412 |
a -> assertVariable(a, "int", "a"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
413 |
a -> assertVariable(a, "double", "a", "1", "1.0"), |
38539 | 414 |
a -> assertCommandOutputStartsWith(a, "/vars aardvark", |
415 |
"| int aardvark = 0"), |
|
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
416 |
a -> assertCommandCheckOutput(a, "/vars -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
417 |
s -> checkLineToList(s, startVarList)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
418 |
a -> assertCommandOutputStartsWith(a, "/vars -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
419 |
"| int aardvark = 0\n| int a = "), |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
420 |
a -> assertCommandOutputStartsWith(a, "/vars f", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
421 |
"| This command does not accept the snippet 'f'"), |
38539 | 422 |
a -> assertCommand(a, "/var " + arg, |
423 |
"| No such snippet: " + arg) |
|
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
424 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
425 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
426 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
427 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
428 |
public void testMethodsArgs() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
429 |
String arg = "qqqq"; |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
430 |
List<String> printingMethodList = new ArrayList<>(PRINTING_CMD_METHOD); |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
431 |
test(new String[]{"--startup", "PRINTING"}, |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
432 |
a -> assertCommandCheckOutput(a, "/methods -all", |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
433 |
s -> checkLineToList(s, printingMethodList)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
434 |
a -> assertCommandCheckOutput(a, "/methods -start", |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
435 |
s -> checkLineToList(s, printingMethodList)), |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
436 |
a -> assertCommandCheckOutput(a, "/methods print println printf", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
437 |
s -> checkLineToList(s, printingMethodList)), |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
438 |
a -> assertCommandCheckOutput(a, "/methods println", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
439 |
s -> assertEquals(s.trim().split("\n").length, 10)), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
440 |
a -> assertCommandCheckOutput(a, "/methods", |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
441 |
s -> checkLineToList(s, printingMethodList)), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
442 |
a -> assertCommandOutputStartsWith(a, "/methods " + arg, |
38539 | 443 |
"| No such snippet: " + arg), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
444 |
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
|
445 |
a -> assertVariable(a, "int", "aardvark"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
446 |
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
|
447 |
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
|
448 |
a -> assertCommandOutputStartsWith(a, "/methods " + arg, |
38539 | 449 |
"| No such snippet: " + arg), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
450 |
a -> assertCommandOutputStartsWith(a, "/methods aardvark", |
38539 | 451 |
"| 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
|
452 |
a -> assertCommandCheckOutput(a, "/methods -start", |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
453 |
s -> checkLineToList(s, printingMethodList)), |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
454 |
a -> assertCommandCheckOutput(a, "/methods print println printf", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
455 |
s -> checkLineToList(s, printingMethodList)), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
456 |
a -> assertCommandOutputStartsWith(a, "/methods g", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
457 |
"| g ()void"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
458 |
a -> assertCommandOutputStartsWith(a, "/methods f", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
459 |
"| f ()int\n" + |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
460 |
"| f (int)void") |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
461 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
462 |
} |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
463 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
464 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
465 |
public void testTypesArgs() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
466 |
String arg = "qqqq"; |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
467 |
List<String> startTypeList = new ArrayList<>(); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
468 |
test( |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
469 |
a -> assertCommandCheckOutput(a, "/types -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
470 |
s -> checkLineToList(s, startTypeList)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
471 |
a -> assertCommandCheckOutput(a, "/types -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
472 |
s -> checkLineToList(s, startTypeList)), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
473 |
a -> assertCommandOutputStartsWith(a, "/types " + arg, |
38539 | 474 |
"| No such snippet: " + arg), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
475 |
a -> assertVariable(a, "int", "aardvark"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
476 |
(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
|
477 |
(a) -> assertClass(a, "interface A { }", "interface", "A"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
478 |
a -> assertCommandOutputStartsWith(a, "/types -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
479 |
"| class A\n" + |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
480 |
"| interface A"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
481 |
(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
|
482 |
(a) -> assertClass(a, "@interface B { }", "@interface", "B"), |
38539 | 483 |
a -> assertCommand(a, "/types aardvark", |
484 |
"| 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
|
485 |
a -> assertCommandOutputStartsWith(a, "/types A", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
486 |
"| interface A"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
487 |
a -> assertCommandOutputStartsWith(a, "/types E", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
488 |
"| enum E"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
489 |
a -> assertCommandOutputStartsWith(a, "/types B", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
490 |
"| @interface B"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
491 |
a -> assertCommandOutputStartsWith(a, "/types " + arg, |
38539 | 492 |
"| No such snippet: " + arg), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
493 |
a -> assertCommandCheckOutput(a, "/types -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
494 |
s -> checkLineToList(s, startTypeList)) |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
495 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
496 |
} |
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
497 |
|
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
498 |
@Test |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
499 |
public void testCompoundStart() { |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
500 |
test(new String[]{"--startup", "DEFAULT", "--startup", "PRINTING"}, |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
501 |
(a) -> assertCommand(a, "printf(\"%4.2f\", Math.PI)", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
502 |
"", "", null, "3.14", "") |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
503 |
); |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
504 |
} |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
505 |
|
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
506 |
@Test |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
507 |
public void testJavaSeStart() { |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
508 |
test(new String[]{"--startup", "JAVASE"}, |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
509 |
(a) -> assertCommand(a, "ZoneOffsetTransitionRule.TimeDefinition.WALL", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
510 |
"$1 ==> WALL") |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
511 |
); |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
512 |
} |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
513 |
|
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
514 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
515 |
public void defineClasses() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
516 |
test( |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
517 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
518 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
519 |
(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
|
520 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
521 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
522 |
(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
|
523 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
524 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
525 |
(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
|
526 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
527 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
528 |
(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
|
529 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
530 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()) |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
531 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
532 |
} |
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
533 |
|
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
534 |
@Test |
37389 | 535 |
public void testCommandPrefix() { |
536 |
test(a -> assertCommandCheckOutput(a, "/s", |
|
537 |
assertStartsWith("| Command: '/s' is ambiguous: /save, /set")), |
|
538 |
a -> assertCommand(a, "int var", "var ==> 0"), |
|
539 |
a -> assertCommandCheckOutput(a, "/va", |
|
540 |
assertStartsWith("| int var = 0")), |
|
541 |
a -> assertCommandCheckOutput(a, "/save", |
|
542 |
assertStartsWith("| '/save' requires a filename argument."))); |
|
543 |
} |
|
544 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
545 |
@Test |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
546 |
public void testOptionQ() { |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
547 |
test(Locale.ROOT, false, new String[]{"-q", "--no-startup"}, "", |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
548 |
(a) -> assertCommand(a, "1+1", "$1 ==> 2"), |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
549 |
(a) -> assertCommand(a, "int x = 5", "") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
550 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
551 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
552 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
553 |
@Test |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
554 |
public void testOptionS() { |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
555 |
test(Locale.ROOT, false, new String[]{"-s", "--no-startup"}, "", |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
556 |
(a) -> assertCommand(a, "1+1", "") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
557 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
558 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
559 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
560 |
@Test |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
561 |
public void testOptionV() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
562 |
test(new String[]{"-v", "--no-startup"}, |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
563 |
(a) -> assertCommand(a, "1+1", |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
564 |
"$1 ==> 2\n" + |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
565 |
"| created scratch variable $1 : int") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
566 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
567 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
568 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
569 |
@Test |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
570 |
public void testOptionFeedback() { |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
571 |
test(Locale.ROOT, false, new String[]{"--feedback", "concise", "--no-startup"}, "", |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
572 |
(a) -> assertCommand(a, "1+1", "$1 ==> 2"), |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
573 |
(a) -> assertCommand(a, "int x = 5", "") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
574 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
575 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
576 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
577 |
@Test |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
578 |
public void testCompoundOptions() { |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
579 |
Consumer<String> confirmNoStartup = s -> { |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
580 |
assertEquals(0, Stream.of(s.split("\n")) |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
581 |
.filter(l -> !l.isEmpty()) |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
582 |
.count(), "Expected no lines: " + s); |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
583 |
}; |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
584 |
test(Locale.ROOT, false, new String[]{"-nq"}, "", |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
585 |
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup), |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
586 |
(a) -> assertCommand(a, "1+1", "$1 ==> 2"), |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
587 |
(a) -> assertCommand(a, "int x = 5", "") |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
588 |
); |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
589 |
test(Locale.ROOT, false, new String[]{"-qn"}, "", |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
590 |
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup), |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
591 |
(a) -> assertCommand(a, "1+1", "$1 ==> 2"), |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
592 |
(a) -> assertCommand(a, "int x = 5", "") |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
593 |
); |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
594 |
test(Locale.ROOT, false, new String[]{"-ns"}, "", |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
595 |
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup), |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
596 |
(a) -> assertCommand(a, "1+1", "") |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
597 |
); |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
598 |
} |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
599 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
600 |
@Test |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
601 |
public void testOptionR() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
602 |
test(new String[]{"-R-Dthe.sound=blorp", "--no-startup"}, |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
603 |
(a) -> assertCommand(a, "System.getProperty(\"the.sound\")", |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
604 |
"$1 ==> \"blorp\"") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
605 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
606 |
} |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
607 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
608 |
@Test |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
609 |
public void test8156910() { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
610 |
test( |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
611 |
(a) -> assertCommandOutputContains(a, "System.out.println(\"%5d\", 10);", "%5d"), |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
612 |
(a) -> assertCommandOutputContains(a, "1234", "==> 1234") |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
613 |
); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
614 |
} |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
615 |
} |