author | coleenp |
Fri, 31 Aug 2018 07:03:46 -0400 | |
changeset 51608 | 625a5bdde0c5 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
1 |
/* |
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
4 |
* |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
8 |
* |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
13 |
* accompanied this code). |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
14 |
* |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
18 |
* |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
21 |
* questions. |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
22 |
*/ |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
23 |
|
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
24 |
/* |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
25 |
* @test |
36154
63cd939d7e20
8150427: Demote ToolReloadTest.java and mark as intermittently failing
darcy
parents:
35812
diff
changeset
|
26 |
* @key intermittent |
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
27 |
* @bug 8081845 8147898 8143955 8165405 8178023 |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
28 |
* @summary Tests for /reload in JShell tool |
35359 | 29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
30 |
* jdk.compiler/com.sun.tools.javac.main |
|
36526 | 31 |
* jdk.jdeps/com.sun.tools.javap |
35359 | 32 |
* jdk.jshell/jdk.internal.jshell.tool |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
33 |
* @library /tools/lib |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36718
diff
changeset
|
34 |
* @build KullaTesting TestingInputStream toolbox.ToolBox Compiler |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
35 |
* @run testng ToolReloadTest |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
36 |
*/ |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
37 |
|
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
38 |
import java.nio.file.Path; |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
39 |
import java.nio.file.Paths; |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
40 |
import java.util.function.Function; |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
41 |
|
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
42 |
import org.testng.annotations.Test; |
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
43 |
import static org.testng.Assert.assertTrue; |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
44 |
|
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
45 |
|
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
46 |
@Test |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
47 |
public class ToolReloadTest extends ReplToolTesting { |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
48 |
|
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
49 |
public void testReloadSnippets() { |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
50 |
test( |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
51 |
(a) -> assertVariable(a, "int", "x", "5", "5"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
52 |
(a) -> assertMethod(a, "int m(int z) { return z * z; }", |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
53 |
"(int)int", "m"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
54 |
(a) -> evaluateExpression(a, "int", "m(x)", "25"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
55 |
(a) -> assertCommand(a, "/reload", |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
56 |
"| Restarting and restoring state.\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
57 |
"-: int x = 5;\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
58 |
"-: int m(int z) { return z * z; }\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
59 |
"-: m(x)\n"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
60 |
(a) -> evaluateExpression(a, "int", "m(x)", "25"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
61 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
62 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
63 |
); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
64 |
} |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
65 |
|
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
66 |
public void testReloadClasspath() { |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
67 |
Function<String,String> prog = (s) -> String.format( |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
68 |
"package pkg; public class A { public String toString() { return \"%s\"; } }\n", s); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
69 |
Compiler compiler = new Compiler(); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
70 |
Path outDir = Paths.get("testClasspathDirectory"); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
71 |
compiler.compile(outDir, prog.apply("A")); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
72 |
Path classpath = compiler.getPath(outDir); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
73 |
test( |
43038 | 74 |
(a) -> assertCommand(a, "/env --class-path " + classpath, |
75 |
"| Setting new options and restoring state."), |
|
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
76 |
(a) -> assertMethod(a, "String foo() { return (new pkg.A()).toString(); }", |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
77 |
"()String", "foo"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
78 |
(a) -> assertVariable(a, "String", "v", "foo()", "\"A\""), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
79 |
(a) -> { |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
80 |
if (!a) compiler.compile(outDir, prog.apply("Aprime")); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
81 |
assertCommand(a, "/reload", |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
82 |
"| Restarting and restoring state.\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
83 |
"-: String foo() { return (new pkg.A()).toString(); }\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
84 |
"-: String v = foo();\n"); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
85 |
}, |
37389 | 86 |
(a) -> assertCommand(a, "v", "v ==> \"Aprime\""), |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
87 |
(a) -> evaluateExpression(a, "String", "foo()", "\"Aprime\""), |
37389 | 88 |
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "Aprime") |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
89 |
); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
90 |
} |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
91 |
|
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
92 |
public void testReloadDrop() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38520
diff
changeset
|
93 |
test(false, new String[]{"--no-startup"}, |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
94 |
a -> assertVariable(a, "int", "a"), |
37389 | 95 |
a -> dropVariable(a, "/dr 1", "int a = 0", "| dropped variable a"), |
43759
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43038
diff
changeset
|
96 |
a -> assertMethod(a, "int b() { return 0; }", "()int", "b"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43038
diff
changeset
|
97 |
a -> dropMethod(a, "/drop b", "int b()", "| dropped method b()"), |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
98 |
a -> assertClass(a, "class A {}", "class", "A"), |
37389 | 99 |
a -> dropClass(a, "/dr A", "class A", "| dropped class A"), |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
100 |
a -> assertCommand(a, "/reload", |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
101 |
"| Restarting and restoring state.\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
102 |
"-: int a;\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
103 |
"-: /drop 1\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
104 |
"-: int b() { return 0; }\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
105 |
"-: /drop b\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
106 |
"-: class A {}\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
107 |
"-: /drop A\n"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
108 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
109 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37389
diff
changeset
|
110 |
a -> assertCommandCheckOutput(a, "/types", assertClasses()), |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
111 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
112 |
); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
113 |
} |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
114 |
|
35812 | 115 |
public void testReloadQuiet() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38520
diff
changeset
|
116 |
test(false, new String[]{"--no-startup"}, |
35812 | 117 |
a -> assertVariable(a, "int", "a"), |
37389 | 118 |
a -> dropVariable(a, "/dr 1", "int a = 0", "| dropped variable a"), |
43759
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43038
diff
changeset
|
119 |
a -> assertMethod(a, "int b() { return 0; }", "()int", "b"), |
61535ac55add
8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents:
43038
diff
changeset
|
120 |
a -> dropMethod(a, "/drop b", "int b()", "| dropped method b()"), |
35812 | 121 |
a -> assertClass(a, "class A {}", "class", "A"), |
37389 | 122 |
a -> dropClass(a, "/dr A", "class A", "| dropped class A"), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
123 |
a -> assertCommand(a, "/reload -quiet", |
37389 | 124 |
"| Restarting and restoring state."), |
35812 | 125 |
a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
126 |
a -> assertCommandCheckOutput(a, "/methods", assertMethods()), |
|
38514
f7df9ab653b0
8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents:
37389
diff
changeset
|
127 |
a -> assertCommandCheckOutput(a, "/types", assertClasses()), |
35812 | 128 |
a -> assertCommandCheckOutput(a, "/imports", assertImports()) |
129 |
); |
|
130 |
} |
|
131 |
||
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
132 |
public void testReloadRepeat() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38520
diff
changeset
|
133 |
test(false, new String[]{"--no-startup"}, |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
134 |
(a) -> assertVariable(a, "int", "c", "7", "7"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
135 |
(a) -> assertCommand(a, "++c", null), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
136 |
(a) -> assertCommand(a, "/!", null), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
137 |
(a) -> assertCommand(a, "/2", null), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
138 |
(a) -> assertCommand(a, "/-1", null), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
139 |
(a) -> assertCommand(a, "/reload", |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
140 |
"| Restarting and restoring state.\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
141 |
"-: int c = 7;\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
142 |
"-: ++c\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
143 |
"-: ++c\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
144 |
"-: ++c\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
145 |
"-: ++c\n" |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
146 |
), |
37389 | 147 |
(a) -> assertCommand(a, "c", "c ==> 11"), |
148 |
(a) -> assertCommand(a, "$4", "$4 ==> 10") |
|
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
149 |
); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
150 |
} |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
151 |
|
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
152 |
public void testReloadIgnore() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38520
diff
changeset
|
153 |
test(false, new String[]{"--no-startup"}, |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
154 |
(a) -> assertCommand(a, "(-)", null), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
155 |
(a) -> assertCommand(a, "/list", null), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
156 |
(a) -> assertCommand(a, "/history", null), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
157 |
(a) -> assertCommand(a, "/help", null), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
158 |
(a) -> assertCommand(a, "/vars", null), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
159 |
(a) -> assertCommand(a, "/save abcd", null), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
160 |
(a) -> assertCommand(a, "/reload", |
37389 | 161 |
"| Restarting and restoring state.") |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
162 |
); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
163 |
} |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
164 |
|
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
165 |
public void testReloadResetRestore() { |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
166 |
test( |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
167 |
(a) -> assertVariable(a, "int", "x", "5", "5"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
168 |
(a) -> assertMethod(a, "int m(int z) { return z * z; }", |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
169 |
"(int)int", "m"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
170 |
(a) -> evaluateExpression(a, "int", "m(x)", "25"), |
37389 | 171 |
(a) -> assertCommand(a, "/reset", "| Resetting state."), |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
172 |
(a) -> assertCommand(a, "/reload -restore", |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
173 |
"| Restarting and restoring from previous state.\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
174 |
"-: int x = 5;\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
175 |
"-: int m(int z) { return z * z; }\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
176 |
"-: m(x)\n"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
177 |
(a) -> evaluateExpression(a, "int", "m(x)", "25"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
178 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
179 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
180 |
); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
181 |
} |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
182 |
|
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
183 |
public void testReloadCrashRestore() { |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
184 |
test( |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
185 |
(a) -> assertVariable(a, "int", "x", "5", "5"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
186 |
(a) -> assertMethod(a, "int m(int z) { return z * z; }", |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
187 |
"(int)int", "m"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
188 |
(a) -> evaluateExpression(a, "int", "m(x)", "25"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
189 |
(a) -> assertCommand(a, "System.exit(1);", |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
190 |
"| State engine terminated.\n" + |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
191 |
"| Restore definitions with: /reload -restore"), |
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
192 |
(a) -> assertCommand(a, "/reload -restore", |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
193 |
"| Restarting and restoring from previous state.\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
194 |
"-: int x = 5;\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
195 |
"-: int m(int z) { return z * z; }\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
196 |
"-: m(x)\n"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
197 |
(a) -> evaluateExpression(a, "int", "m(x)", "25"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
198 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
199 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
200 |
); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
201 |
} |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
202 |
|
44683
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
203 |
public void testEnvBadModule() { |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
204 |
test( |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
205 |
(a) -> assertVariable(a, "int", "x", "5", "5"), |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
206 |
(a) -> assertMethod(a, "int m(int z) { return z * z; }", |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
207 |
"(int)int", "m"), |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
208 |
(a) -> assertCommandCheckOutput(a, "/env --add-module unKnown", |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
209 |
s -> { |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
210 |
assertTrue(s.startsWith( |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
211 |
"| Setting new options and restoring state.\n" + |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
212 |
"| Restart failed:")); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
213 |
assertTrue(s.contains("unKnown"), |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
214 |
"\"unKnown\" missing from: " + s); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
215 |
assertTrue(s.contains("previous settings"), |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
216 |
"\"previous settings\" missing from: " + s); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
217 |
}), |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
218 |
(a) -> evaluateExpression(a, "int", "m(x)", "25"), |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
219 |
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
220 |
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
221 |
); |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
222 |
} |
610dc2b48954
8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents:
43759
diff
changeset
|
223 |
|
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
224 |
public void testReloadExitRestore() { |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38520
diff
changeset
|
225 |
test(false, new String[]{"--no-startup"}, |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
226 |
(a) -> assertVariable(a, "int", "x", "5", "5"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
227 |
(a) -> assertMethod(a, "int m(int z) { return z * z; }", |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
228 |
"(int)int", "m"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
229 |
(a) -> evaluateExpression(a, "int", "m(x)", "25") |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
230 |
); |
40588
b5c32bfa9710
8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents:
38520
diff
changeset
|
231 |
test(false, new String[]{"--no-startup"}, |
38520
17e72b872ffd
8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents:
38514
diff
changeset
|
232 |
(a) -> assertCommand(a, "/reload -restore", |
34999
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
233 |
"| Restarting and restoring from previous state.\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
234 |
"-: int x = 5;\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
235 |
"-: int m(int z) { return z * z; }\n" + |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
236 |
"-: m(x)\n"), |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
237 |
(a) -> evaluateExpression(a, "int", "m(x)", "25") |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
238 |
); |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
239 |
} |
aacf94dab449
8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff
changeset
|
240 |
} |