38539
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 8157395 8157393 8157517
|
|
27 |
* @summary Tests of jshell comand options, and undoing operations
|
|
28 |
* @modules jdk.jshell/jdk.internal.jshell.tool
|
|
29 |
* @build ToolCommandOptionTest ReplToolTesting
|
|
30 |
* @run testng ToolCommandOptionTest
|
|
31 |
*/
|
|
32 |
import org.testng.annotations.Test;
|
|
33 |
import static org.testng.Assert.assertFalse;
|
|
34 |
|
|
35 |
@Test
|
|
36 |
public class ToolCommandOptionTest extends ReplToolTesting {
|
|
37 |
|
|
38 |
public void listTest() {
|
|
39 |
test(
|
|
40 |
(a) -> assertCommand(a, "int x;",
|
|
41 |
"x ==> 0"),
|
|
42 |
(a) -> assertCommand(a, "/li",
|
|
43 |
"1 : int x;"),
|
|
44 |
(a) -> assertCommandOutputStartsWith(a, "/lis -st",
|
|
45 |
"\n s1 : import"),
|
|
46 |
(a) -> assertCommandOutputStartsWith(a, "/list -all",
|
|
47 |
"\n s1 : import"),
|
|
48 |
(a) -> assertCommandOutputContains(a, "/list -all",
|
|
49 |
"1 : int x;"),
|
|
50 |
(a) -> assertCommandOutputContains(a, "/list -history",
|
|
51 |
"int x;"),
|
|
52 |
(a) -> assertCommandOutputContains(a, "/li -h",
|
|
53 |
"/lis -st"),
|
|
54 |
(a) -> assertCommand(a, "/list -furball",
|
|
55 |
"| Unknown option: -furball -- /list -furball"),
|
|
56 |
(a) -> assertCommand(a, "/list x",
|
|
57 |
"1 : int x;"),
|
|
58 |
(a) -> assertCommand(a, "/li x -start",
|
|
59 |
"| Options and snippets must not both be used: /list x -start"),
|
|
60 |
(a) -> assertCommand(a, "/l -st -al",
|
|
61 |
"| Conflicting options -- /list -st -al")
|
|
62 |
);
|
|
63 |
}
|
|
64 |
|
|
65 |
public void typesTest() {
|
|
66 |
test(
|
|
67 |
(a) -> assertCommand(a, "int x",
|
|
68 |
"x ==> 0"),
|
|
69 |
(a) -> assertCommand(a, "/types x",
|
|
70 |
"| This command does not accept the snippet 'x' : int x;"),
|
|
71 |
(a) -> assertCommand(a, "class C {}",
|
|
72 |
"| created class C"),
|
|
73 |
(a) -> assertCommand(a, "/ty",
|
|
74 |
"| class C"),
|
|
75 |
(a) -> assertCommand(a, "/ty -st",
|
|
76 |
""),
|
|
77 |
(a) -> assertCommand(a, "/types -all",
|
|
78 |
"| class C"),
|
|
79 |
(a) -> assertCommand(a, "/types -furball",
|
|
80 |
"| Unknown option: -furball -- /types -furball"),
|
|
81 |
(a) -> assertCommand(a, "/types C",
|
|
82 |
"| class C"),
|
|
83 |
(a) -> assertCommand(a, "/types C -start",
|
|
84 |
"| Options and snippets must not both be used: /types C -start"),
|
|
85 |
(a) -> assertCommand(a, "/ty -st -al",
|
|
86 |
"| Conflicting options -- /types -st -al")
|
|
87 |
);
|
|
88 |
}
|
|
89 |
|
|
90 |
public void dropTest() {
|
|
91 |
test(false, new String[]{"-nostartup"},
|
|
92 |
(a) -> assertCommand(a, "int x = 5;",
|
|
93 |
"x ==> 5"),
|
|
94 |
(a) -> assertCommand(a, "x",
|
|
95 |
"x ==> 5"),
|
|
96 |
(a) -> assertCommand(a, "long y;",
|
|
97 |
"y ==> 0"),
|
|
98 |
(a) -> assertCommand(a, "/drop -furball",
|
|
99 |
"| Unknown option: -furball -- /drop -furball"),
|
|
100 |
(a) -> assertCommand(a, "/drop -all",
|
|
101 |
"| Unknown option: -all -- /drop -all"),
|
|
102 |
(a) -> assertCommandOutputStartsWith(a, "/drop z",
|
|
103 |
"| No such snippet: z"),
|
|
104 |
(a) -> assertCommandOutputStartsWith(a, "/drop 2",
|
|
105 |
"| This command does not accept the snippet '2' : x"),
|
|
106 |
(a) -> assertCommand(a, "/dr x y",
|
|
107 |
"| dropped variable x\n" +
|
|
108 |
"| dropped variable y"),
|
|
109 |
(a) -> assertCommand(a, "/list",
|
|
110 |
"2 : x")
|
|
111 |
);
|
|
112 |
}
|
|
113 |
|
|
114 |
public void setEditorTest() {
|
|
115 |
test(
|
|
116 |
(a) -> assertCommand(a, "/set editor -furball",
|
|
117 |
"| Unknown option: -furball -- /set editor -furball"),
|
|
118 |
(a) -> assertCommand(a, "/set editor -furball prog",
|
|
119 |
"| Unknown option: -furball -- /set editor -furball prog"),
|
|
120 |
(a) -> assertCommand(a, "/set editor -furball -mattress",
|
|
121 |
"| Unknown option: -furball -mattress -- /set editor -furball -mattress"),
|
|
122 |
(a) -> assertCommand(a, "/set editor -default prog",
|
|
123 |
"| Specify -default option or program, not both -- /set editor -default prog"),
|
|
124 |
(a) -> assertCommand(a, "/set editor prog",
|
|
125 |
"| Editor set to: prog"),
|
|
126 |
(a) -> assertCommand(a, "/set editor prog -default",
|
|
127 |
"| Editor set to: prog"),
|
|
128 |
(a) -> assertCommand(a, "/se ed prog -furball",
|
|
129 |
"| Editor set to: prog"),
|
|
130 |
(a) -> assertCommand(a, "/set editor prog arg1 -furball arg3 -default arg4",
|
|
131 |
"| Editor set to: prog"),
|
|
132 |
(a) -> assertCommand(a, "/set editor -default",
|
|
133 |
""),
|
|
134 |
(a) -> assertCommand(a, "/se edi -def",
|
|
135 |
""),
|
|
136 |
(a) -> assertCommand(a, "/set editor",
|
|
137 |
"| The '/set editor' command requires a path argument")
|
|
138 |
);
|
|
139 |
}
|
|
140 |
|
|
141 |
public void retainEditorTest() {
|
|
142 |
test(
|
|
143 |
(a) -> assertCommand(a, "/retain editor -furball",
|
|
144 |
"| Unknown option: -furball -- /retain editor -furball"),
|
|
145 |
(a) -> assertCommand(a, "/retain editor -furball prog",
|
|
146 |
"| Unknown option: -furball -- /retain editor -furball prog"),
|
|
147 |
(a) -> assertCommand(a, "/retain editor -furball -mattress",
|
|
148 |
"| Unknown option: -furball -mattress -- /retain editor -furball -mattress"),
|
|
149 |
(a) -> assertCommand(a, "/retain editor -default prog",
|
|
150 |
"| Specify -default option or program, not both -- /retain editor -default prog"),
|
|
151 |
(a) -> assertCommand(a, "/retain editor prog",
|
|
152 |
"| Editor set to: prog"),
|
|
153 |
(a) -> assertCommand(a, "/retain editor prog -default",
|
|
154 |
"| Editor set to: prog"),
|
|
155 |
(a) -> assertCommand(a, "/ret ed prog -furball",
|
|
156 |
"| Editor set to: prog"),
|
|
157 |
(a) -> assertCommand(a, "/retain editor prog arg1 -furball arg3 -default arg4",
|
|
158 |
"| Editor set to: prog"),
|
|
159 |
(a) -> assertCommand(a, "/retain editor -default",
|
|
160 |
""),
|
|
161 |
(a) -> assertCommand(a, "/reta edi -def",
|
|
162 |
""),
|
|
163 |
(a) -> assertCommand(a, "/retain editor",
|
|
164 |
"")
|
|
165 |
);
|
|
166 |
}
|
|
167 |
|
|
168 |
public void setStartTest() {
|
|
169 |
test(
|
|
170 |
(a) -> assertCommand(a, "/set start -furball",
|
|
171 |
"| Unknown option: -furball -- /set start -furball"),
|
|
172 |
(a) -> assertCommand(a, "/set start -furball pyle",
|
|
173 |
"| Unknown option: -furball -- /set start -furball pyle"),
|
|
174 |
(a) -> assertCommand(a, "/se st pyle -furball",
|
|
175 |
"| Unknown option: -furball -- /set st pyle -furball"),
|
|
176 |
(a) -> assertCommand(a, "/set start -furball -mattress",
|
|
177 |
"| Unknown option: -furball -mattress -- /set start -furball -mattress"),
|
|
178 |
(a) -> assertCommand(a, "/set start foo -default",
|
|
179 |
"| Specify either one option or a startup file name -- /set start foo -default"),
|
|
180 |
(a) -> assertCommand(a, "/set start frfg",
|
|
181 |
"| File 'frfg' for '/set start' is not found."),
|
|
182 |
(a) -> assertCommand(a, "/set start -default",
|
|
183 |
""),
|
|
184 |
(a) -> assertCommand(a, "/se sta -no",
|
|
185 |
""),
|
|
186 |
(a) -> assertCommand(a, "/set start",
|
|
187 |
"| Specify either one option or a startup file name -- /set start")
|
|
188 |
);
|
|
189 |
}
|
|
190 |
|
|
191 |
public void retainStartTest() {
|
|
192 |
test(
|
|
193 |
(a) -> assertCommand(a, "/retain start -furball",
|
|
194 |
"| Unknown option: -furball -- /retain start -furball"),
|
|
195 |
(a) -> assertCommand(a, "/retain start -furball pyle",
|
|
196 |
"| Unknown option: -furball -- /retain start -furball pyle"),
|
|
197 |
(a) -> assertCommand(a, "/ret st pyle -furball",
|
|
198 |
"| Unknown option: -furball -- /retain st pyle -furball"),
|
|
199 |
(a) -> assertCommand(a, "/retain start -furball -mattress",
|
|
200 |
"| Unknown option: -furball -mattress -- /retain start -furball -mattress"),
|
|
201 |
(a) -> assertCommand(a, "/retain start foo -default",
|
|
202 |
"| Specify either one option or a startup file name -- /retain start foo -default"),
|
|
203 |
(a) -> assertCommand(a, "/retain start frfg",
|
|
204 |
"| File 'frfg' for '/retain start' is not found."),
|
|
205 |
(a) -> assertCommand(a, "/retain start -default",
|
|
206 |
""),
|
|
207 |
(a) -> assertCommand(a, "/ret sta -no",
|
|
208 |
""),
|
|
209 |
(a) -> assertCommand(a, "/retain start",
|
|
210 |
"")
|
|
211 |
);
|
|
212 |
}
|
|
213 |
|
|
214 |
public void setModeTest() {
|
|
215 |
test(
|
|
216 |
(a) -> assertCommandOutputStartsWith(a, "/set mode",
|
|
217 |
"| Missing the feedback mode"),
|
|
218 |
(a) -> assertCommandOutputStartsWith(a, "/set mode *",
|
|
219 |
"| Expected a feedback mode name: *"),
|
|
220 |
(a) -> assertCommandOutputStartsWith(a, "/set mode -quiet",
|
|
221 |
"| Missing the feedback mode"),
|
|
222 |
(a) -> assertCommandOutputStartsWith(a, "/set mode -quiet *",
|
|
223 |
"| Expected a feedback mode name: *"),
|
|
224 |
(a) -> assertCommandOutputStartsWith(a, "/set mode amode normal thing",
|
|
225 |
"| Unexpected arguments at end of command: thing"),
|
|
226 |
(a) -> assertCommand(a, "/set mode mymode",
|
|
227 |
"| Created new feedback mode: mymode"),
|
|
228 |
(a) -> assertCommand(a, "/set mode mymode -delete",
|
|
229 |
""),
|
|
230 |
(a) -> assertCommand(a, "/set mode mymode normal",
|
|
231 |
"| Created new feedback mode: mymode"),
|
|
232 |
(a) -> assertCommand(a, "/set mode -del mymode",
|
|
233 |
""),
|
|
234 |
(a) -> assertCommandOutputStartsWith(a, "/set mode mymode -command -quiet",
|
|
235 |
"| Conflicting options"),
|
|
236 |
(a) -> assertCommandOutputStartsWith(a, "/set mode mymode -delete -quiet",
|
|
237 |
"| Conflicting options"),
|
|
238 |
(a) -> assertCommandOutputStartsWith(a, "/set mode mymode -command -delete",
|
|
239 |
"| Conflicting options"),
|
|
240 |
(a) -> assertCommandOutputStartsWith(a, "/set mode mymode -d",
|
|
241 |
"| No feedback mode named: mymode"),
|
|
242 |
(a) -> assertCommandOutputStartsWith(a, "/set mode normal",
|
|
243 |
"| Not valid with a predefined mode: normal"),
|
|
244 |
(a) -> assertCommand(a, "/se mo -c mymode",
|
|
245 |
"| Created new feedback mode: mymode"),
|
|
246 |
(a) -> assertCommand(a, "/set feedback mymode",
|
|
247 |
"| Feedback mode: mymode"),
|
|
248 |
(a) -> assertCommandOutputStartsWith(a, "/set mode mymode -delete",
|
|
249 |
"| The current feedback mode 'mymode' cannot be deleted"),
|
|
250 |
(a) -> assertCommand(a, "/set feedback no",
|
|
251 |
"| Feedback mode: normal"),
|
|
252 |
(a) -> assertCommandOutputStartsWith(a, "/set mode mymode -delete",
|
|
253 |
""),
|
|
254 |
(a) -> assertCommandCheckOutput(a, "/set feedback",
|
|
255 |
(s) -> assertFalse(s.contains("mymode"), "Didn't delete: " + s))
|
|
256 |
);
|
|
257 |
}
|
|
258 |
|
|
259 |
public void setModeSmashTest() {
|
|
260 |
test(
|
|
261 |
(a) -> assertCommand(a, "/set mode mymode -command",
|
|
262 |
"| Created new feedback mode: mymode"),
|
|
263 |
(a) -> assertCommand(a, "/set feedback mymode",
|
|
264 |
"| Feedback mode: mymode"),
|
|
265 |
(a) -> assertCommand(a, "/set format mymode display 'blurb'",
|
|
266 |
""),
|
|
267 |
(a) -> assertCommand(a, "45",
|
|
268 |
"blurb"),
|
|
269 |
(a) -> assertCommand(a, "/set mode mymode normal",
|
|
270 |
"| Created new feedback mode: mymode"),
|
|
271 |
(a) -> assertCommandOutputContains(a, "45",
|
|
272 |
" ==> 45")
|
|
273 |
);
|
|
274 |
}
|
|
275 |
|
|
276 |
public void retainModeTest() {
|
|
277 |
test(
|
|
278 |
(a) -> assertCommandOutputStartsWith(a, "/retain mode",
|
|
279 |
"| Missing the feedback mode"),
|
|
280 |
(a) -> assertCommandOutputStartsWith(a, "/retain mode *",
|
|
281 |
"| Expected a feedback mode name: *"),
|
|
282 |
(a) -> assertCommandOutputStartsWith(a, "/retain mode amode normal",
|
|
283 |
"| Unexpected arguments at end of command: normal"),
|
|
284 |
(a) -> assertCommandOutputStartsWith(a, "/retain mode mymode",
|
|
285 |
"| Does not match any current feedback mode: mymode"),
|
|
286 |
(a) -> assertCommandOutputStartsWith(a, "/retain mode mymode -delete",
|
|
287 |
"| No feedback mode named: mymode"),
|
|
288 |
(a) -> assertCommandOutputStartsWith(a, "/retain mode -d mymode",
|
|
289 |
"| No feedback mode named: mymode"),
|
|
290 |
(a) -> assertCommandOutputStartsWith(a, "/retain mode normal",
|
|
291 |
"| Not valid with a predefined mode: normal"),
|
|
292 |
(a) -> assertCommand(a, "/set mode mymode verbose",
|
|
293 |
"| Created new feedback mode: mymode"),
|
|
294 |
(a) -> assertCommand(a, "/retain mode mymode",
|
|
295 |
""),
|
|
296 |
(a) -> assertCommand(a, "/set mode mymode -delete",
|
|
297 |
""),
|
|
298 |
(a) -> assertCommand(a, "/retain mode mymode -delete",
|
|
299 |
""),
|
|
300 |
(a) -> assertCommand(a, "/set mode kmode normal",
|
|
301 |
"| Created new feedback mode: kmode"),
|
|
302 |
(a) -> assertCommand(a, "/retain mode kmode",
|
|
303 |
""),
|
|
304 |
(a) -> assertCommand(a, "/set mode kmode -delete",
|
|
305 |
""),
|
|
306 |
(a) -> assertCommand(a, "/set mode tmode normal",
|
|
307 |
"| Created new feedback mode: tmode"),
|
|
308 |
(a) -> assertCommandOutputStartsWith(a, "/retain feedback tmode",
|
|
309 |
"| '/retain feedback <mode>' requires that <mode> is predefined or has been retained with '/retain mode'"),
|
|
310 |
(a) -> assertCommand(a, "/set format tmode display 'YES'",
|
|
311 |
""),
|
|
312 |
(a) -> assertCommand(a, "/set feedback tmode",
|
|
313 |
"| Feedback mode: tmode"),
|
|
314 |
(a) -> assertCommand(a, "45",
|
|
315 |
"YES"),
|
|
316 |
(a) -> assertCommand(a, "/retain mode tmode",
|
|
317 |
""),
|
|
318 |
(a) -> assertCommand(a, "/retain feedback tmode",
|
|
319 |
"| Feedback mode: tmode"),
|
|
320 |
(a) -> assertCommand(a, "/set format tmode display 'blurb'",
|
|
321 |
""),
|
|
322 |
(a) -> assertCommand(a, "45",
|
|
323 |
"blurb")
|
|
324 |
);
|
|
325 |
test(
|
|
326 |
(a) -> assertCommand(a, "45",
|
|
327 |
"YES"),
|
|
328 |
(a) -> assertCommand(a, "/set feedback kmode",
|
|
329 |
"| Feedback mode: kmode"),
|
|
330 |
(a) -> assertCommandOutputStartsWith(a, "/retain mode kmode -delete",
|
|
331 |
"| The current feedback mode 'kmode' cannot be deleted"),
|
|
332 |
(a) -> assertCommandOutputStartsWith(a, "/retain mode tmode -delete",
|
|
333 |
"| The retained feedback mode 'tmode' cannot be deleted"),
|
|
334 |
(a) -> assertCommand(a, "/retain feedback normal",
|
|
335 |
"| Feedback mode: normal"),
|
|
336 |
(a) -> assertCommand(a, "/retain mode tmode -delete",
|
|
337 |
""),
|
|
338 |
(a) -> assertCommandOutputStartsWith(a, "/retain mode kmode -delete",
|
|
339 |
"")
|
|
340 |
);
|
|
341 |
test(
|
|
342 |
(a) -> assertCommandOutputStartsWith(a, "/set feedback tmode",
|
|
343 |
"| Does not match any current feedback mode: tmode"),
|
|
344 |
(a) -> assertCommandOutputStartsWith(a, "/set feedback kmode",
|
|
345 |
"| Does not match any current feedback mode: kmode"),
|
|
346 |
(a) -> assertCommandOutputStartsWith(a, "/set feedback mymode",
|
|
347 |
"| Does not match any current feedback mode: mymode"),
|
|
348 |
(a) -> assertCommandCheckOutput(a, "/set feedback",
|
|
349 |
(s) -> assertFalse(s.contains("mymode"), "Didn't delete mymode: " + s)),
|
|
350 |
(a) -> assertCommandCheckOutput(a, "/set feedback",
|
|
351 |
(s) -> assertFalse(s.contains("kmode"), "Didn't delete kmode: " + s)),
|
|
352 |
(a) -> assertCommandCheckOutput(a, "/set feedback",
|
|
353 |
(s) -> assertFalse(s.contains("tmode"), "Didn't delete tmode: " + s))
|
|
354 |
);
|
|
355 |
}
|
|
356 |
|
|
357 |
}
|