author | coleenp |
Fri, 31 Aug 2018 07:03:46 -0400 | |
changeset 51608 | 625a5bdde0c5 |
parent 48347 | 4f9683bf0923 |
child 53058 | 83840e83476a |
permissions | -rw-r--r-- |
46185
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
1 |
/* |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
4 |
* |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
8 |
* |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
13 |
* accompanied this code). |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
14 |
* |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
18 |
* |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
21 |
* questions. |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
22 |
*/ |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
23 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
24 |
/** |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
25 |
* @test |
48347
4f9683bf0923
8188894: jdk/jshell/ToolShiftTabTest.java failed with IllegalStateException
rfield
parents:
48275
diff
changeset
|
26 |
* @bug 8166334 8188894 |
46185
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
27 |
* @summary test shift-tab shortcuts "fixes" |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
28 |
* @modules |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
29 |
* jdk.jshell/jdk.internal.jshell.tool.resources:open |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
30 |
* jdk.jshell/jdk.jshell:open |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
31 |
* @build UITesting |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
32 |
* @build ToolShiftTabTest |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
33 |
* @run testng/timeout=300 ToolShiftTabTest |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
34 |
*/ |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
35 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
36 |
import java.util.regex.Pattern; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
37 |
import org.testng.annotations.Test; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
38 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
39 |
@Test |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
40 |
public class ToolShiftTabTest extends UITesting { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
41 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
42 |
// Shift-tab as escape sequence |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
43 |
private String FIX = "\033\133\132"; |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
44 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
45 |
public void testFixVariable() throws Exception { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
46 |
doRunTest((inputSink, out) -> { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
47 |
inputSink.write("3+4"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
48 |
inputSink.write(FIX + "v"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
49 |
inputSink.write("jj\n"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
50 |
waitOutput(out, "jj ==> 7"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
51 |
inputSink.write("jj\n"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
52 |
waitOutput(out, "jj ==> 7"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
53 |
}); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
54 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
55 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
56 |
public void testFixMethod() throws Exception { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
57 |
doRunTest((inputSink, out) -> { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
58 |
inputSink.write("5.5 >= 3.1415926535"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
59 |
inputSink.write(FIX + "m"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
60 |
waitOutput(out, "boolean "); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
61 |
inputSink.write("mm\n"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
62 |
waitOutput(out, "| created method mm()"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
63 |
inputSink.write("mm()\n"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
64 |
waitOutput(out, "==> true"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
65 |
inputSink.write("/method\n"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
66 |
waitOutput(out, "boolean mm()"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
67 |
}); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
68 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
69 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
70 |
public void testFixMethodVoid() throws Exception { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
71 |
doRunTest((inputSink, out) -> { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
72 |
inputSink.write("System.out.println(\"Testing\")"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
73 |
inputSink.write(FIX + "m"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
74 |
inputSink.write("p\n"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
75 |
waitOutput(out, "| created method p()"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
76 |
inputSink.write("p()\n"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
77 |
waitOutput(out, "Testing"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
78 |
inputSink.write("/method\n"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
79 |
waitOutput(out, "void p()"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
80 |
}); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
81 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
82 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
83 |
public void testFixMethodNoLeaks() throws Exception { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
84 |
doRunTest((inputSink, out) -> { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
85 |
inputSink.write("4"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
86 |
inputSink.write(FIX + "m"); |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47216
diff
changeset
|
87 |
inputSink.write(INTERRUPT + " 55"); |
46185
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
88 |
inputSink.write(FIX + "m"); |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47216
diff
changeset
|
89 |
inputSink.write(INTERRUPT + " 55"); |
46185
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
90 |
inputSink.write(FIX + "m"); |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47216
diff
changeset
|
91 |
inputSink.write(INTERRUPT + " 55"); |
46185
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
92 |
inputSink.write(FIX + "m"); |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47216
diff
changeset
|
93 |
inputSink.write(INTERRUPT + " 55"); |
46185
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
94 |
inputSink.write(FIX + "m"); |
48275
b2190c70a1ac
8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents:
47216
diff
changeset
|
95 |
inputSink.write(INTERRUPT + "'X'"); |
46185
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
96 |
inputSink.write(FIX + "m"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
97 |
inputSink.write("nl\n"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
98 |
waitOutput(out, "| created method nl()"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
99 |
inputSink.write("/list\n"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
100 |
waitOutput(out, Pattern.quote("1 : char nl() { return 'X'; }")); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
101 |
inputSink.write("true\n"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
102 |
waitOutput(out, Pattern.quote("$2 ==> true")); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
103 |
inputSink.write("/list\n"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
104 |
waitOutput(out, "2 : true"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
105 |
}); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
106 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
107 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
108 |
public void testFixImport() throws Exception { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
109 |
doRunTest((inputSink, out) -> { |
48347
4f9683bf0923
8188894: jdk/jshell/ToolShiftTabTest.java failed with IllegalStateException
rfield
parents:
48275
diff
changeset
|
110 |
do { |
4f9683bf0923
8188894: jdk/jshell/ToolShiftTabTest.java failed with IllegalStateException
rfield
parents:
48275
diff
changeset
|
111 |
inputSink.write("Frame"); |
4f9683bf0923
8188894: jdk/jshell/ToolShiftTabTest.java failed with IllegalStateException
rfield
parents:
48275
diff
changeset
|
112 |
inputSink.write(FIX + "i"); |
4f9683bf0923
8188894: jdk/jshell/ToolShiftTabTest.java failed with IllegalStateException
rfield
parents:
48275
diff
changeset
|
113 |
inputSink.write("1"); |
4f9683bf0923
8188894: jdk/jshell/ToolShiftTabTest.java failed with IllegalStateException
rfield
parents:
48275
diff
changeset
|
114 |
inputSink.write(".WIDTH\n"); |
4f9683bf0923
8188894: jdk/jshell/ToolShiftTabTest.java failed with IllegalStateException
rfield
parents:
48275
diff
changeset
|
115 |
} while (!waitOutput(out, "==> 1", "Results may be incomplete")); |
46185
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
116 |
inputSink.write("/import\n"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
117 |
waitOutput(out, "| import java.awt.Frame"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
118 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
119 |
inputSink.write("Object"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
120 |
inputSink.write(FIX + "i"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
121 |
waitOutput(out, "The identifier is resolvable in this context"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
122 |
}); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
123 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
124 |
|
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
125 |
public void testFixBad() throws Exception { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
126 |
doRunTest((inputSink, out) -> { |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
127 |
inputSink.write("123"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
128 |
inputSink.write(FIX + "z"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
129 |
waitOutput(out, "Unexpected character after Shift-Tab"); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
130 |
}); |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
131 |
} |
f4c981fc7818
8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents:
diff
changeset
|
132 |
} |