langtools/test/jdk/jshell/ToolReloadTest.java
author rfield
Fri, 12 Feb 2016 10:51:36 -0800
changeset 35812 6a6ca0bd3c14
parent 35359 f04501964016
child 36154 63cd939d7e20
permissions -rw-r--r--
8146138: jshell tool: add /help <command> 8147495: jshell tool: correctly handle arguments on /seteditor command 8147886: jshell tool: commands don't allow reference to start-up or explicit id of dropped/failed snippets 8147887: jshell tool: /list start -- fails 8147898: jshell tool: /reload quiet -- should quiet echo Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34999
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
     1
/*
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 34999
diff changeset
     2
 * Copyright (c) 2015, 2016, 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
35812
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
    26
 * @bug 8081845 8147898
34999
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    27
 * @summary Tests for /reload in JShell tool
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 34999
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.api
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 34999
diff changeset
    29
 *          jdk.compiler/com.sun.tools.javac.main
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 34999
diff changeset
    30
 *          jdk.jshell/jdk.internal.jshell.tool
34999
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    31
 * @library /tools/lib
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    32
 * @build KullaTesting TestingInputStream ToolBox Compiler
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    33
 * @run testng ToolReloadTest
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    34
 */
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    35
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    36
import java.nio.file.Path;
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    37
import java.nio.file.Paths;
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    38
import java.util.function.Function;
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    39
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    40
import org.testng.annotations.Test;
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
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    43
@Test
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    44
public class ToolReloadTest extends ReplToolTesting {
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
    public void testReloadSnippets() {
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    47
        test(
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    48
                (a) -> assertVariable(a, "int", "x", "5", "5"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    49
                (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
    50
                        "(int)int", "m"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    51
                (a) -> evaluateExpression(a, "int", "m(x)", "25"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    52
                (a) -> assertCommand(a, "/reload",
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    53
                        "|  Restarting and restoring state.\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    54
                        "-: int x = 5;\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    55
                        "-: int m(int z) { return z * z; }\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    56
                        "-: m(x)\n"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    57
                (a) -> evaluateExpression(a, "int", "m(x)", "25"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    58
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    59
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods())
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    60
        );
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    61
    }
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    62
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    63
    public void testReloadClasspath() {
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    64
        Function<String,String> prog = (s) -> String.format(
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    65
                "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
    66
        Compiler compiler = new Compiler();
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    67
        Path outDir = Paths.get("testClasspathDirectory");
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    68
        compiler.compile(outDir, prog.apply("A"));
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    69
        Path classpath = compiler.getPath(outDir);
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    70
        test(
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    71
                (a) -> assertCommand(a, "/classpath " + classpath,
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    72
                        String.format("|  Path %s added to classpath\n", classpath)),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    73
                (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
    74
                        "()String", "foo"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    75
                (a) -> assertVariable(a, "String", "v", "foo()", "\"A\""),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    76
                (a) -> {
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    77
                       if (!a) compiler.compile(outDir, prog.apply("Aprime"));
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    78
                       assertCommand(a, "/reload",
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    79
                        "|  Restarting and restoring state.\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    80
                        "-: /classpath " + classpath + "\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    81
                        "-: String foo() { return (new pkg.A()).toString(); }\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    82
                        "-: String v = foo();\n");
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    83
                       },
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    84
                (a) -> assertCommand(a, "v", "|  Variable v of type String has value \"Aprime\"\n"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    85
                (a) -> evaluateExpression(a, "String", "foo()", "\"Aprime\""),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    86
                (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "\"Aprime\"")
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    87
        );
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    88
    }
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
    public void testReloadDrop() {
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    91
        test(false, new String[]{"-nostartup"},
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    92
                a -> assertVariable(a, "int", "a"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    93
                a -> dropVariable(a, "/dr 1", "int a = 0"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    94
                a -> assertMethod(a, "int b() { return 0; }", "()I", "b"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    95
                a -> dropMethod(a, "/drop b", "b ()I"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    96
                a -> assertClass(a, "class A {}", "class", "A"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    97
                a -> dropClass(a, "/dr A", "class A"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    98
                a -> assertCommand(a, "/reload",
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
    99
                        "|  Restarting and restoring state.\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   100
                        "-: int a;\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   101
                        "-: /drop 1\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   102
                        "-: int b() { return 0; }\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   103
                        "-: /drop b\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   104
                        "-: class A {}\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   105
                        "-: /drop A\n"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   106
                a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   107
                a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   108
                a -> assertCommandCheckOutput(a, "/classes", assertClasses()),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   109
                a -> assertCommandCheckOutput(a, "/imports", assertImports())
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   110
        );
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   111
    }
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   112
35812
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   113
    public void testReloadQuiet() {
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   114
        test(false, new String[]{"-nostartup"},
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   115
                a -> assertVariable(a, "int", "a"),
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   116
                a -> dropVariable(a, "/dr 1", "int a = 0"),
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   117
                a -> assertMethod(a, "int b() { return 0; }", "()I", "b"),
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   118
                a -> dropMethod(a, "/drop b", "b ()I"),
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   119
                a -> assertClass(a, "class A {}", "class", "A"),
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   120
                a -> dropClass(a, "/dr A", "class A"),
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   121
                a -> assertCommand(a, "/reload quiet",
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   122
                        "|  Restarting and restoring state.\n"),
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   123
                a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   124
                a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   125
                a -> assertCommandCheckOutput(a, "/classes", assertClasses()),
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   126
                a -> assertCommandCheckOutput(a, "/imports", assertImports())
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   127
        );
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   128
    }
6a6ca0bd3c14 8146138: jshell tool: add /help <command>
rfield
parents: 35359
diff changeset
   129
34999
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   130
    public void testReloadRepeat() {
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   131
        test(false, new String[]{"-nostartup"},
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   132
                (a) -> assertVariable(a, "int", "c", "7", "7"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   133
                (a) -> assertCommand(a, "++c", null),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   134
                (a) -> assertCommand(a, "/!", null),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   135
                (a) -> assertCommand(a, "/2", null),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   136
                (a) -> assertCommand(a, "/-1", null),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   137
                (a) -> assertCommand(a, "/reload",
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   138
                        "|  Restarting and restoring state.\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   139
                        "-: int c = 7;\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   140
                        "-: ++c\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   141
                        "-: ++c\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
                ),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   145
                (a) -> assertCommand(a, "c", "|  Variable c of type int has value 11\n"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   146
                (a) -> assertCommand(a, "$4", "|  Variable $4 of type int has value 10\n")
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   147
        );
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   148
    }
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
    public void testReloadIgnore() {
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   151
        test(false, new String[]{"-nostartup"},
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   152
                (a) -> assertCommand(a, "(-)", null),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   153
                (a) -> assertCommand(a, "/list", null),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   154
                (a) -> assertCommand(a, "/history", null),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   155
                (a) -> assertCommand(a, "/help", null),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   156
                (a) -> assertCommand(a, "/vars", null),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   157
                (a) -> assertCommand(a, "/save abcd", null),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   158
                (a) -> assertCommand(a, "/reload",
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   159
                        "|  Restarting and restoring state.\n")
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   160
        );
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   161
    }
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
    public void testReloadResetRestore() {
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   164
        test(
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   165
                (a) -> assertVariable(a, "int", "x", "5", "5"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   166
                (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
   167
                        "(int)int", "m"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   168
                (a) -> evaluateExpression(a, "int", "m(x)", "25"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   169
                (a) -> assertCommand(a, "/reset", "|  Resetting state.\n"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   170
                (a) -> assertCommand(a, "/reload restore",
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   171
                        "|  Restarting and restoring from previous state.\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   172
                        "-: int x = 5;\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   173
                        "-: int m(int z) { return z * z; }\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   174
                        "-: m(x)\n"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   175
                (a) -> evaluateExpression(a, "int", "m(x)", "25"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   176
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   177
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods())
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   178
        );
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   179
    }
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
    public void testReloadCrashRestore() {
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   182
        test(
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   183
                (a) -> assertVariable(a, "int", "x", "5", "5"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   184
                (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
   185
                        "(int)int", "m"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   186
                (a) -> evaluateExpression(a, "int", "m(x)", "25"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   187
                (a) -> assertCommand(a, "System.exit(1);",
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   188
                        "|  State engine terminated.\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   189
                        "|  Restore definitions with: /reload restore\n"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   190
                (a) -> assertCommand(a, "/reload restore",
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   191
                        "|  Restarting and restoring from previous state.\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   192
                        "-: int x = 5;\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   193
                        "-: int m(int z) { return z * z; }\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   194
                        "-: m(x)\n"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   195
                (a) -> evaluateExpression(a, "int", "m(x)", "25"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   196
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   197
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods())
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   198
        );
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   199
    }
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
    public void testReloadExitRestore() {
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   202
        test(false, new String[]{"-nostartup"},
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   203
                (a) -> assertVariable(a, "int", "x", "5", "5"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   204
                (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
   205
                        "(int)int", "m"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   206
                (a) -> evaluateExpression(a, "int", "m(x)", "25")
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   207
        );
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   208
        test(false, new String[]{"-nostartup"},
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   209
                (a) -> assertCommand(a, "/reload restore",
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   210
                        "|  Restarting and restoring from previous state.\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   211
                        "-: int x = 5;\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   212
                        "-: int m(int z) { return z * z; }\n" +
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   213
                        "-: m(x)\n"),
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   214
                (a) -> evaluateExpression(a, "int", "m(x)", "25")
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   215
        );
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   216
    }
aacf94dab449 8081845: JShell: Need way to refresh relative to external state
rfield
parents:
diff changeset
   217
}