test/langtools/jdk/jshell/DropTest.java
author rfield
Mon, 03 Jun 2019 08:21:04 -0700
changeset 55156 1c291d1c272c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8199623: JShell: corralling not restored on drop Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     1
/*
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     4
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     8
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    14
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    18
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    21
 * questions.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    22
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    23
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    24
/*
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    25
 * @test
55156
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
    26
 * @bug 8081431 8080069 8167128 8199623
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    27
 * @summary Test of JShell#drop().
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    28
 * @build KullaTesting TestingInputStream
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    29
 * @run testng DropTest
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    30
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    31
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    32
import jdk.jshell.DeclarationSnippet;
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
    33
import jdk.jshell.Snippet;
55156
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
    34
import jdk.jshell.MethodSnippet;
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
    35
import jdk.jshell.VarSnippet;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
import org.testng.annotations.Test;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    37
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    38
import static jdk.jshell.Snippet.Status.*;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    39
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    40
@Test
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    41
public class DropTest extends KullaTesting {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    42
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    43
    public void testDrop() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
    44
        Snippet var = varKey(assertEval("int x;"));
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
    45
        Snippet method = methodKey(assertEval("int mu() { return x * 4; }"));
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
    46
        Snippet clazz = classKey(assertEval("class C { String v() { return \"#\" + mu(); } }"));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    47
        assertDrop(var,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
                ste(var, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    49
                ste(method, VALID, RECOVERABLE_DEFINED, false, var));
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
    50
        assertDrop(method,
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
    51
                ste(method, RECOVERABLE_DEFINED, DROPPED, true, null),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
    52
                ste(clazz, VALID, RECOVERABLE_DEFINED, false, method));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
    53
        VarSnippet cc = varKey(assertEval("C c;"));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
    54
        assertEvalUnresolvedException("new C();", "C", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    55
        assertVariables();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    56
        assertMethods();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
        assertClasses();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    58
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    59
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
    60
        method = methodKey(assertEval("int mu() { return x * 4; }",
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36499
diff changeset
    61
                added(RECOVERABLE_DEFINED),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
    62
                ste(clazz, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    63
        assertEval("int x = 10;", "10",
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36499
diff changeset
    64
                added(VALID),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
                ste(method, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET));
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
    66
        Snippet c0 = varKey(assertEval("C c0 = new C();"));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    67
        assertEval("c0.v();", "\"#40\"");
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
    68
        assertEval("C c = new C();",
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
    69
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
    70
                ste(cc, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    71
        assertEval("c.v();", "\"#40\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    72
        assertEval("int mu() { return x * 3; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    73
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    74
                ste(method, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    75
        assertEval("c.v();", "\"#30\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    76
        assertEval("class C { String v() { return \"@\" + mu(); } }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
                ste(clazz, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    79
        assertEval("c0.v();", "\"@30\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    80
        assertDrop(c0,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    81
                ste(c0, VALID, DROPPED, true, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    82
        assertEval("c = new C();");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    83
        assertEval("c.v();", "\"@30\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    84
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    85
        assertVariables();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    86
        assertMethods();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    87
        assertClasses();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    88
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    89
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    90
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    91
    public void testDropImport() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
    92
        Snippet imp = importKey(assertEval("import java.util.*;"));
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
    93
        Snippet decl = varKey(
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    94
                assertEval("List<Integer> list = Arrays.asList(1, 2, 3);", "[1, 2, 3]"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    95
        assertEval("list;", "[1, 2, 3]");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    96
        assertDrop(imp,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    97
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    98
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    99
                ste(imp, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   100
                ste(decl, VALID, RECOVERABLE_NOT_DEFINED, true, imp));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   101
        assertDeclareFail("list;", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   102
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   103
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   104
    public void testDropStatement() {
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   105
        Snippet x = key(assertEval("if (true);"));
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   106
        assertDrop(x, ste(x, VALID, DROPPED, true, null));
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   107
    }
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   108
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   109
    public void testDropVarToMethod() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   110
        Snippet x = varKey(assertEval("int x;"));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   111
        DeclarationSnippet method = methodKey(assertEval("double mu() { return x * 4; }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   112
        assertEval("x == 0;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
        assertEval("mu() == 0.0;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   114
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   115
        assertDrop(x,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   116
                ste(x, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   117
                ste(method, VALID, RECOVERABLE_DEFINED, false, x));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   118
        assertUnresolvedDependencies1(method, RECOVERABLE_DEFINED, "variable x");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   119
        assertEvalUnresolvedException("mu();", "mu", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   120
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   121
        assertVariables();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   122
        assertMethods();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   123
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   124
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   125
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   126
    public void testDropMethodToMethod() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   127
        Snippet a = methodKey(assertEval("double a() { return 2; }"));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   128
        DeclarationSnippet b = methodKey(assertEval("double b() { return a() * 10; }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   129
        assertEval("double c() { return b() * 3; }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   130
        DeclarationSnippet d = methodKey(assertEval("double d() { return c() + 1000; }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   131
        assertEval("d();", "1060.0");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   132
        assertDrop(a,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   133
                ste(a, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   134
                ste(b, VALID, RECOVERABLE_DEFINED, false, a));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   135
        assertUnresolvedDependencies1(b, RECOVERABLE_DEFINED, "method a()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   136
        assertUnresolvedDependencies(d, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   137
        assertEvalUnresolvedException("d();", "b", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   138
        assertMethods();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   139
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   140
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   141
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   142
    public void testDropClassToMethod() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   143
        Snippet c = classKey(assertEval("class C { int f() { return 7; } }"));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   144
        DeclarationSnippet m = methodKey(assertEval("int m() { return new C().f(); }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   145
        assertDrop(c,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   146
                ste(c, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   147
                ste(m, VALID, RECOVERABLE_DEFINED, false, c));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   148
        assertUnresolvedDependencies1(m, RECOVERABLE_DEFINED, "class C");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   149
        assertEvalUnresolvedException("m();", "m", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   150
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   151
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   152
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   153
    public void testDropVarToClass() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   154
        Snippet x = varKey(assertEval("int x;"));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   155
        DeclarationSnippet a = classKey(assertEval("class A { double a = 4 * x; }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   156
        assertDrop(x,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   157
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   158
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   159
                ste(x, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
   160
                ste(a, VALID, RECOVERABLE_DEFINED, false, x));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
   161
        assertEval("A foo() { return null; }");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
   162
        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable x");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
   163
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   164
        assertVariables();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   165
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   166
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   167
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   168
    public void testDropMethodToClass() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   169
        Snippet x = methodKey(assertEval("int x() { return 0; }"));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   170
        DeclarationSnippet a = classKey(assertEval("class A { double a = 4 * x(); }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   171
        assertDrop(x,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   172
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   173
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   174
                ste(x, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
   175
                ste(a, VALID, RECOVERABLE_DEFINED, false, x));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
   176
        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "method x()");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 35736
diff changeset
   177
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   178
        assertMethods();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   179
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   180
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   181
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   182
    public void testDropClassToClass() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   183
        Snippet a = classKey(assertEval("class A {}"));
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   184
        Snippet b = classKey(assertEval("class B extends A {}"));
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   185
        Snippet c = classKey(assertEval("class C extends B {}"));
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   186
        Snippet d = classKey(assertEval("class D extends C {}"));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   187
        assertDrop(a,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   188
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   189
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   190
                ste(a, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   191
                ste(b, VALID, RECOVERABLE_NOT_DEFINED, true, a),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   192
                ste(c, VALID, RECOVERABLE_NOT_DEFINED, true, b),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   193
                ste(d, VALID, RECOVERABLE_NOT_DEFINED, true, c));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   194
        assertUnresolvedDependencies1((DeclarationSnippet) b, RECOVERABLE_NOT_DEFINED, "class A");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   195
        assertDrop(c,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   196
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   197
                DiagCheck.DIAG_ERROR,
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36499
diff changeset
   198
                ste(c, RECOVERABLE_NOT_DEFINED, DROPPED, false, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   199
        assertEval("interface A {}", null, null,
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36499
diff changeset
   200
                DiagCheck.DIAG_OK,
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36499
diff changeset
   201
                DiagCheck.DIAG_ERROR,
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36499
diff changeset
   202
                added(VALID));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   203
        assertClasses();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   204
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   205
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   206
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   207
    public void testDropNoUpdate() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   208
        String as1 = "class A {}";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   209
        String as2 = "class A extends java.util.ArrayList<Boolean> {}";
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   210
        Snippet a = classKey(assertEval(as1, added(VALID)));
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   211
        Snippet b = classKey(assertEval("class B extends A {}", added(VALID)));
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 37644
diff changeset
   212
        Snippet ax = classKey(assertEval(as2,
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   213
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   214
                ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   215
                ste(b, VALID, VALID, true, MAIN_SNIPPET)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   216
        ax = classKey(assertEval(as1,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   217
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   218
                ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   219
                ste(b, VALID, VALID, true, MAIN_SNIPPET)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   220
        assertDrop(b,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   221
                ste(b, VALID, DROPPED, true, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   222
        ax = classKey(assertEval(as2,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   223
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   224
                ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   225
        assertEval(as1,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   226
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   227
                ste(ax, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   228
    }
55156
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
   229
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
   230
    // 8199623
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
   231
    public void testTwoForkedDrop() {
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
   232
        MethodSnippet p = methodKey(assertEval("void p() throws Exception { ((String) null).toString(); }"));
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
   233
        MethodSnippet n = methodKey(assertEval("void n() throws Exception { try { p(); } catch (Exception ex) { throw new RuntimeException(\"bar\", ex); }}"));
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
   234
        MethodSnippet m = methodKey(assertEval("void m() { try { n(); } catch (Exception ex) { throw new RuntimeException(\"foo\", ex); }}"));
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
   235
        MethodSnippet c = methodKey(assertEval("void c() throws Throwable { p(); }"));
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
   236
        assertDrop(p,
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
   237
                ste(p, VALID, DROPPED, true, null),
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
   238
                ste(n, VALID, RECOVERABLE_DEFINED, false, p),
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
   239
                ste(c, VALID, RECOVERABLE_DEFINED, false, p));
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
   240
        assertActiveKeys();
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 47216
diff changeset
   241
    }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   242
}