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
|
|
26 |
* @summary Test of JShell#drop().
|
|
27 |
* @build KullaTesting TestingInputStream
|
|
28 |
* @run testng DropTest
|
|
29 |
*/
|
|
30 |
|
|
31 |
import jdk.jshell.DeclarationSnippet;
|
|
32 |
import jdk.jshell.PersistentSnippet;
|
|
33 |
import org.testng.annotations.Test;
|
|
34 |
|
|
35 |
import static jdk.jshell.Snippet.Status.*;
|
|
36 |
|
|
37 |
@Test
|
|
38 |
public class DropTest extends KullaTesting {
|
|
39 |
|
|
40 |
public void testDrop() {
|
|
41 |
PersistentSnippet var = varKey(assertEval("int x;"));
|
|
42 |
PersistentSnippet method = methodKey(assertEval("int mu() { return x * 4; }"));
|
|
43 |
PersistentSnippet clazz = classKey(assertEval("class C { String v() { return \"#\" + mu(); } }"));
|
|
44 |
assertDrop(var,
|
|
45 |
ste(var, VALID, DROPPED, true, null),
|
|
46 |
ste(method, VALID, RECOVERABLE_DEFINED, false, var));
|
|
47 |
//assertDrop(method,
|
|
48 |
// ste(method, RECOVERABLE_DEFINED, DROPPED, false, null),
|
|
49 |
// ste(clazz, RECOVERABLE_NOT_DEFINED, RECOVERABLE_NOT_DEFINED, false, method));
|
|
50 |
//assertDeclareFail("new C();", "compiler.err.cant.resolve.location");
|
|
51 |
assertVariables();
|
|
52 |
assertMethods();
|
|
53 |
assertClasses();
|
|
54 |
assertActiveKeys();
|
|
55 |
|
|
56 |
assertEval("int x = 10;", "10",
|
|
57 |
ste(var, DROPPED, VALID, true, null),
|
|
58 |
ste(method, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET));
|
|
59 |
PersistentSnippet c0 = varKey(assertEval("C c0 = new C();"));
|
|
60 |
assertEval("c0.v();", "\"#40\"");
|
|
61 |
assertEval("C c = new C();");
|
|
62 |
assertEval("c.v();", "\"#40\"");
|
|
63 |
assertEval("int mu() { return x * 3; }",
|
|
64 |
ste(MAIN_SNIPPET, VALID, VALID, false, null),
|
|
65 |
ste(method, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
|
|
66 |
assertEval("c.v();", "\"#30\"");
|
|
67 |
assertEval("class C { String v() { return \"@\" + mu(); } }",
|
|
68 |
ste(MAIN_SNIPPET, VALID, VALID, false, null),
|
|
69 |
ste(clazz, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
|
|
70 |
assertEval("c0.v();", "\"@30\"");
|
|
71 |
assertDrop(c0,
|
|
72 |
ste(c0, VALID, DROPPED, true, null));
|
|
73 |
assertEval("c = new C();");
|
|
74 |
assertEval("c.v();", "\"@30\"");
|
|
75 |
|
|
76 |
assertVariables();
|
|
77 |
assertMethods();
|
|
78 |
assertClasses();
|
|
79 |
assertActiveKeys();
|
|
80 |
}
|
|
81 |
|
|
82 |
@Test(enabled = false) // TODO 8081431
|
|
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 |
}
|