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
|
36499
|
26 |
* @bug 8081431 8080069
|
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;
|
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() {
|
|
43 |
PersistentSnippet var = varKey(assertEval("int x;"));
|
|
44 |
PersistentSnippet method = methodKey(assertEval("int mu() { return x * 4; }"));
|
|
45 |
PersistentSnippet clazz = classKey(assertEval("class C { String v() { return \"#\" + mu(); } }"));
|
|
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; }",
|
|
60 |
ste(MAIN_SNIPPET, DROPPED, RECOVERABLE_DEFINED, true, null),
|
|
61 |
ste(clazz, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)));
|
33362
|
62 |
assertEval("int x = 10;", "10",
|
36499
|
63 |
ste(MAIN_SNIPPET, DROPPED, VALID, true, null),
|
33362
|
64 |
ste(method, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET));
|
|
65 |
PersistentSnippet c0 = varKey(assertEval("C c0 = new C();"));
|
|
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() {
|
|
91 |
PersistentSnippet imp = importKey(assertEval("import java.util.*;"));
|
|
92 |
PersistentSnippet decl = varKey(
|
|
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 |
|
|
103 |
public void testDropVarToMethod() {
|
|
104 |
PersistentSnippet x = varKey(assertEval("int x;"));
|
|
105 |
DeclarationSnippet method = methodKey(assertEval("double mu() { return x * 4; }"));
|
|
106 |
assertEval("x == 0;", "true");
|
|
107 |
assertEval("mu() == 0.0;", "true");
|
|
108 |
|
|
109 |
assertDrop(x,
|
|
110 |
ste(x, VALID, DROPPED, true, null),
|
|
111 |
ste(method, VALID, RECOVERABLE_DEFINED, false, x));
|
|
112 |
assertUnresolvedDependencies1(method, RECOVERABLE_DEFINED, "variable x");
|
|
113 |
assertEvalUnresolvedException("mu();", "mu", 1, 0);
|
|
114 |
|
|
115 |
assertVariables();
|
|
116 |
assertMethods();
|
|
117 |
assertActiveKeys();
|
|
118 |
}
|
|
119 |
|
|
120 |
public void testDropMethodToMethod() {
|
|
121 |
PersistentSnippet a = methodKey(assertEval("double a() { return 2; }"));
|
|
122 |
DeclarationSnippet b = methodKey(assertEval("double b() { return a() * 10; }"));
|
|
123 |
assertEval("double c() { return b() * 3; }");
|
|
124 |
DeclarationSnippet d = methodKey(assertEval("double d() { return c() + 1000; }"));
|
|
125 |
assertEval("d();", "1060.0");
|
|
126 |
assertDrop(a,
|
|
127 |
ste(a, VALID, DROPPED, true, null),
|
|
128 |
ste(b, VALID, RECOVERABLE_DEFINED, false, a));
|
|
129 |
assertUnresolvedDependencies1(b, RECOVERABLE_DEFINED, "method a()");
|
|
130 |
assertUnresolvedDependencies(d, 0);
|
|
131 |
assertEvalUnresolvedException("d();", "b", 1, 0);
|
|
132 |
assertMethods();
|
|
133 |
assertActiveKeys();
|
|
134 |
}
|
|
135 |
|
|
136 |
public void testDropClassToMethod() {
|
|
137 |
PersistentSnippet c = classKey(assertEval("class C { int f() { return 7; } }"));
|
|
138 |
DeclarationSnippet m = methodKey(assertEval("int m() { return new C().f(); }"));
|
|
139 |
assertDrop(c,
|
|
140 |
ste(c, VALID, DROPPED, true, null),
|
|
141 |
ste(m, VALID, RECOVERABLE_DEFINED, false, c));
|
|
142 |
assertUnresolvedDependencies1(m, RECOVERABLE_DEFINED, "class C");
|
|
143 |
assertEvalUnresolvedException("m();", "m", 1, 0);
|
|
144 |
assertActiveKeys();
|
|
145 |
}
|
|
146 |
|
|
147 |
public void testDropVarToClass() {
|
|
148 |
PersistentSnippet x = varKey(assertEval("int x;"));
|
|
149 |
DeclarationSnippet a = classKey(assertEval("class A { double a = 4 * x; }"));
|
|
150 |
assertDrop(x,
|
|
151 |
DiagCheck.DIAG_OK,
|
|
152 |
DiagCheck.DIAG_ERROR,
|
|
153 |
ste(x, VALID, DROPPED, true, null),
|
36499
|
154 |
ste(a, VALID, RECOVERABLE_DEFINED, false, x));
|
|
155 |
assertEval("A foo() { return null; }");
|
|
156 |
assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable x");
|
|
157 |
assertEvalUnresolvedException("new A();", "A", 1, 0);
|
33362
|
158 |
assertVariables();
|
|
159 |
assertActiveKeys();
|
|
160 |
}
|
|
161 |
|
|
162 |
public void testDropMethodToClass() {
|
|
163 |
PersistentSnippet x = methodKey(assertEval("int x() { return 0; }"));
|
|
164 |
DeclarationSnippet a = classKey(assertEval("class A { double a = 4 * x(); }"));
|
|
165 |
assertDrop(x,
|
|
166 |
DiagCheck.DIAG_OK,
|
|
167 |
DiagCheck.DIAG_ERROR,
|
|
168 |
ste(x, VALID, DROPPED, true, null),
|
36499
|
169 |
ste(a, VALID, RECOVERABLE_DEFINED, false, x));
|
|
170 |
assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "method x()");
|
|
171 |
assertEvalUnresolvedException("new A();", "A", 1, 0);
|
33362
|
172 |
assertMethods();
|
|
173 |
assertActiveKeys();
|
|
174 |
}
|
|
175 |
|
|
176 |
public void testDropClassToClass() {
|
|
177 |
PersistentSnippet a = classKey(assertEval("class A {}"));
|
|
178 |
PersistentSnippet b = classKey(assertEval("class B extends A {}"));
|
|
179 |
PersistentSnippet c = classKey(assertEval("class C extends B {}"));
|
|
180 |
PersistentSnippet d = classKey(assertEval("class D extends C {}"));
|
|
181 |
assertDrop(a,
|
|
182 |
DiagCheck.DIAG_OK,
|
|
183 |
DiagCheck.DIAG_ERROR,
|
|
184 |
ste(a, VALID, DROPPED, true, null),
|
|
185 |
ste(b, VALID, RECOVERABLE_NOT_DEFINED, true, a),
|
|
186 |
ste(c, VALID, RECOVERABLE_NOT_DEFINED, true, b),
|
|
187 |
ste(d, VALID, RECOVERABLE_NOT_DEFINED, true, c));
|
|
188 |
assertUnresolvedDependencies1((DeclarationSnippet) b, RECOVERABLE_NOT_DEFINED, "class A");
|
|
189 |
assertDrop(c,
|
|
190 |
DiagCheck.DIAG_OK,
|
|
191 |
DiagCheck.DIAG_ERROR,
|
|
192 |
ste(c, RECOVERABLE_NOT_DEFINED, DROPPED, false, null),
|
|
193 |
ste(d, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, c));
|
|
194 |
assertEval("interface A {}", null, null,
|
|
195 |
DiagCheck.DIAG_OK, DiagCheck.DIAG_ERROR,
|
|
196 |
ste(a, DROPPED, VALID, true, null),
|
|
197 |
ste(b, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, MAIN_SNIPPET));
|
|
198 |
assertClasses();
|
|
199 |
assertActiveKeys();
|
|
200 |
}
|
|
201 |
|
|
202 |
public void testDropNoUpdate() {
|
|
203 |
String as1 = "class A {}";
|
|
204 |
String as2 = "class A extends java.util.ArrayList<Boolean> {}";
|
|
205 |
PersistentSnippet a = classKey(assertEval(as1, added(VALID)));
|
|
206 |
PersistentSnippet b = classKey(assertEval("class B extends A {}", added(VALID)));
|
|
207 |
PersistentSnippet ax = classKey(assertEval(as2,
|
|
208 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
209 |
ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
210 |
ste(b, VALID, VALID, true, MAIN_SNIPPET)));
|
|
211 |
ax = classKey(assertEval(as1,
|
|
212 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
213 |
ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
|
|
214 |
ste(b, VALID, VALID, true, MAIN_SNIPPET)));
|
|
215 |
assertDrop(b,
|
|
216 |
ste(b, VALID, DROPPED, true, null));
|
|
217 |
ax = classKey(assertEval(as2,
|
|
218 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
219 |
ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
|
|
220 |
assertEval(as1,
|
|
221 |
ste(MAIN_SNIPPET, VALID, VALID, true, null),
|
|
222 |
ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
|
|
223 |
}
|
|
224 |
}
|