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