author | tschatzl |
Fri, 04 Aug 2017 14:15:42 +0200 | |
changeset 46750 | bcab0128a16f |
parent 45602 | 7aeef976cb06 |
permissions | -rw-r--r-- |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
1 |
/* |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
2 |
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
37007
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 |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
26 |
* @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103 8165405 8173073 8173848 8174041 8173916 8174028 8174262 8174797 8177079 8180508 |
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; |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
40 |
import java.util.regex.Pattern; |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
41 |
import java.util.stream.Collectors; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
42 |
import java.util.stream.Stream; |
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 org.testng.annotations.Test; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
45 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
46 |
import static org.testng.Assert.assertEquals; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
47 |
import static org.testng.Assert.assertTrue; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
48 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
49 |
public class ToolSimpleTest extends ReplToolTesting { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
50 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
51 |
@Test |
37389 | 52 |
public void testRemaining() { |
53 |
test( |
|
54 |
(a) -> assertCommand(a, "int z; z =", "z ==> 0"), |
|
55 |
(a) -> assertCommand(a, "5", "z ==> 5"), |
|
56 |
(a) -> assertCommand(a, "/*nada*/; int q =", ""), |
|
57 |
(a) -> assertCommand(a, "77", "q ==> 77"), |
|
58 |
(a) -> assertCommand(a, "//comment;", ""), |
|
59 |
(a) -> assertCommand(a, "int v;", "v ==> 0"), |
|
60 |
(a) -> assertCommand(a, "int v; int c", |
|
61 |
"v ==> 0\n" + |
|
62 |
"c ==> 0") |
|
63 |
); |
|
64 |
} |
|
65 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
66 |
@Test |
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
67 |
public void testOpenComment() { |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
68 |
test( |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
69 |
(a) -> assertCommand(a, "int z = /* blah", ""), |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
70 |
(a) -> assertCommand(a, "baz */ 5", "z ==> 5"), |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
71 |
(a) -> assertCommand(a, "/** hoge ", ""), |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
72 |
(a) -> assertCommand(a, "baz **/", ""), |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
73 |
(a) -> assertCommand(a, "int v", "v ==> 0") |
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 |
} |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
76 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
77 |
@Test |
43586
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
78 |
public void testLessThan() { |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
79 |
test( |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
80 |
(a) -> assertCommand(a, "45", "$1 ==> 45"), |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
81 |
(a) -> assertCommand(a, "72", "$2 ==> 72"), |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
82 |
(a) -> assertCommand(a, "$1 < $2", "$3 ==> true"), |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
83 |
(a) -> assertCommand(a, "int a, b", "a ==> 0\n" + |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
84 |
"b ==> 0"), |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
85 |
(a) -> assertCommand(a, "a < b", "$6 ==> false") |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
86 |
); |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
87 |
} |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
88 |
|
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
89 |
@Test |
37389 | 90 |
public void oneLineOfError() { |
91 |
test( |
|
92 |
(a) -> assertCommand(a, "12+", null), |
|
93 |
(a) -> assertCommandCheckOutput(a, " true", (s) -> |
|
94 |
assertTrue(s.contains("12+") && !s.contains("true"), "Output: '" + s + "'")) |
|
95 |
); |
|
96 |
} |
|
97 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
98 |
@Test |
37389 | 99 |
public void defineVariables() { |
100 |
test( |
|
101 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
102 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
103 |
(a) -> assertVariable(a, "int", "a"), |
|
104 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
105 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
106 |
(a) -> assertVariable(a, "double", "a", "1", "1.0"), |
|
107 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
108 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
109 |
(a) -> evaluateExpression(a, "double", "2 * a", "2.0"), |
|
110 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
111 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()) |
|
112 |
); |
|
113 |
} |
|
114 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
115 |
@Test |
37389 | 116 |
public void defineMethods() { |
117 |
test( |
|
118 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
119 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
120 |
(a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"), |
|
121 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
122 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
123 |
(a) -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"), |
|
124 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
125 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
126 |
(a) -> assertMethod(a, "void g() {}", "()void", "g"), |
|
127 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
128 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
|
129 |
); |
|
130 |
} |
|
131 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
132 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
133 |
public void defineTypes() { |
37389 | 134 |
test( |
135 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
136 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 137 |
(a) -> assertClass(a, "class A { }", "class", "A"), |
138 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
139 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 140 |
(a) -> assertClass(a, "interface A { }", "interface", "A"), |
141 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
142 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 143 |
(a) -> assertClass(a, "enum A { }", "enum", "A"), |
144 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
145 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 146 |
(a) -> assertClass(a, "@interface A { }", "@interface", "A"), |
147 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
148 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()) |
37389 | 149 |
); |
150 |
} |
|
151 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
152 |
@Test |
37389 | 153 |
public void defineImports() { |
154 |
test( |
|
155 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
156 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
157 |
(a) -> assertImport(a, "import java.util.stream.Stream;", "", "java.util.stream.Stream"), |
|
158 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
159 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
160 |
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
|
161 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
162 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
163 |
(a) -> assertImport(a, "import static java.lang.Math.PI;", "static", "java.lang.Math.PI"), |
|
164 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
165 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
166 |
(a) -> assertImport(a, "import static java.lang.Math.*;", "static", "java.lang.Math.*"), |
|
167 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
168 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()) |
|
169 |
); |
|
170 |
} |
|
171 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
172 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
173 |
public void defineVar() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
174 |
test( |
37389 | 175 |
(a) -> assertCommand(a, "int x = 72", "x ==> 72"), |
176 |
(a) -> assertCommand(a, "x", "x ==> 72"), |
|
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
177 |
(a) -> assertCommand(a, "/vars", "| int x = 72") |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
178 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
179 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
180 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
181 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
182 |
public void defineUnresolvedVar() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
183 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
184 |
(a) -> assertCommand(a, "undefined x", |
37389 | 185 |
"| 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
|
186 |
(a) -> assertCommand(a, "/vars", "| undefined x = (not-active)") |
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 |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
191 |
public void testUnresolved() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
192 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
193 |
(a) -> assertCommand(a, "int f() { return g() + x + new A().a; }", |
37389 | 194 |
"| 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
|
195 |
(a) -> assertCommand(a, "f()", |
37389 | 196 |
"| 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
|
197 |
(a) -> assertCommandOutputStartsWith(a, "int g() { return x; }", |
37389 | 198 |
"| created method g(), however, it cannot be invoked until variable x is declared"), |
199 |
(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
|
200 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
201 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
202 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
203 |
@Test |
37389 | 204 |
public void testUnknownCommand() { |
205 |
test((a) -> assertCommand(a, "/unknown", |
|
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
206 |
"| Invalid command: /unknown\n" + |
37389 | 207 |
"| Type /help for help.")); |
208 |
} |
|
209 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
210 |
@Test |
37389 | 211 |
public void testEmptyClassPath() { |
43038 | 212 |
test(after -> assertCommand(after, "/env --class-path", "| Argument to class-path missing.")); |
37389 | 213 |
} |
214 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
215 |
@Test |
43856
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43766
diff
changeset
|
216 |
public void testInvalidClassPath() { |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43766
diff
changeset
|
217 |
test( |
43861
825bad9a162a
8174862: JShell tests: new JDK-8174797 testInvalidClassPath fails on Windows
rfield
parents:
43856
diff
changeset
|
218 |
a -> assertCommand(a, "/env --class-path snurgefusal", |
825bad9a162a
8174862: JShell tests: new JDK-8174797 testInvalidClassPath fails on Windows
rfield
parents:
43856
diff
changeset
|
219 |
"| File 'snurgefusal' for '--class-path' is not found.") |
43856
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43766
diff
changeset
|
220 |
); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43766
diff
changeset
|
221 |
} |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43766
diff
changeset
|
222 |
|
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43766
diff
changeset
|
223 |
@Test |
37389 | 224 |
public void testNoArgument() { |
38539 | 225 |
test( |
226 |
(a) -> assertCommand(a, "/save", |
|
227 |
"| '/save' requires a filename argument."), |
|
228 |
(a) -> assertCommand(a, "/open", |
|
229 |
"| '/open' requires a filename argument."), |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
41514
diff
changeset
|
230 |
(a) -> assertCommandOutputStartsWith(a, "/drop", |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
41514
diff
changeset
|
231 |
"| In the /drop argument, please specify an import, variable, method, or class to drop.") |
38539 | 232 |
); |
37389 | 233 |
} |
234 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
235 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
236 |
public void testDebug() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
237 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
238 |
(a) -> assertCommand(a, "/deb", "| Debugging on"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
239 |
(a) -> assertCommand(a, "/debug", "| Debugging off"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
240 |
(a) -> assertCommand(a, "/debug", "| Debugging on"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
241 |
(a) -> assertCommand(a, "/deb", "| Debugging off") |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
242 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
243 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
244 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
245 |
@Test |
37389 | 246 |
public void testDrop() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
247 |
test(false, new String[]{"--no-startup"}, |
37389 | 248 |
a -> assertVariable(a, "int", "a"), |
249 |
a -> dropVariable(a, "/drop 1", "int a = 0", "| dropped variable a"), |
|
43759
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
250 |
a -> assertMethod(a, "int b() { return 0; }", "()int", "b"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
251 |
a -> dropMethod(a, "/drop 2", "int b()", "| dropped method b()"), |
37389 | 252 |
a -> assertClass(a, "class A {}", "class", "A"), |
253 |
a -> dropClass(a, "/drop 3", "class A", "| dropped class A"), |
|
254 |
a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
|
255 |
a -> dropImport(a, "/drop 4", "import java.util.stream.*", ""), |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
40601
diff
changeset
|
256 |
a -> assertCommand(a, "for (int i = 0; i < 10; ++i) {}", ""), |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
40601
diff
changeset
|
257 |
a -> assertCommand(a, "/drop 5", ""), |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
40601
diff
changeset
|
258 |
a -> assertCommand(a, "/list", ""), |
37389 | 259 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
260 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
261 |
a -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 262 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
263 |
); |
|
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
264 |
test(false, new String[]{"--no-startup"}, |
37389 | 265 |
a -> assertVariable(a, "int", "a"), |
266 |
a -> dropVariable(a, "/drop a", "int a = 0", "| dropped variable a"), |
|
43759
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
267 |
a -> assertMethod(a, "int b() { return 0; }", "()int", "b"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
268 |
a -> dropMethod(a, "/drop b", "int b()", "| dropped method b()"), |
37389 | 269 |
a -> assertClass(a, "class A {}", "class", "A"), |
270 |
a -> dropClass(a, "/drop A", "class A", "| dropped class A"), |
|
271 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
272 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
273 |
a -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 274 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
275 |
); |
|
276 |
} |
|
277 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
278 |
@Test |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
279 |
public void testDropRange() { |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
280 |
test(false, new String[]{"--no-startup"}, |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
281 |
a -> assertVariable(a, "int", "a"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
282 |
a -> assertMethod(a, "int b() { return 0; }", "()int", "b"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
283 |
a -> assertClass(a, "class A {}", "class", "A"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
284 |
a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
285 |
a -> assertCommand(a, "for (int i = 0; i < 10; ++i) {}", ""), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
286 |
a -> assertCommand(a, "/drop 3-5 b 1", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
287 |
"| dropped class A\n" + |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
288 |
"| dropped method b()\n" + |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
289 |
"| dropped variable a\n"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
290 |
a -> assertCommand(a, "/list", "") |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
291 |
); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
292 |
} |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
293 |
|
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
294 |
@Test |
37389 | 295 |
public void testDropNegative() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
296 |
test(false, new String[]{"--no-startup"}, |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
297 |
a -> assertCommandOutputStartsWith(a, "/drop 0", "| No snippet with id: 0"), |
38539 | 298 |
a -> assertCommandOutputStartsWith(a, "/drop a", "| No such snippet: a"), |
37389 | 299 |
a -> assertCommandCheckOutput(a, "/drop", |
300 |
assertStartsWith("| In the /drop argument, please specify an import, variable, method, or class to drop.")), |
|
301 |
a -> assertVariable(a, "int", "a"), |
|
302 |
a -> assertCommand(a, "a", "a ==> 0"), |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
40601
diff
changeset
|
303 |
a -> assertCommand(a, "/drop 2", ""), |
38539 | 304 |
a -> assertCommand(a, "/drop 2", |
305 |
"| This command does not accept the snippet '2' : a\n" + |
|
306 |
"| See /types, /methods, /vars, or /list") |
|
37389 | 307 |
); |
308 |
} |
|
309 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
310 |
@Test |
37389 | 311 |
public void testAmbiguousDrop() { |
312 |
test( |
|
313 |
a -> assertVariable(a, "int", "a"), |
|
314 |
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), |
|
315 |
a -> assertClass(a, "class a {}", "class", "a"), |
|
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
316 |
a -> assertCommand(a, "/drop a", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
317 |
"| dropped variable a\n" + |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
318 |
"| dropped method a()\n" + |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
319 |
"| dropped class a") |
37389 | 320 |
); |
321 |
test( |
|
322 |
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), |
|
323 |
a -> assertMethod(a, "double a(int a) { return 0; }", "(int)double", "a"), |
|
324 |
a -> assertMethod(a, "double a(double a) { return 0; }", "(double)double", "a"), |
|
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
325 |
a -> assertCommand(a, "/drop a", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
326 |
"| dropped method a()\n" + |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
327 |
"| dropped method a(int)\n" + |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
328 |
"| dropped method a(double)\n") |
37389 | 329 |
); |
330 |
} |
|
331 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
332 |
@Test |
42412
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
333 |
public void testApplicationOfPost() { |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
334 |
test( |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
335 |
(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
|
336 |
(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
|
337 |
(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
|
338 |
(a) -> assertCommand(a, "/set prompt t \"+\" \"-\"", ""), |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
339 |
(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
|
340 |
); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
341 |
} |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
342 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
343 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
344 |
public void testHelpLength() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
345 |
Consumer<String> testOutput = (s) -> { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
346 |
List<String> ss = Stream.of(s.split("\n")) |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
347 |
.filter(l -> !l.isEmpty()) |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
348 |
.collect(Collectors.toList()); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
349 |
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
|
350 |
}; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
351 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
352 |
(a) -> assertCommandCheckOutput(a, "/?", testOutput), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
353 |
(a) -> assertCommandCheckOutput(a, "/help", testOutput), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
354 |
(a) -> assertCommandCheckOutput(a, "/help /list", testOutput) |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
355 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
356 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
357 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
358 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
359 |
public void testHelp() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
360 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
361 |
(a) -> assertHelp(a, "/?", "/list", "/help", "/exit", "intro"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
362 |
(a) -> assertHelp(a, "/help", "/list", "/help", "/exit", "intro"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
363 |
(a) -> assertHelp(a, "/help short", "shortcuts", "<tab>"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
364 |
(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
|
365 |
(a) -> assertHelp(a, "/help /set prompt", "optionally contain '%s'", "quoted"), |
44454
74af976d6798
8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents:
43861
diff
changeset
|
366 |
(a) -> assertHelp(a, "/help /help", "/help <command>"), |
74af976d6798
8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents:
43861
diff
changeset
|
367 |
(a) -> assertHelp(a, "/help li", "/list -start"), |
74af976d6798
8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents:
43861
diff
changeset
|
368 |
(a) -> assertHelp(a, "/help fe", "/set feedback -retain") |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
369 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
370 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
371 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
372 |
@Test |
42412
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
373 |
public void testHelpFormat() { |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
374 |
test( |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
375 |
(a) -> assertCommandCheckOutput(a, "/help", s -> { |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
376 |
String[] lines = s.split("\\R"); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
377 |
assertTrue(lines.length > 20, |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
378 |
"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
|
379 |
+ "\n" + s); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
380 |
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
|
381 |
String l = lines[i]; |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
382 |
assertTrue(l.startsWith("| "), |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
383 |
"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
|
384 |
assertTrue(l.length() <= 80, |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
385 |
"/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
|
386 |
} |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
387 |
}) |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
388 |
); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
389 |
} |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
390 |
|
45602
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
391 |
@Test |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
392 |
public void testConfusedUserPseudoCommands() { |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
393 |
test( |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
394 |
(a) -> assertHelp(a, "/-<n>", "last snippet", "digits"), |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
395 |
(a) -> assertHelp(a, "/<id>", "last snippet", "digits") |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
396 |
); |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
397 |
} |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
398 |
|
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
399 |
private void assertHelp(boolean a, String command, String... find) { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
400 |
assertCommandCheckOutput(a, command, s -> { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
401 |
for (String f : find) { |
42412
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
402 |
assertTrue(s.contains(f), |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
403 |
"Expected output of " + command + " to contain: " + f |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
404 |
+ "\n" + s); |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
405 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
406 |
}); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
407 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
408 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
409 |
// 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
|
410 |
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
|
411 |
String trimmed = in.trim(); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
412 |
String[] res = trimmed.isEmpty() |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
413 |
? new String[0] |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
414 |
: trimmed.split("\n"); |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
415 |
assertEquals(res.length, match.size(), "Got: " + Arrays.asList(res)); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
416 |
for (int i = 0; i < match.size(); ++i) { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
417 |
assertTrue(res[i].contains(match.get(i))); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
418 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
419 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
420 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
421 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
422 |
public void testListArgs() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
423 |
String arg = "qqqq"; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
424 |
List<String> startVarList = new ArrayList<>(START_UP); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
425 |
startVarList.add("int aardvark"); |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
426 |
startVarList.add("int weevil"); |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
427 |
test( |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
428 |
a -> assertCommandCheckOutput(a, "/list -all", |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
429 |
s -> checkLineToList(s, START_UP)), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
430 |
a -> assertCommandOutputStartsWith(a, "/list " + arg, |
38539 | 431 |
"| No such snippet: " + arg), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
432 |
a -> assertVariable(a, "int", "aardvark"), |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
433 |
a -> assertVariable(a, "int", "weevil"), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
434 |
a -> assertCommandOutputContains(a, "/list aardvark", "aardvark"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
435 |
a -> assertCommandCheckOutput(a, "/list -start", |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
436 |
s -> checkLineToList(s, START_UP)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
437 |
a -> assertCommandCheckOutput(a, "/list -all", |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
438 |
s -> checkLineToList(s, startVarList)), |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
439 |
a -> assertCommandOutputStartsWith(a, "/list s3", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
440 |
"s3 : import"), |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
441 |
a -> assertCommandCheckOutput(a, "/list 1-2 s3", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
442 |
s -> { |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
443 |
assertTrue(Pattern.matches(".*aardvark.*\\R.*weevil.*\\R.*s3.*import.*", s.trim()), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
444 |
"No match: " + s); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
445 |
}), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
446 |
a -> assertCommandOutputStartsWith(a, "/list " + arg, |
38539 | 447 |
"| No such snippet: " + arg) |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
448 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
449 |
} |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
450 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
451 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
452 |
public void testVarsArgs() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
453 |
String arg = "qqqq"; |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
454 |
List<String> startVarList = new ArrayList<>(); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
455 |
test( |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
456 |
a -> assertCommandCheckOutput(a, "/vars -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
457 |
s -> checkLineToList(s, startVarList)), |
38539 | 458 |
a -> assertCommand(a, "/vars " + arg, |
459 |
"| No such snippet: " + arg), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
460 |
a -> assertVariable(a, "int", "aardvark"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
461 |
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
|
462 |
a -> assertVariable(a, "int", "a"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
463 |
a -> assertVariable(a, "double", "a", "1", "1.0"), |
38539 | 464 |
a -> assertCommandOutputStartsWith(a, "/vars aardvark", |
465 |
"| int aardvark = 0"), |
|
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
466 |
a -> assertCommandCheckOutput(a, "/vars -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
467 |
s -> checkLineToList(s, startVarList)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
468 |
a -> assertCommandOutputStartsWith(a, "/vars -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
469 |
"| int aardvark = 0\n| int a = "), |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
470 |
a -> assertCommandOutputStartsWith(a, "/vars 1-4", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
471 |
"| 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
|
472 |
a -> assertCommandOutputStartsWith(a, "/vars f", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
473 |
"| This command does not accept the snippet 'f'"), |
38539 | 474 |
a -> assertCommand(a, "/var " + arg, |
475 |
"| No such snippet: " + arg) |
|
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
476 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
477 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
478 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
479 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
480 |
public void testMethodsArgs() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
481 |
String arg = "qqqq"; |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
482 |
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
|
483 |
test(new String[]{"--startup", "PRINTING"}, |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
484 |
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
|
485 |
s -> checkLineToList(s, printingMethodList)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
486 |
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
|
487 |
s -> checkLineToList(s, printingMethodList)), |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
488 |
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
|
489 |
s -> checkLineToList(s, printingMethodList)), |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
490 |
a -> assertCommandCheckOutput(a, "/methods println", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
491 |
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
|
492 |
a -> assertCommandCheckOutput(a, "/methods", |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
493 |
s -> checkLineToList(s, printingMethodList)), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
494 |
a -> assertCommandOutputStartsWith(a, "/methods " + arg, |
38539 | 495 |
"| No such snippet: " + arg), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
496 |
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
|
497 |
a -> assertVariable(a, "int", "aardvark"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
498 |
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
|
499 |
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
|
500 |
a -> assertCommandOutputStartsWith(a, "/methods " + arg, |
38539 | 501 |
"| No such snippet: " + arg), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
502 |
a -> assertCommandOutputStartsWith(a, "/methods aardvark", |
38539 | 503 |
"| 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
|
504 |
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
|
505 |
s -> checkLineToList(s, printingMethodList)), |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
506 |
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
|
507 |
s -> checkLineToList(s, printingMethodList)), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
508 |
a -> assertCommandOutputStartsWith(a, "/methods g", |
43759
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
509 |
"| void g()"), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
510 |
a -> assertCommandOutputStartsWith(a, "/methods f", |
43759
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
511 |
"| int f()\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
512 |
"| void f(int)") |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
513 |
); |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
514 |
} |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
515 |
|
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
516 |
@Test |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
517 |
public void testMethodsWithErrors() { |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
518 |
test(new String[]{"--no-startup"}, |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
519 |
a -> assertCommand(a, "double m(int x) { return x; }", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
520 |
"| created method m(int)"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
521 |
a -> assertCommand(a, "GARBAGE junk() { return TRASH; }", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
522 |
"| created method junk(), however, it cannot be referenced until class GARBAGE, and variable TRASH are declared"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
523 |
a -> assertCommand(a, "int w = 5;", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
524 |
"w ==> 5"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
525 |
a -> assertCommand(a, "int tyer() { return w; }", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
526 |
"| created method tyer()"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
527 |
a -> assertCommand(a, "String w = \"hi\";", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
528 |
"w ==> \"hi\""), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
529 |
a -> assertCommand(a, "/methods", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
530 |
"| double m(int)\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
531 |
"| GARBAGE junk()\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
532 |
"| which cannot be referenced until class GARBAGE, and variable TRASH are declared\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
533 |
"| int tyer()\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
534 |
"| which cannot be invoked until this error is corrected: \n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
535 |
"| incompatible types: java.lang.String cannot be converted to int\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
536 |
"| int tyer() { return w; }\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
537 |
"| ^\n") |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
538 |
); |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
539 |
} |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
540 |
|
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
541 |
@Test |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
542 |
public void testTypesWithErrors() { |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
543 |
test(new String[]{"--no-startup"}, |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
544 |
a -> assertCommand(a, "class C extends NONE { int x; }", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
545 |
"| created class C, however, it cannot be referenced until class NONE is declared"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
546 |
a -> assertCommand(a, "class D { void m() { System.out.println(nada); } }", |
43766
498b07dcf851
8174262: Error message misspelling: "instanciated"
rfield
parents:
43759
diff
changeset
|
547 |
"| created class D, however, it cannot be instantiated or its methods invoked until variable nada is declared"), |
43759
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
548 |
a -> assertCommand(a, "/types", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
549 |
"| class C\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
550 |
"| which cannot be referenced until class NONE is declared\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
551 |
"| class D\n" + |
43766
498b07dcf851
8174262: Error message misspelling: "instanciated"
rfield
parents:
43759
diff
changeset
|
552 |
"| which cannot be instantiated or its methods invoked until variable nada is declared\n") |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
553 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
554 |
} |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
555 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
556 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
557 |
public void testTypesArgs() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
558 |
String arg = "qqqq"; |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
559 |
List<String> startTypeList = new ArrayList<>(); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
560 |
test( |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
561 |
a -> assertCommandCheckOutput(a, "/types -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
562 |
s -> checkLineToList(s, startTypeList)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
563 |
a -> assertCommandCheckOutput(a, "/types -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
564 |
s -> checkLineToList(s, startTypeList)), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
565 |
a -> assertCommandOutputStartsWith(a, "/types " + arg, |
38539 | 566 |
"| No such snippet: " + arg), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
567 |
a -> assertVariable(a, "int", "aardvark"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
568 |
(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
|
569 |
(a) -> assertClass(a, "interface A { }", "interface", "A"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
570 |
a -> assertCommandOutputStartsWith(a, "/types -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
571 |
"| class A\n" + |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
572 |
"| interface A"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
573 |
(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
|
574 |
(a) -> assertClass(a, "@interface B { }", "@interface", "B"), |
38539 | 575 |
a -> assertCommand(a, "/types aardvark", |
576 |
"| 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
|
577 |
a -> assertCommandOutputStartsWith(a, "/types A", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
578 |
"| interface A"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
579 |
a -> assertCommandOutputStartsWith(a, "/types E", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
580 |
"| enum E"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
581 |
a -> assertCommandOutputStartsWith(a, "/types B", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
582 |
"| @interface B"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
583 |
a -> assertCommandOutputStartsWith(a, "/types " + arg, |
38539 | 584 |
"| No such snippet: " + arg), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
585 |
a -> assertCommandCheckOutput(a, "/types -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
586 |
s -> checkLineToList(s, startTypeList)) |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
587 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
588 |
} |
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
589 |
|
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
590 |
@Test |
43274
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
591 |
public void testBlankLinesInSnippetContinuation() { |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
592 |
test(Locale.ROOT, false, new String[]{"--no-startup"}, "", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
593 |
a -> assertCommand(a, "class C {", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
594 |
""), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
595 |
a -> assertCommand(a, "", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
596 |
""), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
597 |
a -> assertCommand(a, "", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
598 |
""), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
599 |
a -> assertCommand(a, " int x;", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
600 |
""), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
601 |
a -> assertCommand(a, "", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
602 |
""), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
603 |
a -> assertCommand(a, "", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
604 |
""), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
605 |
a -> assertCommand(a, "}", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
606 |
"| created class C"), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
607 |
a -> assertCommand(a, "/list", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
608 |
"\n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
609 |
" 1 : class C {\n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
610 |
" \n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
611 |
" \n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
612 |
" int x;\n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
613 |
" \n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
614 |
" \n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
615 |
" }") |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
616 |
); |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
617 |
} |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
618 |
|
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
619 |
@Test |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
620 |
public void testCompoundStart() { |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
621 |
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
|
622 |
(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
|
623 |
"", "", null, "3.14", "") |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
624 |
); |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
625 |
} |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
626 |
|
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
627 |
@Test |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
628 |
public void testJavaSeStart() { |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
629 |
test(new String[]{"--startup", "JAVASE"}, |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
630 |
(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
|
631 |
"$1 ==> WALL") |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
632 |
); |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
633 |
} |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
634 |
|
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
635 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
636 |
public void defineClasses() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
637 |
test( |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
638 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
639 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
640 |
(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
|
641 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
642 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
643 |
(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
|
644 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
645 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
646 |
(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
|
647 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
648 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
649 |
(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
|
650 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
651 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()) |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
652 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
653 |
} |
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
654 |
|
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
655 |
@Test |
37389 | 656 |
public void testCommandPrefix() { |
657 |
test(a -> assertCommandCheckOutput(a, "/s", |
|
658 |
assertStartsWith("| Command: '/s' is ambiguous: /save, /set")), |
|
659 |
a -> assertCommand(a, "int var", "var ==> 0"), |
|
660 |
a -> assertCommandCheckOutput(a, "/va", |
|
661 |
assertStartsWith("| int var = 0")), |
|
662 |
a -> assertCommandCheckOutput(a, "/save", |
|
663 |
assertStartsWith("| '/save' requires a filename argument."))); |
|
664 |
} |
|
665 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
666 |
@Test |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
667 |
public void testOptionQ() { |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
668 |
test(Locale.ROOT, false, new String[]{"-q", "--no-startup"}, "", |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
669 |
(a) -> assertCommand(a, "1+1", "$1 ==> 2"), |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
670 |
(a) -> assertCommand(a, "int x = 5", "") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
671 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
672 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
673 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
674 |
@Test |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
675 |
public void testOptionS() { |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
676 |
test(Locale.ROOT, false, new String[]{"-s", "--no-startup"}, "", |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
677 |
(a) -> assertCommand(a, "1+1", "") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
678 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
679 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
680 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
681 |
@Test |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
682 |
public void testOptionV() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
683 |
test(new String[]{"-v", "--no-startup"}, |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
684 |
(a) -> assertCommand(a, "1+1", |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
685 |
"$1 ==> 2\n" + |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
686 |
"| created scratch variable $1 : int") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
687 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
688 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
689 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
690 |
@Test |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
691 |
public void testOptionFeedback() { |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
692 |
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
|
693 |
(a) -> assertCommand(a, "1+1", "$1 ==> 2"), |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
694 |
(a) -> assertCommand(a, "int x = 5", "") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
695 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
696 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
697 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
698 |
@Test |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
699 |
public void testCompoundOptions() { |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
700 |
Consumer<String> confirmNoStartup = s -> { |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
701 |
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
|
702 |
.filter(l -> !l.isEmpty()) |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
703 |
.count(), "Expected no lines: " + s); |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
704 |
}; |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
705 |
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
|
706 |
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup), |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
707 |
(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
|
708 |
(a) -> assertCommand(a, "int x = 5", "") |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
709 |
); |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
710 |
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
|
711 |
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup), |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
712 |
(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
|
713 |
(a) -> assertCommand(a, "int x = 5", "") |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
714 |
); |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
715 |
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
|
716 |
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup), |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
717 |
(a) -> assertCommand(a, "1+1", "") |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
718 |
); |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
719 |
} |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
720 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
721 |
@Test |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
722 |
public void testOptionR() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
723 |
test(new String[]{"-R-Dthe.sound=blorp", "--no-startup"}, |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
724 |
(a) -> assertCommand(a, "System.getProperty(\"the.sound\")", |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
725 |
"$1 ==> \"blorp\"") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
726 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
727 |
} |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
728 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
729 |
@Test |
43038 | 730 |
public void testWrapSourceHandlerDiagCrash() { |
731 |
test(new String[]{"--add-exports", "jdk.javadoc/ALL-UNNAMED"}, |
|
732 |
(a) -> assertCommand(a, "1+1", "$1 ==> 2") |
|
733 |
); |
|
734 |
} |
|
735 |
||
736 |
@Test |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
737 |
public void test8156910() { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
738 |
test( |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
739 |
(a) -> assertCommandOutputContains(a, "System.out.println(\"%5d\", 10);", "%5d"), |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
740 |
(a) -> assertCommandOutputContains(a, "1234", "==> 1234") |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
741 |
); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
742 |
} |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
743 |
} |