author | rfield |
Tue, 02 Feb 2016 16:11:09 -0800 | |
changeset 35736 | bae6ea327651 |
parent 33362 | 65ec6de1d6b4 |
child 36499 | 9d823cc0fe98 |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
2 |
* Copyright (c) 2015, 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 |
|
35736
bae6ea327651
8080357: JShell: Only unqualified unresolved references should be corralled
rfield
parents:
33362
diff
changeset
|
26 |
* @bug 8081431 |
33362 | 27 |
* @summary Test of JShell#drop(). |
28 |
* @build KullaTesting TestingInputStream |
|
29 |
* @run testng DropTest |
|
30 |
*/ |
|
31 |
||
32 |
import jdk.jshell.DeclarationSnippet; |
|
33 |
import jdk.jshell.PersistentSnippet; |
|
34 |
import org.testng.annotations.Test; |
|
35 |
||
36 |
import static jdk.jshell.Snippet.Status.*; |
|
37 |
||
38 |
@Test |
|
39 |
public class DropTest extends KullaTesting { |
|
40 |
||
41 |
public void testDrop() { |
|
42 |
PersistentSnippet var = varKey(assertEval("int x;")); |
|
43 |
PersistentSnippet method = methodKey(assertEval("int mu() { return x * 4; }")); |
|
44 |
PersistentSnippet clazz = classKey(assertEval("class C { String v() { return \"#\" + mu(); } }")); |
|
45 |
assertDrop(var, |
|
46 |
ste(var, VALID, DROPPED, true, null), |
|
47 |
ste(method, VALID, RECOVERABLE_DEFINED, false, var)); |
|
48 |
//assertDrop(method, |
|
49 |
// ste(method, RECOVERABLE_DEFINED, DROPPED, false, null), |
|
50 |
// ste(clazz, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, method)); |
|
51 |
//assertDeclareFail("new C();", "compiler.err.cant.resolve.location"); |
|
52 |
assertVariables(); |
|
53 |
assertMethods(); |
|
54 |
assertClasses(); |
|
55 |
assertActiveKeys(); |
|
56 |
||
57 |
assertEval("int x = 10;", "10", |
|
58 |
ste(var, DROPPED, VALID, true, null), |
|
59 |
ste(method, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)); |
|
60 |
PersistentSnippet c0 = varKey(assertEval("C c0 = new C();")); |
|
61 |
assertEval("c0.v();", "\"#40\""); |
|
62 |
assertEval("C c = new C();"); |
|
63 |
assertEval("c.v();", "\"#40\""); |
|
64 |
assertEval("int mu() { return x * 3; }", |
|
65 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
|
66 |
ste(method, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
67 |
assertEval("c.v();", "\"#30\""); |
|
68 |
assertEval("class C { String v() { return \"@\" + mu(); } }", |
|
69 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
|
70 |
ste(clazz, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
71 |
assertEval("c0.v();", "\"@30\""); |
|
72 |
assertDrop(c0, |
|
73 |
ste(c0, VALID, DROPPED, true, null)); |
|
74 |
assertEval("c = new C();"); |
|
75 |
assertEval("c.v();", "\"@30\""); |
|
76 |
||
77 |
assertVariables(); |
|
78 |
assertMethods(); |
|
79 |
assertClasses(); |
|
80 |
assertActiveKeys(); |
|
81 |
} |
|
82 |
||
83 |
public void testDropImport() { |
|
84 |
PersistentSnippet imp = importKey(assertEval("import java.util.*;")); |
|
85 |
PersistentSnippet decl = varKey( |
|
86 |
assertEval("List<Integer> list = Arrays.asList(1, 2, 3);", "[1, 2, 3]")); |
|
87 |
assertEval("list;", "[1, 2, 3]"); |
|
88 |
assertDrop(imp, |
|
89 |
DiagCheck.DIAG_OK, |
|
90 |
DiagCheck.DIAG_ERROR, |
|
91 |
ste(imp, VALID, DROPPED, true, null), |
|
92 |
ste(decl, VALID, RECOVERABLE_NOT_DEFINED, true, imp)); |
|
93 |
assertDeclareFail("list;", "compiler.err.cant.resolve.location"); |
|
94 |
} |
|
95 |
||
96 |
public void testDropVarToMethod() { |
|
97 |
PersistentSnippet x = varKey(assertEval("int x;")); |
|
98 |
DeclarationSnippet method = methodKey(assertEval("double mu() { return x * 4; }")); |
|
99 |
assertEval("x == 0;", "true"); |
|
100 |
assertEval("mu() == 0.0;", "true"); |
|
101 |
||
102 |
assertDrop(x, |
|
103 |
ste(x, VALID, DROPPED, true, null), |
|
104 |
ste(method, VALID, RECOVERABLE_DEFINED, false, x)); |
|
105 |
assertUnresolvedDependencies1(method, RECOVERABLE_DEFINED, "variable x"); |
|
106 |
assertEvalUnresolvedException("mu();", "mu", 1, 0); |
|
107 |
||
108 |
assertVariables(); |
|
109 |
assertMethods(); |
|
110 |
assertActiveKeys(); |
|
111 |
} |
|
112 |
||
113 |
public void testDropMethodToMethod() { |
|
114 |
PersistentSnippet a = methodKey(assertEval("double a() { return 2; }")); |
|
115 |
DeclarationSnippet b = methodKey(assertEval("double b() { return a() * 10; }")); |
|
116 |
assertEval("double c() { return b() * 3; }"); |
|
117 |
DeclarationSnippet d = methodKey(assertEval("double d() { return c() + 1000; }")); |
|
118 |
assertEval("d();", "1060.0"); |
|
119 |
assertDrop(a, |
|
120 |
ste(a, VALID, DROPPED, true, null), |
|
121 |
ste(b, VALID, RECOVERABLE_DEFINED, false, a)); |
|
122 |
assertUnresolvedDependencies1(b, RECOVERABLE_DEFINED, "method a()"); |
|
123 |
assertUnresolvedDependencies(d, 0); |
|
124 |
assertEvalUnresolvedException("d();", "b", 1, 0); |
|
125 |
assertMethods(); |
|
126 |
assertActiveKeys(); |
|
127 |
} |
|
128 |
||
129 |
public void testDropClassToMethod() { |
|
130 |
PersistentSnippet c = classKey(assertEval("class C { int f() { return 7; } }")); |
|
131 |
DeclarationSnippet m = methodKey(assertEval("int m() { return new C().f(); }")); |
|
132 |
assertDrop(c, |
|
133 |
ste(c, VALID, DROPPED, true, null), |
|
134 |
ste(m, VALID, RECOVERABLE_DEFINED, false, c)); |
|
135 |
assertUnresolvedDependencies1(m, RECOVERABLE_DEFINED, "class C"); |
|
136 |
assertEvalUnresolvedException("m();", "m", 1, 0); |
|
137 |
assertActiveKeys(); |
|
138 |
} |
|
139 |
||
140 |
public void testDropVarToClass() { |
|
141 |
PersistentSnippet x = varKey(assertEval("int x;")); |
|
142 |
DeclarationSnippet a = classKey(assertEval("class A { double a = 4 * x; }")); |
|
143 |
assertDrop(x, |
|
144 |
DiagCheck.DIAG_OK, |
|
145 |
DiagCheck.DIAG_ERROR, |
|
146 |
ste(x, VALID, DROPPED, true, null), |
|
147 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, x)); |
|
148 |
assertUnresolvedDependencies1(a, RECOVERABLE_NOT_DEFINED, "variable x"); |
|
149 |
assertDeclareFail("new A().a;", "compiler.err.cant.resolve.location"); |
|
150 |
assertVariables(); |
|
151 |
assertActiveKeys(); |
|
152 |
} |
|
153 |
||
154 |
public void testDropMethodToClass() { |
|
155 |
PersistentSnippet x = methodKey(assertEval("int x() { return 0; }")); |
|
156 |
DeclarationSnippet a = classKey(assertEval("class A { double a = 4 * x(); }")); |
|
157 |
assertDrop(x, |
|
158 |
DiagCheck.DIAG_OK, |
|
159 |
DiagCheck.DIAG_ERROR, |
|
160 |
ste(x, VALID, DROPPED, true, null), |
|
161 |
ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, x)); |
|
162 |
assertUnresolvedDependencies1(a, RECOVERABLE_NOT_DEFINED, "method x()"); |
|
163 |
assertDeclareFail("new A().a;", "compiler.err.cant.resolve.location"); |
|
164 |
assertMethods(); |
|
165 |
assertActiveKeys(); |
|
166 |
} |
|
167 |
||
168 |
public void testDropClassToClass() { |
|
169 |
PersistentSnippet a = classKey(assertEval("class A {}")); |
|
170 |
PersistentSnippet b = classKey(assertEval("class B extends A {}")); |
|
171 |
PersistentSnippet c = classKey(assertEval("class C extends B {}")); |
|
172 |
PersistentSnippet d = classKey(assertEval("class D extends C {}")); |
|
173 |
assertDrop(a, |
|
174 |
DiagCheck.DIAG_OK, |
|
175 |
DiagCheck.DIAG_ERROR, |
|
176 |
ste(a, VALID, DROPPED, true, null), |
|
177 |
ste(b, VALID, RECOVERABLE_NOT_DEFINED, true, a), |
|
178 |
ste(c, VALID, RECOVERABLE_NOT_DEFINED, true, b), |
|
179 |
ste(d, VALID, RECOVERABLE_NOT_DEFINED, true, c)); |
|
180 |
assertUnresolvedDependencies1((DeclarationSnippet) b, RECOVERABLE_NOT_DEFINED, "class A"); |
|
181 |
assertDrop(c, |
|
182 |
DiagCheck.DIAG_OK, |
|
183 |
DiagCheck.DIAG_ERROR, |
|
184 |
ste(c, RECOVERABLE_NOT_DEFINED, DROPPED, false, null), |
|
185 |
ste(d, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, c)); |
|
186 |
assertEval("interface A {}", null, null, |
|
187 |
DiagCheck.DIAG_OK, DiagCheck.DIAG_ERROR, |
|
188 |
ste(a, DROPPED, VALID, true, null), |
|
189 |
ste(b, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, MAIN_SNIPPET)); |
|
190 |
assertClasses(); |
|
191 |
assertActiveKeys(); |
|
192 |
} |
|
193 |
||
194 |
public void testDropNoUpdate() { |
|
195 |
String as1 = "class A {}"; |
|
196 |
String as2 = "class A extends java.util.ArrayList<Boolean> {}"; |
|
197 |
PersistentSnippet a = classKey(assertEval(as1, added(VALID))); |
|
198 |
PersistentSnippet b = classKey(assertEval("class B extends A {}", added(VALID))); |
|
199 |
PersistentSnippet ax = classKey(assertEval(as2, |
|
200 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
201 |
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET), |
|
202 |
ste(b, VALID, VALID, true, MAIN_SNIPPET))); |
|
203 |
ax = classKey(assertEval(as1, |
|
204 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
205 |
ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET), |
|
206 |
ste(b, VALID, VALID, true, MAIN_SNIPPET))); |
|
207 |
assertDrop(b, |
|
208 |
ste(b, VALID, DROPPED, true, null)); |
|
209 |
ax = classKey(assertEval(as2, |
|
210 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
211 |
ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET))); |
|
212 |
assertEval(as1, |
|
213 |
ste(MAIN_SNIPPET, VALID, VALID, true, null), |
|
214 |
ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
|
215 |
} |
|
216 |
} |