author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 52938 | 5ff7480c9e28 |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48272
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
33362 | 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 |
||
47840 | 24 |
/* |
25 |
* @test 8151754 8080883 8160089 8170162 8166581 8172102 8171343 8178023 8186708 8179856 8185840 8190383 |
|
26 |
* @summary Testing startExCe-up options. |
|
35359 | 27 |
* @modules jdk.compiler/com.sun.tools.javac.api |
28 |
* jdk.compiler/com.sun.tools.javac.main |
|
36526 | 29 |
* jdk.jdeps/com.sun.tools.javap |
35359 | 30 |
* jdk.jshell/jdk.internal.jshell.tool |
33362 | 31 |
* @library /tools/lib |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36715
diff
changeset
|
32 |
* @build Compiler toolbox.ToolBox |
33362 | 33 |
* @run testng StartOptionTest |
34 |
*/ |
|
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
35 |
import java.io.ByteArrayInputStream; |
33362 | 36 |
import java.io.ByteArrayOutputStream; |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
37 |
import java.io.InputStream; |
33362 | 38 |
import java.io.PrintStream; |
39 |
import java.nio.charset.StandardCharsets; |
|
40 |
import java.nio.file.Path; |
|
41641
a628785b9dd9
8167637: jshell tool: /edit should use EDITOR setting
rfield
parents:
40767
diff
changeset
|
41 |
import java.util.HashMap; |
36990 | 42 |
import java.util.Locale; |
33362 | 43 |
import java.util.function.Consumer; |
44 |
||
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43367
diff
changeset
|
45 |
import java.util.logging.Level; |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43367
diff
changeset
|
46 |
import java.util.logging.Logger; |
52938 | 47 |
import java.util.regex.Pattern; |
48 |
||
33362 | 49 |
import org.testng.annotations.AfterMethod; |
50 |
import org.testng.annotations.BeforeMethod; |
|
51 |
import org.testng.annotations.Test; |
|
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
52 |
import jdk.jshell.tool.JavaShellToolBuilder; |
33362 | 53 |
import static org.testng.Assert.assertEquals; |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
54 |
import static org.testng.Assert.assertFalse; |
33362 | 55 |
import static org.testng.Assert.assertTrue; |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41641
diff
changeset
|
56 |
import static org.testng.Assert.fail; |
33362 | 57 |
|
58 |
@Test |
|
59 |
public class StartOptionTest { |
|
60 |
||
47840 | 61 |
protected ByteArrayOutputStream cmdout; |
62 |
protected ByteArrayOutputStream cmderr; |
|
63 |
protected ByteArrayOutputStream console; |
|
64 |
protected ByteArrayOutputStream userout; |
|
65 |
protected ByteArrayOutputStream usererr; |
|
66 |
protected InputStream cmdInStream; |
|
33362 | 67 |
|
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
68 |
private JavaShellToolBuilder builder() { |
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43367
diff
changeset
|
69 |
// turn on logging of launch failures |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43367
diff
changeset
|
70 |
Logger.getLogger("jdk.jshell.execution").setLevel(Level.ALL); |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
71 |
return JavaShellToolBuilder |
47840 | 72 |
.builder() |
73 |
.out(new PrintStream(cmdout), new PrintStream(console), new PrintStream(userout)) |
|
74 |
.err(new PrintStream(cmderr), new PrintStream(usererr)) |
|
75 |
.in(cmdInStream, null) |
|
76 |
.persistence(new HashMap<>()) |
|
77 |
.env(new HashMap<>()) |
|
78 |
.locale(Locale.ROOT); |
|
33362 | 79 |
} |
80 |
||
47840 | 81 |
protected int runShell(String... args) { |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
82 |
try { |
47840 | 83 |
return builder() |
84 |
.start(args); |
|
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
85 |
} catch (Exception ex) { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
86 |
fail("Repl tool died with exception", ex); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
87 |
} |
47840 | 88 |
return -1; // for compiler |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
89 |
} |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
90 |
|
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
91 |
protected void check(ByteArrayOutputStream str, Consumer<String> checkOut, String label) { |
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
92 |
byte[] bytes = str.toByteArray(); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
93 |
str.reset(); |
47840 | 94 |
String out = new String(bytes, StandardCharsets.UTF_8); |
52938 | 95 |
out = stripAnsi(out); |
96 |
out = out.replaceAll("[\r\n]+", "\n"); |
|
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
97 |
if (checkOut != null) { |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
98 |
checkOut.accept(out); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
99 |
} else { |
47840 | 100 |
assertEquals(out, "", label + ": Expected empty -- "); |
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
101 |
} |
33362 | 102 |
} |
103 |
||
47840 | 104 |
protected void checkExit(int ec, Consumer<Integer> checkCode) { |
105 |
if (checkCode != null) { |
|
106 |
checkCode.accept(ec); |
|
107 |
} else { |
|
108 |
assertEquals(ec, 0, "Expected standard exit code (0), but found: " + ec); |
|
109 |
} |
|
110 |
} |
|
111 |
||
112 |
// Start and check the resultant: exit code (Ex), command output (Co), |
|
113 |
// user output (Uo), command error (Ce), and console output (Cn) |
|
114 |
protected void startExCoUoCeCn(Consumer<Integer> checkExitCode, |
|
115 |
Consumer<String> checkCmdOutput, |
|
116 |
Consumer<String> checkUserOutput, |
|
117 |
Consumer<String> checkError, |
|
118 |
Consumer<String> checkConsole, |
|
119 |
String... args) { |
|
120 |
int ec = runShell(args); |
|
121 |
checkExit(ec, checkExitCode); |
|
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
122 |
check(cmdout, checkCmdOutput, "cmdout"); |
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
123 |
check(cmderr, checkError, "cmderr"); |
47840 | 124 |
check(console, checkConsole, "console"); |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
125 |
check(userout, checkUserOutput, "userout"); |
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
126 |
check(usererr, null, "usererr"); |
33362 | 127 |
} |
128 |
||
47840 | 129 |
// Start with an exit code and command error check |
130 |
protected void startExCe(int eec, Consumer<String> checkError, String... args) { |
|
131 |
StartOptionTest.this.startExCoUoCeCn( |
|
132 |
(Integer ec) -> assertEquals((int) ec, eec, |
|
133 |
"Expected error exit code (" + eec + "), but found: " + ec), |
|
134 |
null, null, checkError, null, args); |
|
135 |
} |
|
136 |
||
137 |
// Start with a command output check |
|
138 |
protected void startCo(Consumer<String> checkCmdOutput, String... args) { |
|
139 |
StartOptionTest.this.startExCoUoCeCn(null, checkCmdOutput, null, null, null, args); |
|
140 |
} |
|
141 |
||
142 |
private Consumer<String> assertOrNull(String expected, String label) { |
|
143 |
return expected == null |
|
144 |
? null |
|
48272
128de6a38f8e
8191455: jdk/jshell/StartOptionTest.java and jdk/jshell/ToolProviderTest.java failed after changeset e0f08a
rfield
parents:
47840
diff
changeset
|
145 |
: s -> assertEquals(s.replaceAll("\\r\\n?", "\n").trim(), expected.trim(), label); |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
146 |
} |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
147 |
|
47840 | 148 |
// Start and check the resultant: exit code (Ex), command output (Co), |
149 |
// user output (Uo), command error (Ce), and console output (Cn) |
|
150 |
protected void startExCoUoCeCn(int expectedExitCode, |
|
151 |
String expectedCmdOutput, |
|
152 |
String expectedUserOutput, |
|
153 |
String expectedError, |
|
154 |
String expectedConsole, |
|
155 |
String... args) { |
|
156 |
startExCoUoCeCn( |
|
157 |
expectedExitCode == 0 |
|
158 |
? null |
|
159 |
: (Integer i) -> assertEquals((int) i, expectedExitCode, |
|
160 |
"Expected exit code (" + expectedExitCode + "), but found: " + i), |
|
161 |
assertOrNull(expectedCmdOutput, "cmdout: "), |
|
162 |
assertOrNull(expectedUserOutput, "userout: "), |
|
163 |
assertOrNull(expectedError, "cmderr: "), |
|
164 |
assertOrNull(expectedConsole, "console: "), |
|
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
165 |
args); |
33362 | 166 |
} |
167 |
||
47840 | 168 |
// Start with an expected exit code and command error |
169 |
protected void startExCe(int ec, String expectedError, String... args) { |
|
170 |
startExCoUoCeCn(ec, null, null, expectedError, null, args); |
|
171 |
} |
|
172 |
||
173 |
// Start with an expected command output |
|
174 |
protected void startCo(String expectedCmdOutput, String... args) { |
|
175 |
startExCoUoCeCn(0, expectedCmdOutput, null, null, null, args); |
|
176 |
} |
|
177 |
||
178 |
// Start with an expected user output |
|
179 |
protected void startUo(String expectedUserOutput, String... args) { |
|
180 |
startExCoUoCeCn(0, null, expectedUserOutput, null, null, args); |
|
181 |
} |
|
182 |
||
33362 | 183 |
@BeforeMethod |
184 |
public void setUp() { |
|
47840 | 185 |
cmdout = new ByteArrayOutputStream(); |
186 |
cmderr = new ByteArrayOutputStream(); |
|
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
187 |
console = new ByteArrayOutputStream(); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
188 |
userout = new ByteArrayOutputStream(); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
189 |
usererr = new ByteArrayOutputStream(); |
47840 | 190 |
setIn("/exit\n"); |
33362 | 191 |
} |
192 |
||
47840 | 193 |
protected String writeToFile(String stuff) { |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
194 |
Compiler compiler = new Compiler(); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
195 |
Path p = compiler.getPath("doit.repl"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
196 |
compiler.writeToFile(p, stuff); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
197 |
return p.toString(); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
198 |
} |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
199 |
|
47840 | 200 |
// Set the input from a String |
201 |
protected void setIn(String s) { |
|
202 |
cmdInStream = new ByteArrayInputStream(s.getBytes()); |
|
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
203 |
} |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42272
diff
changeset
|
204 |
|
47840 | 205 |
// Test load files |
206 |
public void testCommandFile() { |
|
207 |
String fn = writeToFile("String str = \"Hello \"\n" + |
|
208 |
"/list\n" + |
|
209 |
"System.out.println(str + str)\n" + |
|
210 |
"/exit\n"); |
|
211 |
startExCoUoCeCn(0, |
|
212 |
"1 : String str = \"Hello \";\n", |
|
213 |
"Hello Hello", |
|
214 |
null, |
|
215 |
null, |
|
216 |
"--no-startup", fn, "-s"); |
|
217 |
} |
|
218 |
||
219 |
// Test that the usage message is printed |
|
220 |
public void testUsage() { |
|
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
48272
diff
changeset
|
221 |
for (String opt : new String[]{"-?", "-h", "--help"}) { |
47840 | 222 |
startCo(s -> { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38613
diff
changeset
|
223 |
assertTrue(s.split("\n").length >= 7, "Not enough usage lines: " + s); |
47504
58ce36f43f1a
8179856: jshell tool: not suitable for pipeline use
rfield
parents:
47216
diff
changeset
|
224 |
assertTrue(s.startsWith("Usage: jshell <option>..."), "Unexpect usage start: " + s); |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
225 |
assertTrue(s.contains("--show-version"), "Expected help: " + s); |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
226 |
assertFalse(s.contains("Welcome"), "Unexpected start: " + s); |
47840 | 227 |
}, opt); |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
228 |
} |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
229 |
} |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
230 |
|
47840 | 231 |
// Test the --help-extra message |
232 |
public void testHelpExtra() { |
|
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
233 |
for (String opt : new String[]{"-X", "--help-extra"}) { |
47840 | 234 |
startCo(s -> { |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
235 |
assertTrue(s.split("\n").length >= 5, "Not enough help-extra lines: " + s); |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
236 |
assertTrue(s.contains("--add-exports"), "Expected --add-exports: " + s); |
48940 | 237 |
assertTrue(s.contains("--execution"), "Expected --execution: " + s); |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
238 |
assertFalse(s.contains("Welcome"), "Unexpected start: " + s); |
47840 | 239 |
}, opt); |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38613
diff
changeset
|
240 |
} |
33362 | 241 |
} |
242 |
||
47840 | 243 |
// Test handling of bogus options |
244 |
public void testUnknown() { |
|
245 |
startExCe(1, "Unknown option: u", "-unknown"); |
|
246 |
startExCe(1, "Unknown option: unknown", "--unknown"); |
|
33362 | 247 |
} |
248 |
||
47840 | 249 |
// Test that input is read with "-" and there is no extra output. |
250 |
public void testHypenFile() { |
|
251 |
setIn("System.out.print(\"Hello\");\n"); |
|
252 |
startUo("Hello", "-"); |
|
253 |
setIn("System.out.print(\"Hello\");\n"); |
|
254 |
startUo("Hello", "-", "-"); |
|
255 |
String fn = writeToFile("System.out.print(\"===\");"); |
|
256 |
setIn("System.out.print(\"Hello\");\n"); |
|
257 |
startUo("===Hello===", fn, "-", fn); |
|
47504
58ce36f43f1a
8179856: jshell tool: not suitable for pipeline use
rfield
parents:
47216
diff
changeset
|
258 |
// check that errors go to standard error |
47840 | 259 |
setIn(") Foobar"); |
260 |
startExCe(0, s -> assertTrue(s.contains("illegal start of expression"), |
|
261 |
"cmderr: illegal start of expression"), |
|
47504
58ce36f43f1a
8179856: jshell tool: not suitable for pipeline use
rfield
parents:
47216
diff
changeset
|
262 |
"-"); |
58ce36f43f1a
8179856: jshell tool: not suitable for pipeline use
rfield
parents:
47216
diff
changeset
|
263 |
} |
58ce36f43f1a
8179856: jshell tool: not suitable for pipeline use
rfield
parents:
47216
diff
changeset
|
264 |
|
47840 | 265 |
// Test that user specified exit codes are propagated |
266 |
public void testExitCode() { |
|
267 |
setIn("/exit 57\n"); |
|
268 |
startExCoUoCeCn(57, null, null, null, "-> /exit 57", "-s"); |
|
269 |
setIn("int eight = 8\n" + |
|
270 |
"/exit eight + \n" + |
|
271 |
" eight\n"); |
|
272 |
startExCoUoCeCn(16, null, null, null, |
|
273 |
"-> int eight = 8\n" + |
|
274 |
"-> /exit eight + \n" + |
|
275 |
">> eight", |
|
276 |
"-s"); |
|
47504
58ce36f43f1a
8179856: jshell tool: not suitable for pipeline use
rfield
parents:
47216
diff
changeset
|
277 |
} |
58ce36f43f1a
8179856: jshell tool: not suitable for pipeline use
rfield
parents:
47216
diff
changeset
|
278 |
|
47840 | 279 |
// Test that non-existent load file sends output to stderr and does not startExCe (no welcome). |
280 |
public void testUnknownLoadFile() { |
|
281 |
startExCe(1, "File 'UNKNOWN' for 'jshell' is not found.", "UNKNOWN"); |
|
38613 | 282 |
} |
283 |
||
47840 | 284 |
// Test bad usage of the --startup option |
285 |
public void testStartup() { |
|
286 |
String fn = writeToFile(""); |
|
287 |
startExCe(1, "Argument to startup missing.", "--startup"); |
|
288 |
startExCe(1, "Conflicting options: both --startup and --no-startup were used.", "--no-startup", "--startup", fn); |
|
289 |
startExCe(1, "Conflicting options: both --startup and --no-startup were used.", "--startup", fn, "--no-startup"); |
|
290 |
startExCe(1, "Argument to startup missing.", "--no-startup", "--startup"); |
|
291 |
} |
|
292 |
||
293 |
// Test an option that causes the back-end to fail is propagated |
|
294 |
public void testStartupFailedOption() { |
|
295 |
startExCe(1, s -> assertTrue(s.contains("Unrecognized option: -hoge-foo-bar"), "cmderr: " + s), |
|
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43367
diff
changeset
|
296 |
"-R-hoge-foo-bar"); |
42272
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41641
diff
changeset
|
297 |
} |
82e273c4f2b3
8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents:
41641
diff
changeset
|
298 |
|
47840 | 299 |
// Test the use of non-existant files with the --startup option |
300 |
public void testStartupUnknown() { |
|
301 |
startExCe(1, "File 'UNKNOWN' for '--startup' is not found.", "--startup", "UNKNOWN"); |
|
302 |
startExCe(1, "File 'UNKNOWN' for '--startup' is not found.", "--startup", "DEFAULT", "--startup", "UNKNOWN"); |
|
33362 | 303 |
} |
304 |
||
47840 | 305 |
// Test bad usage of --class-path option |
306 |
public void testClasspath() { |
|
307 |
for (String cp : new String[]{"--class-path"}) { |
|
308 |
startExCe(1, "Only one --class-path option may be used.", cp, ".", "--class-path", "."); |
|
309 |
startExCe(1, "Argument to class-path missing.", cp); |
|
33362 | 310 |
} |
311 |
} |
|
312 |
||
47840 | 313 |
// Test bogus module on --add-modules option |
314 |
public void testUnknownModule() { |
|
315 |
startExCe(1, s -> assertTrue(s.contains("rror") && s.contains("unKnown"), "cmderr: " + s), |
|
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43367
diff
changeset
|
316 |
"--add-modules", "unKnown"); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43367
diff
changeset
|
317 |
} |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43367
diff
changeset
|
318 |
|
47840 | 319 |
// Test that muliple feedback options fail |
320 |
public void testFeedbackOptionConflict() { |
|
321 |
startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", |
|
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38613
diff
changeset
|
322 |
"--feedback", "concise", "--feedback", "verbose"); |
47840 | 323 |
startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "--feedback", "concise", "-s"); |
324 |
startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "--feedback", "verbose", "-q"); |
|
325 |
startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "--feedback", "concise", "-v"); |
|
326 |
startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-v", "--feedback", "concise"); |
|
327 |
startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-q", "-v"); |
|
328 |
startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-s", "-v"); |
|
329 |
startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-v", "-q"); |
|
330 |
startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-q", "-s"); |
|
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38613
diff
changeset
|
331 |
} |
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38613
diff
changeset
|
332 |
|
47840 | 333 |
// Test bogus arguments to the --feedback option |
334 |
public void testNegFeedbackOption() { |
|
335 |
startExCe(1, "Argument to feedback missing.", "--feedback"); |
|
336 |
startExCe(1, "Does not match any current feedback mode: blorp -- --feedback blorp", "--feedback", "blorp"); |
|
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
337 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
338 |
|
47840 | 339 |
// Test --version |
340 |
public void testVersion() { |
|
341 |
startCo(s -> { |
|
342 |
assertTrue(s.startsWith("jshell"), "unexpected version: " + s); |
|
343 |
assertFalse(s.contains("Welcome"), "Unexpected start: " + s); |
|
344 |
}, |
|
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
345 |
"--version"); |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
346 |
} |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
347 |
|
47840 | 348 |
// Test --show-version |
349 |
public void testShowVersion() { |
|
350 |
startExCoUoCeCn(null, |
|
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
351 |
s -> { |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
352 |
assertTrue(s.startsWith("jshell"), "unexpected version: " + s); |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
353 |
assertTrue(s.contains("Welcome"), "Expected start (but got no welcome): " + s); |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
354 |
}, |
47840 | 355 |
null, |
356 |
null, |
|
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
357 |
s -> assertTrue(s.trim().startsWith("jshell>"), "Expected prompt, got: " + s), |
47840 | 358 |
"--show-version"); |
33362 | 359 |
} |
360 |
||
361 |
@AfterMethod |
|
362 |
public void tearDown() { |
|
47840 | 363 |
cmdout = null; |
364 |
cmderr = null; |
|
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
365 |
console = null; |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
366 |
userout = null; |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
367 |
usererr = null; |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42972
diff
changeset
|
368 |
cmdInStream = null; |
33362 | 369 |
} |
52938 | 370 |
|
371 |
private static String stripAnsi(String str) { |
|
372 |
if (str == null) return ""; |
|
373 |
return ANSI_CODE_PATTERN.matcher(str).replaceAll(""); |
|
374 |
} |
|
375 |
||
376 |
public static final Pattern ANSI_CODE_PATTERN = Pattern.compile("\033\\[[\060-\077]*[\040-\057]*[\100-\176]"); |
|
33362 | 377 |
} |