author | rfield |
Mon, 03 Jun 2019 08:21:04 -0700 | |
changeset 55156 | 1c291d1c272c |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
36499 | 2 |
* Copyright (c) 2015, 2016, 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 |
||
24 |
/* |
|
25 |
* @test |
|
55156 | 26 |
* @bug 8081431 8080069 8167128 8199623 |
33362 | 27 |
* @summary Test of JShell#drop(). |
28 |
* @build KullaTesting TestingInputStream |
|
29 |
* @run testng DropTest |
|
30 |
*/ |
|
31 |
||
32 |
import jdk.jshell.DeclarationSnippet; |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
33 |
import jdk.jshell.Snippet; |
55156 | 34 |
import jdk.jshell.MethodSnippet; |
36499 | 35 |
import jdk.jshell.VarSnippet; |
33362 | 36 |
import org.testng.annotations.Test; |
37 |
||
38 |
import static jdk.jshell.Snippet.Status.*; |
|
39 |
||
40 |
@Test |
|
41 |
public class DropTest extends KullaTesting { |
|
42 |
||
43 |
public void testDrop() { |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
44 |
Snippet var = varKey(assertEval("int x;")); |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
45 |
Snippet method = methodKey(assertEval("int mu() { return x * 4; }")); |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
46 |
Snippet clazz = classKey(assertEval("class C { String v() { return \"#\" + mu(); } }")); |
33362 | 47 |
assertDrop(var, |
48 |
ste(var, VALID, DROPPED, true, null), |
|
49 |
ste(method, VALID, RECOVERABLE_DEFINED, false, var)); |
|
36499 | 50 |
assertDrop(method, |
51 |
ste(method, RECOVERABLE_DEFINED, DROPPED, true, null), |
|
52 |
ste(clazz, VALID, RECOVERABLE_DEFINED, false, method)); |
|
53 |
VarSnippet cc = varKey(assertEval("C c;")); |
|
54 |
assertEvalUnresolvedException("new C();", "C", 1, 0); |
|
33362 | 55 |
assertVariables(); |
56 |
assertMethods(); |
|
57 |
assertClasses(); |
|
58 |
assertActiveKeys(); |
|
59 |
||
36499 | 60 |
method = methodKey(assertEval("int mu() { return x * 4; }", |
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
36499
diff
changeset
|
61 |
added(RECOVERABLE_DEFINED), |
36499 | 62 |
ste(clazz, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET))); |
33362 | 63 |
assertEval("int x = 10;", "10", |
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
36499
diff
changeset
|
64 |
added(VALID), |
33362 | 65 |
ste(method, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)); |
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
66 |
Snippet c0 = varKey(assertEval("C c0 = new C();")); |
33362 | 67 |
assertEval("c0.v();", "\"#40\""); |
36499 | 68 |
assertEval("C c = new C();", |
69 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
|
70 |
ste(cc, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
33362 | 71 |
assertEval("c.v();", "\"#40\""); |
72 |
assertEval("int mu() { return x * 3; }", |
|
73 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
|
74 |
ste(method, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
75 |
assertEval("c.v();", "\"#30\""); |
|
76 |
assertEval("class C { String v() { return \"@\" + mu(); } }", |
|
77 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
|
78 |
ste(clazz, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
79 |
assertEval("c0.v();", "\"@30\""); |
|
80 |
assertDrop(c0, |
|
81 |
ste(c0, VALID, DROPPED, true, null)); |
|
82 |
assertEval("c = new C();"); |
|
83 |
assertEval("c.v();", "\"@30\""); |
|
84 |
||
85 |
assertVariables(); |
|
86 |
assertMethods(); |
|
87 |
assertClasses(); |
|
88 |
assertActiveKeys(); |
|
89 |
} |
|
90 |
||
91 |
public void testDropImport() { |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
92 |
Snippet imp = importKey(assertEval("import java.util.*;")); |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
93 |
Snippet decl = varKey( |
33362 | 94 |
assertEval("List<Integer> list = Arrays.asList(1, 2, 3);", "[1, 2, 3]")); |
95 |
assertEval("list;", "[1, 2, 3]"); |
|
96 |
assertDrop(imp, |
|
97 |
DiagCheck.DIAG_OK, |
|
98 |
DiagCheck.DIAG_ERROR, |
|
99 |
ste(imp, VALID, DROPPED, true, null), |
|
100 |
ste(decl, VALID, RECOVERABLE_NOT_DEFINED, true, imp)); |
|
101 |
assertDeclareFail("list;", "compiler.err.cant.resolve.location"); |
|
102 |
} |
|
103 |
||
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
104 |
public void testDropStatement() { |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
105 |
Snippet x = key(assertEval("if (true);")); |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
106 |
assertDrop(x, ste(x, VALID, DROPPED, true, null)); |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
107 |
} |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
108 |
|
33362 | 109 |
public void testDropVarToMethod() { |
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
110 |
Snippet x = varKey(assertEval("int x;")); |
33362 | 111 |
DeclarationSnippet method = methodKey(assertEval("double mu() { return x * 4; }")); |
112 |
assertEval("x == 0;", "true"); |
|
113 |
assertEval("mu() == 0.0;", "true"); |
|
114 |
||
115 |
assertDrop(x, |
|
116 |
ste(x, VALID, DROPPED, true, null), |
|
117 |
ste(method, VALID, RECOVERABLE_DEFINED, false, x)); |
|
118 |
assertUnresolvedDependencies1(method, RECOVERABLE_DEFINED, "variable x"); |
|
119 |
assertEvalUnresolvedException("mu();", "mu", 1, 0); |
|
120 |
||
121 |
assertVariables(); |
|
122 |
assertMethods(); |
|
123 |
assertActiveKeys(); |
|
124 |
} |
|
125 |
||
126 |
public void testDropMethodToMethod() { |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
127 |
Snippet a = methodKey(assertEval("double a() { return 2; }")); |
33362 | 128 |
DeclarationSnippet b = methodKey(assertEval("double b() { return a() * 10; }")); |
129 |
assertEval("double c() { return b() * 3; }"); |
|
130 |
DeclarationSnippet d = methodKey(assertEval("double d() { return c() + 1000; }")); |
|
131 |
assertEval("d();", "1060.0"); |
|
132 |
assertDrop(a, |
|
133 |
ste(a, VALID, DROPPED, true, null), |
|
134 |
ste(b, VALID, RECOVERABLE_DEFINED, false, a)); |
|
135 |
assertUnresolvedDependencies1(b, RECOVERABLE_DEFINED, "method a()"); |
|
136 |
assertUnresolvedDependencies(d, 0); |
|
137 |
assertEvalUnresolvedException("d();", "b", 1, 0); |
|
138 |
assertMethods(); |
|
139 |
assertActiveKeys(); |
|
140 |
} |
|
141 |
||
142 |
public void testDropClassToMethod() { |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
143 |
Snippet c = classKey(assertEval("class C { int f() { return 7; } }")); |
33362 | 144 |
DeclarationSnippet m = methodKey(assertEval("int m() { return new C().f(); }")); |
145 |
assertDrop(c, |
|
146 |
ste(c, VALID, DROPPED, true, null), |
|
147 |
ste(m, VALID, RECOVERABLE_DEFINED, false, c)); |
|
148 |
assertUnresolvedDependencies1(m, RECOVERABLE_DEFINED, "class C"); |
|
149 |
assertEvalUnresolvedException("m();", "m", 1, 0); |
|
150 |
assertActiveKeys(); |
|
151 |
} |
|
152 |
||
153 |
public void testDropVarToClass() { |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
154 |
Snippet x = varKey(assertEval("int x;")); |
33362 | 155 |
DeclarationSnippet a = classKey(assertEval("class A { double a = 4 * x; }")); |
156 |
assertDrop(x, |
|
157 |
DiagCheck.DIAG_OK, |
|
158 |
DiagCheck.DIAG_ERROR, |
|
159 |
ste(x, VALID, DROPPED, true, null), |
|
36499 | 160 |
ste(a, VALID, RECOVERABLE_DEFINED, false, x)); |
161 |
assertEval("A foo() { return null; }"); |
|
162 |
assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable x"); |
|
163 |
assertEvalUnresolvedException("new A();", "A", 1, 0); |
|
33362 | 164 |
assertVariables(); |
165 |
assertActiveKeys(); |
|
166 |
} |
|
167 |
||
168 |
public void testDropMethodToClass() { |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
169 |
Snippet x = methodKey(assertEval("int x() { return 0; }")); |
33362 | 170 |
DeclarationSnippet a = classKey(assertEval("class A { double a = 4 * x(); }")); |
171 |
assertDrop(x, |
|
172 |
DiagCheck.DIAG_OK, |
|
173 |
DiagCheck.DIAG_ERROR, |
|
174 |
ste(x, VALID, DROPPED, true, null), |
|
36499 | 175 |
ste(a, VALID, RECOVERABLE_DEFINED, false, x)); |
176 |
assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "method x()"); |
|
177 |
assertEvalUnresolvedException("new A();", "A", 1, 0); |
|
33362 | 178 |
assertMethods(); |
179 |
assertActiveKeys(); |
|
180 |
} |
|
181 |
||
182 |
public void testDropClassToClass() { |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
183 |
Snippet a = classKey(assertEval("class A {}")); |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
184 |
Snippet b = classKey(assertEval("class B extends A {}")); |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
185 |
Snippet c = classKey(assertEval("class C extends B {}")); |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
186 |
Snippet d = classKey(assertEval("class D extends C {}")); |
33362 | 187 |
assertDrop(a, |
188 |
DiagCheck.DIAG_OK, |
|
189 |
DiagCheck.DIAG_ERROR, |
|
190 |
ste(a, VALID, DROPPED, true, null), |
|
191 |
ste(b, VALID, RECOVERABLE_NOT_DEFINED, true, a), |
|
192 |
ste(c, VALID, RECOVERABLE_NOT_DEFINED, true, b), |
|
193 |
ste(d, VALID, RECOVERABLE_NOT_DEFINED, true, c)); |
|
194 |
assertUnresolvedDependencies1((DeclarationSnippet) b, RECOVERABLE_NOT_DEFINED, "class A"); |
|
195 |
assertDrop(c, |
|
196 |
DiagCheck.DIAG_OK, |
|
197 |
DiagCheck.DIAG_ERROR, |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
36499
diff
changeset
|
198 |
ste(c, RECOVERABLE_NOT_DEFINED, DROPPED, false, null)); |
33362 | 199 |
assertEval("interface A {}", null, null, |
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
36499
diff
changeset
|
200 |
DiagCheck.DIAG_OK, |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
36499
diff
changeset
|
201 |
DiagCheck.DIAG_ERROR, |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
36499
diff
changeset
|
202 |
added(VALID)); |
33362 | 203 |
assertClasses(); |
204 |
assertActiveKeys(); |
|
205 |
} |
|
206 |
||
207 |
public void testDropNoUpdate() { |
|
208 |
String as1 = "class A {}"; |
|
209 |
String as2 = "class A extends java.util.ArrayList<Boolean> {}"; |
|
41514
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
210 |
Snippet a = classKey(assertEval(as1, added(VALID))); |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
211 |
Snippet b = classKey(assertEval("class B extends A {}", added(VALID))); |
a75c2b869d8d
8167128: JShell: /drop of statement gives confusing output
rfield
parents:
37644
diff
changeset
|
212 |
Snippet ax = classKey(assertEval(as2, |
33362 | 213 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
214 |
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET), |
|
215 |
ste(b, VALID, VALID, true, MAIN_SNIPPET))); |
|
216 |
ax = classKey(assertEval(as1, |
|
217 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
218 |
ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET), |
|
219 |
ste(b, VALID, VALID, true, MAIN_SNIPPET))); |
|
220 |
assertDrop(b, |
|
221 |
ste(b, VALID, DROPPED, true, null)); |
|
222 |
ax = classKey(assertEval(as2, |
|
223 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
224 |
ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET))); |
|
225 |
assertEval(as1, |
|
226 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
227 |
ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
228 |
} |
|
55156 | 229 |
|
230 |
// 8199623 |
|
231 |
public void testTwoForkedDrop() { |
|
232 |
MethodSnippet p = methodKey(assertEval("void p() throws Exception { ((String) null).toString(); }")); |
|
233 |
MethodSnippet n = methodKey(assertEval("void n() throws Exception { try { p(); } catch (Exception ex) { throw new RuntimeException(\"bar\", ex); }}")); |
|
234 |
MethodSnippet m = methodKey(assertEval("void m() { try { n(); } catch (Exception ex) { throw new RuntimeException(\"foo\", ex); }}")); |
|
235 |
MethodSnippet c = methodKey(assertEval("void c() throws Throwable { p(); }")); |
|
236 |
assertDrop(p, |
|
237 |
ste(p, VALID, DROPPED, true, null), |
|
238 |
ste(n, VALID, RECOVERABLE_DEFINED, false, p), |
|
239 |
ste(c, VALID, RECOVERABLE_DEFINED, false, p)); |
|
240 |
assertActiveKeys(); |
|
241 |
} |
|
33362 | 242 |
} |