author | rfield |
Thu, 02 Jun 2016 14:05:13 -0700 | |
changeset 38836 | b09d1cfbf28c |
parent 38535 | langtools/test/jdk/jshell/ExecutionControlTest.java@4a25025e0b0d |
child 43566 | 71aef8336eaa |
permissions | -rw-r--r-- |
38535
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
1 |
/* |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
4 |
* |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
8 |
* |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
13 |
* accompanied this code). |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
14 |
* |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
18 |
* |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
21 |
* questions. |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
22 |
*/ |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
23 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
24 |
import javax.tools.Diagnostic; |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
25 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
26 |
import jdk.jshell.VarSnippet; |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
27 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
28 |
import static jdk.jshell.Snippet.Status.VALID; |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
29 |
import static jdk.jshell.Snippet.SubKind.*; |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
30 |
|
38836
b09d1cfbf28c
8131029: JShell: recover from VMConnection launch failure
rfield
parents:
38535
diff
changeset
|
31 |
public class ExecutionControlTestBase extends KullaTesting { |
38535
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
32 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
33 |
public void classesDeclaration() { |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
34 |
assertEval("interface A { }"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
35 |
assertEval("class B implements A { }"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
36 |
assertEval("interface C extends A { }"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
37 |
assertEval("enum D implements C { }"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
38 |
assertEval("@interface E { }"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
39 |
assertClasses( |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
40 |
clazz(KullaTesting.ClassType.INTERFACE, "A"), |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
41 |
clazz(KullaTesting.ClassType.CLASS, "B"), |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
42 |
clazz(KullaTesting.ClassType.INTERFACE, "C"), |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
43 |
clazz(KullaTesting.ClassType.ENUM, "D"), |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
44 |
clazz(KullaTesting.ClassType.ANNOTATION, "E")); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
45 |
assertActiveKeys(); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
46 |
} |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
47 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
48 |
public void interfaceTest() { |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
49 |
String interfaceSource |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
50 |
= "interface A {\n" |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
51 |
+ " default int defaultMethod() { return 1; }\n" |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
52 |
+ " static int staticMethod() { return 2; }\n" |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
53 |
+ " int method();\n" |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
54 |
+ " class Inner1 {}\n" |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
55 |
+ " static class Inner2 {}\n" |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
56 |
+ "}"; |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
57 |
assertEval(interfaceSource); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
58 |
assertEval("A.staticMethod();", "2"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
59 |
String classSource |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
60 |
= "class B implements A {\n" |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
61 |
+ " public int method() { return 3; }\n" |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
62 |
+ "}"; |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
63 |
assertEval(classSource); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
64 |
assertEval("B b = new B();"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
65 |
assertEval("b.defaultMethod();", "1"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
66 |
assertDeclareFail("B.staticMethod();", |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
67 |
new ExpectedDiagnostic("compiler.err.cant.resolve.location.args", 0, 14, 1, -1, -1, Diagnostic.Kind.ERROR)); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
68 |
assertEval("b.method();", "3"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
69 |
assertEval("new A.Inner1();"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
70 |
assertEval("new A.Inner2();"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
71 |
assertEval("new B.Inner1();"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
72 |
assertEval("new B.Inner2();"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
73 |
} |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
74 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
75 |
public void variables() { |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
76 |
VarSnippet snx = varKey(assertEval("int x = 10;")); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
77 |
VarSnippet sny = varKey(assertEval("String y = \"hi\";")); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
78 |
VarSnippet snz = varKey(assertEval("long z;")); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
79 |
assertVariables(variable("int", "x"), variable("String", "y"), variable("long", "z")); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
80 |
assertVarValue(snx, "10"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
81 |
assertVarValue(sny, "\"hi\""); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
82 |
assertVarValue(snz, "0"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
83 |
assertActiveKeys(); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
84 |
} |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
85 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
86 |
public void methodOverload() { |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
87 |
assertEval("int m() { return 1; }"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
88 |
assertEval("int m(int x) { return 2; }"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
89 |
assertEval("int m(String s) { return 3; }"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
90 |
assertEval("int m(int x, int y) { return 4; }"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
91 |
assertEval("int m(int x, String z) { return 5; }"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
92 |
assertEval("int m(int x, String z, long g) { return 6; }"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
93 |
assertMethods( |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
94 |
method("()int", "m"), |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
95 |
method("(int)int", "m"), |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
96 |
method("(String)int", "m"), |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
97 |
method("(int,int)int", "m"), |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
98 |
method("(int,String)int", "m"), |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
99 |
method("(int,String,long)int", "m") |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
100 |
); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
101 |
assertEval("m();", "1"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
102 |
assertEval("m(3);", "2"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
103 |
assertEval("m(\"hi\");", "3"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
104 |
assertEval("m(7, 8);", "4"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
105 |
assertEval("m(7, \"eight\");", "5"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
106 |
assertEval("m(7, \"eight\", 9L);", "6"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
107 |
assertActiveKeys(); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
108 |
} |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
109 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
110 |
public void testExprSanity() { |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
111 |
assertEval("int x = 3;", "3"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
112 |
assertEval("int y = 4;", "4"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
113 |
assertEval("x + y;", "7"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
114 |
assertActiveKeys(); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
115 |
} |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
116 |
|
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
117 |
public void testImportOnDemand() { |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
118 |
assertImportKeyMatch("import java.util.*;", "java.util.*", TYPE_IMPORT_ON_DEMAND_SUBKIND, added(VALID)); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
119 |
assertEval("List<Integer> list = new ArrayList<>();"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
120 |
assertEval("list.add(45);"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
121 |
assertEval("list.size();", "1"); |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
122 |
} |
4a25025e0b0d
8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents:
diff
changeset
|
123 |
} |