author | jlaskey |
Wed, 09 Jan 2019 11:13:00 -0400 | |
changeset 53227 | f15d443f9731 |
parent 53058 | 83840e83476a |
child 55156 | 1c291d1c272c |
permissions | -rw-r--r-- |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
1 |
/* |
48610
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
48349
diff
changeset
|
2 |
* Copyright (c) 2016, 2018, 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 |
53058
83840e83476a
8215099: jshell tool: /help representation of ctrl/meta characters inconsistent
rfield
parents:
52938
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 8177466 8172154 8192979 8191842 8198573 8198801 8210596 8210959 8215099 |
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 |
52938 | 33 |
* @run testng/othervm ToolSimpleTest |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
34 |
*/ |
52214
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
35 |
|
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
36 |
import java.util.ArrayList; |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
37 |
import java.util.Arrays; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
38 |
import java.util.List; |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
39 |
import java.util.Locale; |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
40 |
import java.util.function.Consumer; |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
41 |
import java.util.regex.Pattern; |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
42 |
import java.util.stream.Collectors; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
43 |
import java.util.stream.Stream; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
44 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
45 |
import org.testng.annotations.Test; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
46 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
47 |
import static org.testng.Assert.assertEquals; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
48 |
import static org.testng.Assert.assertTrue; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
49 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
50 |
public class ToolSimpleTest extends ReplToolTesting { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
51 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
52 |
@Test |
37389 | 53 |
public void testRemaining() { |
54 |
test( |
|
55 |
(a) -> assertCommand(a, "int z; z =", "z ==> 0"), |
|
56 |
(a) -> assertCommand(a, "5", "z ==> 5"), |
|
57 |
(a) -> assertCommand(a, "/*nada*/; int q =", ""), |
|
58 |
(a) -> assertCommand(a, "77", "q ==> 77"), |
|
59 |
(a) -> assertCommand(a, "//comment;", ""), |
|
60 |
(a) -> assertCommand(a, "int v;", "v ==> 0"), |
|
61 |
(a) -> assertCommand(a, "int v; int c", |
|
62 |
"v ==> 0\n" + |
|
63 |
"c ==> 0") |
|
64 |
); |
|
65 |
} |
|
66 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
67 |
@Test |
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
68 |
public void testOpenComment() { |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
69 |
test( |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
70 |
(a) -> assertCommand(a, "int z = /* blah", ""), |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
71 |
(a) -> assertCommand(a, "baz */ 5", "z ==> 5"), |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
72 |
(a) -> assertCommand(a, "/** hoge ", ""), |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
73 |
(a) -> assertCommand(a, "baz **/", ""), |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
74 |
(a) -> assertCommand(a, "int v", "v ==> 0") |
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 |
} |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
38539
diff
changeset
|
77 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
78 |
@Test |
52213 | 79 |
public void testSwitchExpression() { |
80 |
test(false, new String[]{"--enable-preview", "--no-startup"}, |
|
81 |
(a) -> assertCommand(a, "enum Day {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY }", "| created enum Day"), |
|
82 |
(a) -> assertCommand(a, "Day day = Day.FRIDAY;", "day ==> FRIDAY"), |
|
83 |
(a) -> assertCommand(a, "switch (day) {", ""), |
|
84 |
(a) -> assertCommand(a, "case MONDAY, FRIDAY, SUNDAY -> 6;", ""), |
|
85 |
(a) -> assertCommand(a, "case TUESDAY -> 7;", ""), |
|
86 |
(a) -> assertCommand(a, "case THURSDAY, SATURDAY -> 8;", ""), |
|
87 |
(a) -> assertCommand(a, "case WEDNESDAY -> 9;", ""), |
|
88 |
(a) -> assertCommandOutputContains(a, "}", " ==> 6") |
|
89 |
); |
|
90 |
} |
|
91 |
||
92 |
@Test |
|
93 |
public void testSwitchExpressionCompletion() { |
|
94 |
test(false, new String[]{"--enable-preview", "--no-startup"}, |
|
95 |
(a) -> assertCommand(a, "enum Day {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY }", "| created enum Day"), |
|
96 |
(a) -> assertCommand(a, "Day day = Day.FRIDAY;", "day ==> FRIDAY"), |
|
97 |
(a) -> assertCommand(a, "switch (day) {", ""), |
|
98 |
(a) -> assertCommand(a, "case MONDAY, FRIDAY, SUNDAY -> 6;", ""), |
|
99 |
(a) -> assertCommand(a, "case TUESDAY -> 7;", ""), |
|
100 |
(a) -> assertCommand(a, "case THURSDAY, SATURDAY -> 8;", ""), |
|
101 |
(a) -> assertCommand(a, "case WEDNESDAY -> 9;", ""), |
|
102 |
(a) -> assertCommand(a, "} +", ""), |
|
103 |
(a) -> assertCommandOutputContains(a, "1000", " ==> 1006") |
|
104 |
); |
|
105 |
} |
|
106 |
||
107 |
@Test |
|
43586
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
108 |
public void testLessThan() { |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
109 |
test( |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
110 |
(a) -> assertCommand(a, "45", "$1 ==> 45"), |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
111 |
(a) -> assertCommand(a, "72", "$2 ==> 72"), |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
112 |
(a) -> assertCommand(a, "$1 < $2", "$3 ==> true"), |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
113 |
(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
|
114 |
"b ==> 0"), |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
115 |
(a) -> assertCommand(a, "a < b", "$6 ==> false") |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
116 |
); |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
117 |
} |
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
118 |
|
cc7a4eb79b29
8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents:
43274
diff
changeset
|
119 |
@Test |
49515
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
120 |
public void testChainedThrow() { |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
121 |
test( |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
122 |
(a) -> assertCommand(a, "void p() throws Exception { ((String) null).toString(); }", |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
123 |
"| created method p()"), |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
124 |
(a) -> assertCommand(a, "void n() throws Exception { try { p(); } catch (Exception ex) { throw new IOException(\"bar\", ex); }}", |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
125 |
"| created method n()"), |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
126 |
(a) -> assertCommand(a, "void m() { try { n(); } catch (Exception ex) { throw new RuntimeException(\"foo\", ex); }}", |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
127 |
"| created method m()"), |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
128 |
(a) -> assertCommand(a, "m()", |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
129 |
"| Exception java.lang.RuntimeException: foo\n" |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
130 |
+ "| at m (#3:1)\n" |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
131 |
+ "| at (#4:1)\n" |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
132 |
+ "| Caused by: java.io.IOException: bar\n" |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
133 |
+ "| at n (#2:1)\n" |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
134 |
+ "| ...\n" |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
135 |
+ "| Caused by: java.lang.NullPointerException\n" |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
136 |
+ "| at p (#1:1)\n" |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
137 |
+ "| ..."), |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
138 |
(a) -> assertCommand(a, "/drop p", |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
139 |
"| dropped method p()"), |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
140 |
(a) -> assertCommand(a, "m()", |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
141 |
"| attempted to call method n() which cannot be invoked until method p() is declared") |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
142 |
); |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
143 |
} |
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
144 |
|
083318155ad1
8198801: JShell: user exception chained cause not retained
rfield
parents:
48940
diff
changeset
|
145 |
@Test |
52214
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
146 |
public void testThrowWithPercent() { |
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
147 |
test( |
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
148 |
(a) -> assertCommandCheckOutput(a, |
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
149 |
"URI u = new URI(\"http\", null, \"h\", -1, \"a\" + (char)0x04, null, null);", (s) -> |
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
150 |
assertTrue(s.contains("URISyntaxException") && !s.contains("JShellTool"), |
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
151 |
"Output: '" + s + "'")), |
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
152 |
(a) -> assertCommandCheckOutput(a, |
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
153 |
"throw new Exception(\"%z\")", (s) -> |
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
154 |
assertTrue(s.contains("java.lang.Exception") && !s.contains("UnknownFormatConversionException"), |
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
155 |
"Output: '" + s + "'")) |
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
156 |
); |
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
157 |
} |
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
158 |
|
b3c7c5a62521
8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents:
52213
diff
changeset
|
159 |
@Test |
37389 | 160 |
public void oneLineOfError() { |
161 |
test( |
|
162 |
(a) -> assertCommand(a, "12+", null), |
|
163 |
(a) -> assertCommandCheckOutput(a, " true", (s) -> |
|
164 |
assertTrue(s.contains("12+") && !s.contains("true"), "Output: '" + s + "'")) |
|
165 |
); |
|
166 |
} |
|
167 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
168 |
@Test |
37389 | 169 |
public void defineVariables() { |
170 |
test( |
|
171 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
172 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
173 |
(a) -> assertVariable(a, "int", "a"), |
|
174 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
175 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
176 |
(a) -> assertVariable(a, "double", "a", "1", "1.0"), |
|
177 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
178 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
179 |
(a) -> evaluateExpression(a, "double", "2 * a", "2.0"), |
|
180 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
181 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()) |
|
182 |
); |
|
183 |
} |
|
184 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
185 |
@Test |
37389 | 186 |
public void defineMethods() { |
187 |
test( |
|
188 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
189 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
190 |
(a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"), |
|
191 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
192 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
193 |
(a) -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"), |
|
194 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
195 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
196 |
(a) -> assertMethod(a, "void g() {}", "()void", "g"), |
|
197 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
198 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
|
199 |
); |
|
200 |
} |
|
201 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
202 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
203 |
public void defineTypes() { |
37389 | 204 |
test( |
205 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
206 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 207 |
(a) -> assertClass(a, "class A { }", "class", "A"), |
208 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
209 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 210 |
(a) -> assertClass(a, "interface A { }", "interface", "A"), |
211 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
212 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 213 |
(a) -> assertClass(a, "enum A { }", "enum", "A"), |
214 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
215 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 216 |
(a) -> assertClass(a, "@interface A { }", "@interface", "A"), |
217 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
218 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()) |
37389 | 219 |
); |
220 |
} |
|
221 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
222 |
@Test |
37389 | 223 |
public void defineImports() { |
224 |
test( |
|
225 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
226 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
227 |
(a) -> assertImport(a, "import java.util.stream.Stream;", "", "java.util.stream.Stream"), |
|
228 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
229 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
230 |
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
|
231 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
232 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
233 |
(a) -> assertImport(a, "import static java.lang.Math.PI;", "static", "java.lang.Math.PI"), |
|
234 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
235 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()), |
|
236 |
(a) -> assertImport(a, "import static java.lang.Math.*;", "static", "java.lang.Math.*"), |
|
237 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
|
238 |
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()) |
|
239 |
); |
|
240 |
} |
|
241 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
242 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
243 |
public void defineVar() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
244 |
test( |
37389 | 245 |
(a) -> assertCommand(a, "int x = 72", "x ==> 72"), |
246 |
(a) -> assertCommand(a, "x", "x ==> 72"), |
|
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
247 |
(a) -> assertCommand(a, "/vars", "| int x = 72") |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
248 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
249 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
250 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
251 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
252 |
public void defineUnresolvedVar() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
253 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
254 |
(a) -> assertCommand(a, "undefined x", |
37389 | 255 |
"| 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
|
256 |
(a) -> assertCommand(a, "/vars", "| undefined x = (not-active)") |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
257 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
258 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
259 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
260 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
261 |
public void testUnresolved() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
262 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
263 |
(a) -> assertCommand(a, "int f() { return g() + x + new A().a; }", |
37389 | 264 |
"| 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
|
265 |
(a) -> assertCommand(a, "f()", |
37389 | 266 |
"| 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
|
267 |
(a) -> assertCommandOutputStartsWith(a, "int g() { return x; }", |
37389 | 268 |
"| created method g(), however, it cannot be invoked until variable x is declared"), |
269 |
(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
|
270 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
271 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
272 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
273 |
@Test |
37389 | 274 |
public void testUnknownCommand() { |
275 |
test((a) -> assertCommand(a, "/unknown", |
|
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
276 |
"| Invalid command: /unknown\n" + |
37389 | 277 |
"| Type /help for help.")); |
278 |
} |
|
279 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
280 |
@Test |
37389 | 281 |
public void testEmptyClassPath() { |
43038 | 282 |
test(after -> assertCommand(after, "/env --class-path", "| Argument to class-path missing.")); |
37389 | 283 |
} |
284 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
285 |
@Test |
43856
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43766
diff
changeset
|
286 |
public void testInvalidClassPath() { |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43766
diff
changeset
|
287 |
test( |
43861
825bad9a162a
8174862: JShell tests: new JDK-8174797 testInvalidClassPath fails on Windows
rfield
parents:
43856
diff
changeset
|
288 |
a -> assertCommand(a, "/env --class-path snurgefusal", |
48259
c0bf7d8af037
8191636: [Windows] jshell tool: Wrong character in /env class-path command crashes jshell
jlahoda
parents:
47837
diff
changeset
|
289 |
"| File 'snurgefusal' for '--class-path' is not found."), |
c0bf7d8af037
8191636: [Windows] jshell tool: Wrong character in /env class-path command crashes jshell
jlahoda
parents:
47837
diff
changeset
|
290 |
a -> assertCommand(a, "/env --class-path ?", |
c0bf7d8af037
8191636: [Windows] jshell tool: Wrong character in /env class-path command crashes jshell
jlahoda
parents:
47837
diff
changeset
|
291 |
"| File '?' for '--class-path' is not found.") |
43856
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43766
diff
changeset
|
292 |
); |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43766
diff
changeset
|
293 |
} |
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43766
diff
changeset
|
294 |
|
fcdebb803c62
8174797: jshell tool: invalid module path crashes tool
rfield
parents:
43766
diff
changeset
|
295 |
@Test |
37389 | 296 |
public void testNoArgument() { |
38539 | 297 |
test( |
298 |
(a) -> assertCommand(a, "/save", |
|
299 |
"| '/save' requires a filename argument."), |
|
300 |
(a) -> assertCommand(a, "/open", |
|
301 |
"| '/open' requires a filename argument."), |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
41514
diff
changeset
|
302 |
(a) -> assertCommandOutputStartsWith(a, "/drop", |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
41514
diff
changeset
|
303 |
"| In the /drop argument, please specify an import, variable, method, or class to drop.") |
38539 | 304 |
); |
37389 | 305 |
} |
306 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
307 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
308 |
public void testDebug() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
309 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
310 |
(a) -> assertCommand(a, "/deb", "| Debugging on"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
311 |
(a) -> assertCommand(a, "/debug", "| Debugging off"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
312 |
(a) -> assertCommand(a, "/debug", "| Debugging on"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
313 |
(a) -> assertCommand(a, "/deb", "| Debugging off") |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
314 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
315 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
316 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
317 |
@Test |
37389 | 318 |
public void testDrop() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
319 |
test(false, new String[]{"--no-startup"}, |
37389 | 320 |
a -> assertVariable(a, "int", "a"), |
321 |
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
|
322 |
a -> assertMethod(a, "int b() { return 0; }", "()int", "b"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
323 |
a -> dropMethod(a, "/drop 2", "int b()", "| dropped method b()"), |
37389 | 324 |
a -> assertClass(a, "class A {}", "class", "A"), |
325 |
a -> dropClass(a, "/drop 3", "class A", "| dropped class A"), |
|
326 |
a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
|
327 |
a -> dropImport(a, "/drop 4", "import java.util.stream.*", ""), |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
40601
diff
changeset
|
328 |
a -> assertCommand(a, "for (int i = 0; i < 10; ++i) {}", ""), |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
40601
diff
changeset
|
329 |
a -> assertCommand(a, "/drop 5", ""), |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
40601
diff
changeset
|
330 |
a -> assertCommand(a, "/list", ""), |
37389 | 331 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
332 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
333 |
a -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 334 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
335 |
); |
|
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
336 |
test(false, new String[]{"--no-startup"}, |
37389 | 337 |
a -> assertVariable(a, "int", "a"), |
338 |
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
|
339 |
a -> assertMethod(a, "int b() { return 0; }", "()int", "b"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
340 |
a -> dropMethod(a, "/drop b", "int b()", "| dropped method b()"), |
37389 | 341 |
a -> assertClass(a, "class A {}", "class", "A"), |
342 |
a -> dropClass(a, "/drop A", "class A", "| dropped class A"), |
|
343 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
|
344 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
345 |
a -> assertCommandCheckOutput(a, "/types", assertClasses()), |
37389 | 346 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
347 |
); |
|
348 |
} |
|
349 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
350 |
@Test |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
351 |
public void testDropRange() { |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
352 |
test(false, new String[]{"--no-startup"}, |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
353 |
a -> assertVariable(a, "int", "a"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
354 |
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
|
355 |
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
|
356 |
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
|
357 |
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
|
358 |
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
|
359 |
"| dropped class A\n" + |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
360 |
"| dropped method b()\n" + |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
361 |
"| dropped variable a\n"), |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
362 |
a -> assertCommand(a, "/list", "") |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
363 |
); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
364 |
} |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
365 |
|
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
366 |
@Test |
37389 | 367 |
public void testDropNegative() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
368 |
test(false, new String[]{"--no-startup"}, |
48349
3d4e8f5a2a69
8179858: jshell tool: sync nomenclature from reference to online /help
rfield
parents:
48292
diff
changeset
|
369 |
a -> assertCommandOutputStartsWith(a, "/drop 0", "| No snippet with ID: 0"), |
38539 | 370 |
a -> assertCommandOutputStartsWith(a, "/drop a", "| No such snippet: a"), |
37389 | 371 |
a -> assertCommandCheckOutput(a, "/drop", |
372 |
assertStartsWith("| In the /drop argument, please specify an import, variable, method, or class to drop.")), |
|
373 |
a -> assertVariable(a, "int", "a"), |
|
374 |
a -> assertCommand(a, "a", "a ==> 0"), |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
40601
diff
changeset
|
375 |
a -> assertCommand(a, "/drop 2", ""), |
38539 | 376 |
a -> assertCommand(a, "/drop 2", |
377 |
"| This command does not accept the snippet '2' : a\n" + |
|
378 |
"| See /types, /methods, /vars, or /list") |
|
37389 | 379 |
); |
380 |
} |
|
381 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
382 |
@Test |
37389 | 383 |
public void testAmbiguousDrop() { |
384 |
test( |
|
385 |
a -> assertVariable(a, "int", "a"), |
|
386 |
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), |
|
387 |
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
|
388 |
a -> assertCommand(a, "/drop a", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
389 |
"| dropped variable a\n" + |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
390 |
"| dropped method a()\n" + |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
391 |
"| dropped class a") |
37389 | 392 |
); |
393 |
test( |
|
394 |
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), |
|
395 |
a -> assertMethod(a, "double a(int a) { return 0; }", "(int)double", "a"), |
|
396 |
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
|
397 |
a -> assertCommand(a, "/drop a", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
398 |
"| dropped method a()\n" + |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
399 |
"| dropped method a(int)\n" + |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
400 |
"| dropped method a(double)\n") |
37389 | 401 |
); |
402 |
} |
|
403 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
404 |
@Test |
42412
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
405 |
public void testApplicationOfPost() { |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
406 |
test( |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
407 |
(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
|
408 |
(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
|
409 |
(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
|
410 |
(a) -> assertCommand(a, "/set prompt t \"+\" \"-\"", ""), |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
411 |
(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
|
412 |
); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
413 |
} |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
414 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
415 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
416 |
public void testHelpLength() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
417 |
Consumer<String> testOutput = (s) -> { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
418 |
List<String> ss = Stream.of(s.split("\n")) |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
419 |
.filter(l -> !l.isEmpty()) |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
420 |
.collect(Collectors.toList()); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
421 |
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
|
422 |
}; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
423 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
424 |
(a) -> assertCommandCheckOutput(a, "/?", testOutput), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
425 |
(a) -> assertCommandCheckOutput(a, "/help", testOutput), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
426 |
(a) -> assertCommandCheckOutput(a, "/help /list", testOutput) |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
427 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
428 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
429 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
430 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
431 |
public void testHelp() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
432 |
test( |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
433 |
(a) -> assertHelp(a, "/?", "/list", "/help", "/exit", "intro"), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
434 |
(a) -> assertHelp(a, "/help", "/list", "/help", "/exit", "intro"), |
53058
83840e83476a
8215099: jshell tool: /help representation of ctrl/meta characters inconsistent
rfield
parents:
52938
diff
changeset
|
435 |
(a) -> assertHelp(a, "/help short", "shortcuts", "Tab"), |
83840e83476a
8215099: jshell tool: /help representation of ctrl/meta characters inconsistent
rfield
parents:
52938
diff
changeset
|
436 |
(a) -> assertHelp(a, "/help keys", "line", "Shift", "imports", "history"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
437 |
(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
|
438 |
(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
|
439 |
(a) -> assertHelp(a, "/help /help", "/help <command>"), |
74af976d6798
8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents:
43861
diff
changeset
|
440 |
(a) -> assertHelp(a, "/help li", "/list -start"), |
74af976d6798
8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents:
43861
diff
changeset
|
441 |
(a) -> assertHelp(a, "/help fe", "/set feedback -retain") |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
442 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
443 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
444 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
445 |
@Test |
48273
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
446 |
public void testHelpStart() { |
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
447 |
test( |
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
448 |
(a) -> assertCommandCheckOutput(a, "/help /exit", |
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
449 |
s -> assertTrue(s.replaceAll("\\r\\n?", "\n").startsWith( |
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
450 |
"| \n" + |
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
451 |
"| /exit\n" + |
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
452 |
"| =====\n" + |
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
453 |
"| " |
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
454 |
)) |
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
455 |
) |
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
456 |
); |
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
457 |
} |
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
458 |
|
e2065f7505eb
8192979: jshell tool: Online help text for commands is confusing
rfield
parents:
47837
diff
changeset
|
459 |
@Test |
42412
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
460 |
public void testHelpFormat() { |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
461 |
test( |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
462 |
(a) -> assertCommandCheckOutput(a, "/help", s -> { |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
463 |
String[] lines = s.split("\\R"); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
464 |
assertTrue(lines.length > 20, |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
465 |
"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
|
466 |
+ "\n" + s); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
467 |
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
|
468 |
String l = lines[i]; |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
469 |
assertTrue(l.startsWith("| "), |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
470 |
"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
|
471 |
assertTrue(l.length() <= 80, |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
472 |
"/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
|
473 |
} |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
474 |
}) |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
475 |
); |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
476 |
} |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
477 |
|
45602
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
478 |
@Test |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
479 |
public void testConfusedUserPseudoCommands() { |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
480 |
test( |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
481 |
(a) -> assertHelp(a, "/-<n>", "last snippet", "digits"), |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
482 |
(a) -> assertHelp(a, "/<id>", "last snippet", "digits") |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
483 |
); |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
484 |
} |
7aeef976cb06
8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents:
45215
diff
changeset
|
485 |
|
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
486 |
private void assertHelp(boolean a, String command, String... find) { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
487 |
assertCommandCheckOutput(a, command, s -> { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
488 |
for (String f : find) { |
42412
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
489 |
assertTrue(s.contains(f), |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
490 |
"Expected output of " + command + " to contain: " + f |
ca6f4f1914b2
8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents:
41937
diff
changeset
|
491 |
+ "\n" + s); |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
492 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
493 |
}); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
494 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
495 |
|
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
496 |
// 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
|
497 |
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
|
498 |
String trimmed = in.trim(); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
499 |
String[] res = trimmed.isEmpty() |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
500 |
? new String[0] |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
501 |
: trimmed.split("\n"); |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
502 |
assertEquals(res.length, match.size(), "Got: " + Arrays.asList(res)); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
503 |
for (int i = 0; i < match.size(); ++i) { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
504 |
assertTrue(res[i].contains(match.get(i))); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
505 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
506 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
507 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
508 |
@Test |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
509 |
public void testListArgs() { |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
510 |
String arg = "qqqq"; |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
511 |
List<String> startVarList = new ArrayList<>(START_UP); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
512 |
startVarList.add("int aardvark"); |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
513 |
startVarList.add("int weevil"); |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
514 |
test( |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
515 |
a -> assertCommandCheckOutput(a, "/list -all", |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
516 |
s -> checkLineToList(s, START_UP)), |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
517 |
a -> assertCommandOutputStartsWith(a, "/list " + arg, |
38539 | 518 |
"| No such snippet: " + arg), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
519 |
a -> assertVariable(a, "int", "aardvark"), |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
520 |
a -> assertVariable(a, "int", "weevil"), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
521 |
a -> assertCommandOutputContains(a, "/list aardvark", "aardvark"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
522 |
a -> assertCommandCheckOutput(a, "/list -start", |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
523 |
s -> checkLineToList(s, START_UP)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
524 |
a -> assertCommandCheckOutput(a, "/list -all", |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
525 |
s -> checkLineToList(s, startVarList)), |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
526 |
a -> assertCommandOutputStartsWith(a, "/list s3", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
527 |
"s3 : import"), |
45215
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
528 |
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
|
529 |
s -> { |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
530 |
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
|
531 |
"No match: " + s); |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
532 |
}), |
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
533 |
a -> assertCommandOutputStartsWith(a, "/list " + arg, |
38539 | 534 |
"| No such snippet: " + arg) |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
535 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
536 |
} |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
537 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
538 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
539 |
public void testVarsArgs() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
540 |
String arg = "qqqq"; |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
541 |
List<String> startVarList = new ArrayList<>(); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
542 |
test( |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
543 |
a -> assertCommandCheckOutput(a, "/vars -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
544 |
s -> checkLineToList(s, startVarList)), |
38539 | 545 |
a -> assertCommand(a, "/vars " + arg, |
546 |
"| No such snippet: " + arg), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
547 |
a -> assertVariable(a, "int", "aardvark"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
548 |
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
|
549 |
a -> assertVariable(a, "int", "a"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
550 |
a -> assertVariable(a, "double", "a", "1", "1.0"), |
38539 | 551 |
a -> assertCommandOutputStartsWith(a, "/vars aardvark", |
552 |
"| int aardvark = 0"), |
|
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
553 |
a -> assertCommandCheckOutput(a, "/vars -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
554 |
s -> checkLineToList(s, startVarList)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
555 |
a -> assertCommandOutputStartsWith(a, "/vars -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
556 |
"| 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
|
557 |
a -> assertCommandOutputStartsWith(a, "/vars 1-4", |
c9477e22877f
8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents:
44454
diff
changeset
|
558 |
"| 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
|
559 |
a -> assertCommandOutputStartsWith(a, "/vars f", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
560 |
"| This command does not accept the snippet 'f'"), |
38539 | 561 |
a -> assertCommand(a, "/var " + arg, |
562 |
"| No such snippet: " + arg) |
|
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
563 |
); |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
564 |
} |
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
565 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
566 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
567 |
public void testMethodsArgs() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
568 |
String arg = "qqqq"; |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
569 |
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
|
570 |
test(new String[]{"--startup", "PRINTING"}, |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
571 |
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
|
572 |
s -> checkLineToList(s, printingMethodList)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
573 |
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
|
574 |
s -> checkLineToList(s, printingMethodList)), |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
575 |
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
|
576 |
s -> checkLineToList(s, printingMethodList)), |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
577 |
a -> assertCommandCheckOutput(a, "/methods println", |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
578 |
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
|
579 |
a -> assertCommandCheckOutput(a, "/methods", |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
580 |
s -> checkLineToList(s, printingMethodList)), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
581 |
a -> assertCommandOutputStartsWith(a, "/methods " + arg, |
38539 | 582 |
"| No such snippet: " + arg), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
583 |
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
|
584 |
a -> assertVariable(a, "int", "aardvark"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
585 |
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
|
586 |
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
|
587 |
a -> assertCommandOutputStartsWith(a, "/methods " + arg, |
38539 | 588 |
"| No such snippet: " + arg), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
589 |
a -> assertCommandOutputStartsWith(a, "/methods aardvark", |
38539 | 590 |
"| 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
|
591 |
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
|
592 |
s -> checkLineToList(s, printingMethodList)), |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
593 |
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
|
594 |
s -> checkLineToList(s, printingMethodList)), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
595 |
a -> assertCommandOutputStartsWith(a, "/methods g", |
43759
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
596 |
"| void g()"), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
597 |
a -> assertCommandOutputStartsWith(a, "/methods f", |
43759
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
598 |
"| int f()\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
599 |
"| void f(int)") |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
600 |
); |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
601 |
} |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
602 |
|
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
603 |
@Test |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
604 |
public void testMethodsWithErrors() { |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
605 |
test(new String[]{"--no-startup"}, |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
606 |
a -> assertCommand(a, "double m(int x) { return x; }", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
607 |
"| created method m(int)"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
608 |
a -> assertCommand(a, "GARBAGE junk() { return TRASH; }", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
609 |
"| 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
|
610 |
a -> assertCommand(a, "int w = 5;", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
611 |
"w ==> 5"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
612 |
a -> assertCommand(a, "int tyer() { return w; }", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
613 |
"| created method tyer()"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
614 |
a -> assertCommand(a, "String w = \"hi\";", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
615 |
"w ==> \"hi\""), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
616 |
a -> assertCommand(a, "/methods", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
617 |
"| double m(int)\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
618 |
"| GARBAGE junk()\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
619 |
"| 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
|
620 |
"| int tyer()\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
621 |
"| 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
|
622 |
"| 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
|
623 |
"| int tyer() { return w; }\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
624 |
"| ^\n") |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
625 |
); |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
626 |
} |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
627 |
|
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
628 |
@Test |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
629 |
public void testTypesWithErrors() { |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
630 |
test(new String[]{"--no-startup"}, |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
631 |
a -> assertCommand(a, "class C extends NONE { int x; }", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
632 |
"| 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
|
633 |
a -> assertCommand(a, "class D { void m() { System.out.println(nada); } }", |
43766
498b07dcf851
8174262: Error message misspelling: "instanciated"
rfield
parents:
43759
diff
changeset
|
634 |
"| 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
|
635 |
a -> assertCommand(a, "/types", |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
636 |
"| class C\n" + |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43586
diff
changeset
|
637 |
"| 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
|
638 |
"| class D\n" + |
43766
498b07dcf851
8174262: Error message misspelling: "instanciated"
rfield
parents:
43759
diff
changeset
|
639 |
"| 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
|
640 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
641 |
} |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
642 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
643 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
644 |
public void testTypesArgs() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
645 |
String arg = "qqqq"; |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
646 |
List<String> startTypeList = new ArrayList<>(); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
647 |
test( |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
648 |
a -> assertCommandCheckOutput(a, "/types -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
649 |
s -> checkLineToList(s, startTypeList)), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
650 |
a -> assertCommandCheckOutput(a, "/types -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
651 |
s -> checkLineToList(s, startTypeList)), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
652 |
a -> assertCommandOutputStartsWith(a, "/types " + arg, |
38539 | 653 |
"| No such snippet: " + arg), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
654 |
a -> assertVariable(a, "int", "aardvark"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
655 |
(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
|
656 |
(a) -> assertClass(a, "interface A { }", "interface", "A"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
657 |
a -> assertCommandOutputStartsWith(a, "/types -all", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
658 |
"| class A\n" + |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
659 |
"| interface A"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
660 |
(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
|
661 |
(a) -> assertClass(a, "@interface B { }", "@interface", "B"), |
38539 | 662 |
a -> assertCommand(a, "/types aardvark", |
663 |
"| 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
|
664 |
a -> assertCommandOutputStartsWith(a, "/types A", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
665 |
"| interface A"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
666 |
a -> assertCommandOutputStartsWith(a, "/types E", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
667 |
"| enum E"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
668 |
a -> assertCommandOutputStartsWith(a, "/types B", |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
669 |
"| @interface B"), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
670 |
a -> assertCommandOutputStartsWith(a, "/types " + arg, |
38539 | 671 |
"| No such snippet: " + arg), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
672 |
a -> assertCommandCheckOutput(a, "/types -start", |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
673 |
s -> checkLineToList(s, startTypeList)) |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
674 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
675 |
} |
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
676 |
|
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
677 |
@Test |
43274
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
678 |
public void testBlankLinesInSnippetContinuation() { |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
679 |
test(Locale.ROOT, false, new String[]{"--no-startup"}, "", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
680 |
a -> assertCommand(a, "class C {", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
681 |
""), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
682 |
a -> assertCommand(a, "", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
683 |
""), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
684 |
a -> assertCommand(a, "", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
685 |
""), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
686 |
a -> assertCommand(a, " int x;", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
687 |
""), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
688 |
a -> assertCommand(a, "", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
689 |
""), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
690 |
a -> assertCommand(a, "", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
691 |
""), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
692 |
a -> assertCommand(a, "}", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
693 |
"| created class C"), |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
694 |
a -> assertCommand(a, "/list", |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
695 |
"\n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
696 |
" 1 : class C {\n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
697 |
" \n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
698 |
" \n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
699 |
" int x;\n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
700 |
" \n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
701 |
" \n" + |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
702 |
" }") |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
703 |
); |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
704 |
} |
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
705 |
|
6b5ed4f9fb81
8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents:
43038
diff
changeset
|
706 |
@Test |
42972
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
707 |
public void testCompoundStart() { |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
708 |
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
|
709 |
(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
|
710 |
"", "", null, "3.14", "") |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
711 |
); |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
712 |
} |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
713 |
|
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
714 |
@Test |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
715 |
public void testJavaSeStart() { |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
716 |
test(new String[]{"--startup", "JAVASE"}, |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
717 |
(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
|
718 |
"$1 ==> WALL") |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
719 |
); |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
720 |
} |
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
721 |
|
47ca49eee534
8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents:
42969
diff
changeset
|
722 |
@Test |
47837
ef7aad81c3d6
8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents:
47268
diff
changeset
|
723 |
public void testJavaSeSetStart() { |
ef7aad81c3d6
8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents:
47268
diff
changeset
|
724 |
test( |
ef7aad81c3d6
8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents:
47268
diff
changeset
|
725 |
(a) -> assertCommand(a, "/set sta JAVASE", ""), |
ef7aad81c3d6
8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents:
47268
diff
changeset
|
726 |
(a) -> assertCommand(a, "/reset", "| Resetting state."), |
ef7aad81c3d6
8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents:
47268
diff
changeset
|
727 |
(a) -> assertCommandCheckOutput(a, "/li -a", |
ef7aad81c3d6
8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents:
47268
diff
changeset
|
728 |
s -> assertTrue(s.split("import ").length > 160, |
ef7aad81c3d6
8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents:
47268
diff
changeset
|
729 |
"not enough imports for JAVASE:\n" + s)) |
ef7aad81c3d6
8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents:
47268
diff
changeset
|
730 |
); |
ef7aad81c3d6
8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents:
47268
diff
changeset
|
731 |
} |
ef7aad81c3d6
8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents:
47268
diff
changeset
|
732 |
|
ef7aad81c3d6
8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents:
47268
diff
changeset
|
733 |
@Test |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
734 |
public void defineClasses() { |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
735 |
test( |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
736 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
737 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
738 |
(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
|
739 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
740 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
741 |
(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
|
742 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
743 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
744 |
(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
|
745 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
746 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
747 |
(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
|
748 |
(a) -> assertCommandCheckOutput(a, "/list", assertList()), |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
749 |
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()) |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
750 |
); |
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37745
diff
changeset
|
751 |
} |
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
752 |
|
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
753 |
@Test |
37389 | 754 |
public void testCommandPrefix() { |
755 |
test(a -> assertCommandCheckOutput(a, "/s", |
|
756 |
assertStartsWith("| Command: '/s' is ambiguous: /save, /set")), |
|
757 |
a -> assertCommand(a, "int var", "var ==> 0"), |
|
758 |
a -> assertCommandCheckOutput(a, "/va", |
|
759 |
assertStartsWith("| int var = 0")), |
|
760 |
a -> assertCommandCheckOutput(a, "/save", |
|
761 |
assertStartsWith("| '/save' requires a filename argument."))); |
|
762 |
} |
|
763 |
||
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
764 |
@Test |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
765 |
public void testOptionQ() { |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
766 |
test(Locale.ROOT, false, new String[]{"-q", "--no-startup"}, "", |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
767 |
(a) -> assertCommand(a, "1+1", "$1 ==> 2"), |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
768 |
(a) -> assertCommand(a, "int x = 5", "") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
769 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
770 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
771 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
772 |
@Test |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
773 |
public void testOptionS() { |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
774 |
test(Locale.ROOT, false, new String[]{"-s", "--no-startup"}, "", |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
775 |
(a) -> assertCommand(a, "1+1", "") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
776 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
777 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
778 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
779 |
@Test |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
780 |
public void testOptionV() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
781 |
test(new String[]{"-v", "--no-startup"}, |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
782 |
(a) -> assertCommand(a, "1+1", |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
783 |
"$1 ==> 2\n" + |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
784 |
"| created scratch variable $1 : int") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
785 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
786 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
787 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
788 |
@Test |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
789 |
public void testOptionFeedback() { |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
790 |
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
|
791 |
(a) -> assertCommand(a, "1+1", "$1 ==> 2"), |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
792 |
(a) -> assertCommand(a, "int x = 5", "") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
793 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
794 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
795 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
796 |
@Test |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
797 |
public void testCompoundOptions() { |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
798 |
Consumer<String> confirmNoStartup = s -> { |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
799 |
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
|
800 |
.filter(l -> !l.isEmpty()) |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
801 |
.count(), "Expected no lines: " + s); |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
802 |
}; |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
803 |
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
|
804 |
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup), |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
805 |
(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
|
806 |
(a) -> assertCommand(a, "int x = 5", "") |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
807 |
); |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
808 |
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
|
809 |
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup), |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
810 |
(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
|
811 |
(a) -> assertCommand(a, "int x = 5", "") |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
812 |
); |
41937
1313399705e9
8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents:
41635
diff
changeset
|
813 |
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
|
814 |
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup), |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
815 |
(a) -> assertCommand(a, "1+1", "") |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
816 |
); |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
817 |
} |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
818 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
819 |
@Test |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
820 |
public void testOptionR() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38835
diff
changeset
|
821 |
test(new String[]{"-R-Dthe.sound=blorp", "--no-startup"}, |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
822 |
(a) -> assertCommand(a, "System.getProperty(\"the.sound\")", |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
823 |
"$1 ==> \"blorp\"") |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
824 |
); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37389
diff
changeset
|
825 |
} |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
826 |
|
42969
a48d4f74d322
8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents:
42412
diff
changeset
|
827 |
@Test |
43038 | 828 |
public void testWrapSourceHandlerDiagCrash() { |
829 |
test(new String[]{"--add-exports", "jdk.javadoc/ALL-UNNAMED"}, |
|
830 |
(a) -> assertCommand(a, "1+1", "$1 ==> 2") |
|
831 |
); |
|
832 |
} |
|
833 |
||
834 |
@Test |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
835 |
public void test8156910() { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
836 |
test( |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
837 |
(a) -> assertCommandOutputContains(a, "System.out.println(\"%5d\", 10);", "%5d"), |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
838 |
(a) -> assertCommandOutputContains(a, "1234", "==> 1234") |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
839 |
); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
840 |
} |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
841 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
842 |
@Test |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
843 |
public void testIntersection() { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
844 |
test( |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
845 |
(a) -> assertCommandOutputContains(a, "<Z extends Runnable&CharSequence> Z get1() { return null; }", "get1()"), |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
846 |
(a) -> assertCommandOutputContains(a, "var g1 = get1()", "g1"), |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
847 |
(a) -> assertCommand(a, "/vars g1", "| CharSequence&Runnable g1 = null"), |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
848 |
(a) -> assertCommandOutputContains(a, "<Z extends Number&CharSequence> Z get2() { return null; }", "get2()"), |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
849 |
(a) -> assertCommandOutputContains(a, "var g2 = get2()", "g2"), |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
850 |
(a) -> assertCommand(a, "/vars g2", "| Number&CharSequence g2 = null") |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
851 |
); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
852 |
} |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
853 |
|
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
854 |
@Test |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
855 |
public void testAnonymous() { |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
856 |
test( |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
857 |
(a) -> assertCommandOutputContains(a, "var r1 = new Object() {}", "r1"), |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
858 |
(a) -> assertCommandOutputContains(a, "/vars r1", "| <anonymous class extending Object> r1 = "), |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
859 |
(a) -> assertCommandOutputContains(a, "var r2 = new Runnable() { public void run() { } }", "r2"), |
48610
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
48349
diff
changeset
|
860 |
(a) -> assertCommandOutputContains(a, "/vars r2", "| <anonymous class implementing Runnable> r2 = "), |
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
48349
diff
changeset
|
861 |
(a) -> assertCommandOutputContains(a, "import java.util.stream.*;", ""), |
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
48349
diff
changeset
|
862 |
(a) -> assertCommandOutputContains(a, "var list = Stream.of(1, 2, 3).map(j -> new Object() { int i = j; }).collect(Collectors.toList());", |
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
48349
diff
changeset
|
863 |
"list"), |
a587f95313f1
8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents:
48349
diff
changeset
|
864 |
(a) -> assertCommandOutputContains(a, "/vars list", "| List<<anonymous class extending Object>> list = ") |
47268
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
865 |
); |
48ec75306997
8177466: Add compiler support for local variable type-inference
mcimadamore
parents:
47216
diff
changeset
|
866 |
} |
48940 | 867 |
|
868 |
// This is mainly interesting in the TestLocalSimpleTest case (8198573) |
|
869 |
@Test |
|
870 |
public void testUpdateFalsePositive() { |
|
871 |
test( |
|
872 |
a -> assertClass(a, "class A { int a() { int error = 0; return error; } }", "class", "A"), |
|
873 |
a -> assertVariable(a, "A", "a", "new A()", "A@.+"), |
|
874 |
a -> assertVariable(a, "int", "error", "4711", "4711"), |
|
875 |
a -> assertCommandOutputContains(a, "a", "A@") |
|
876 |
); |
|
877 |
} |
|
37007
6023a9a9d58a
8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff
changeset
|
878 |
} |