langtools/test/jdk/jshell/ToolSimpleTest.java
author rfield
Thu, 18 May 2017 14:16:25 -0700
changeset 45215 c9477e22877f
parent 44454 74af976d6798
child 45602 7aeef976cb06
permissions -rw-r--r--
8167554: jshell tool: re-execute a range and/or sequence of snippets 8180508: jshell tool: support id ranges in all commands with id arguments Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
     1
/*
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
     4
 *
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
     8
 *
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    13
 * accompanied this code).
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    14
 *
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    18
 *
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    21
 * questions.
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    22
 */
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    23
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    24
/*
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    25
 * @test
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
    26
 * @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103  8165405 8173073 8173848 8174041 8173916 8174028 8174262 8174797 8177079 8180508
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    27
 * @summary Simple jshell tool tests
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.api
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    29
 *          jdk.compiler/com.sun.tools.javac.main
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    30
 *          jdk.jdeps/com.sun.tools.javap
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    31
 *          jdk.jshell/jdk.internal.jshell.tool
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    32
 * @build KullaTesting TestingInputStream
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    33
 * @run testng ToolSimpleTest
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    34
 */
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    35
import java.util.Arrays;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    36
import java.util.ArrayList;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    37
import java.util.List;
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
    38
import java.util.Locale;
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    39
import java.util.function.Consumer;
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
    40
import java.util.regex.Pattern;
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    41
import java.util.stream.Collectors;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    42
import java.util.stream.Stream;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    43
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    44
import org.testng.annotations.Test;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    45
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    46
import static org.testng.Assert.assertEquals;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    47
import static org.testng.Assert.assertTrue;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    48
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    49
public class ToolSimpleTest extends ReplToolTesting {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    50
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
    51
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    52
    public void testRemaining() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    53
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    54
                (a) -> assertCommand(a, "int z; z =", "z ==> 0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    55
                (a) -> assertCommand(a, "5", "z ==> 5"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    56
                (a) -> assertCommand(a, "/*nada*/; int q =", ""),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    57
                (a) -> assertCommand(a, "77", "q ==> 77"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    58
                (a) -> assertCommand(a, "//comment;", ""),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    59
                (a) -> assertCommand(a, "int v;", "v ==> 0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    60
                (a) -> assertCommand(a, "int v; int c",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    61
                        "v ==> 0\n" +
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    62
                        "c ==> 0")
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    63
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    64
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    65
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
    66
    @Test
38835
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    67
    public void testOpenComment() {
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    68
        test(
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    69
                (a) -> assertCommand(a, "int z = /* blah", ""),
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    70
                (a) -> assertCommand(a, "baz */ 5", "z ==> 5"),
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    71
                (a) -> assertCommand(a, "/** hoge ", ""),
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    72
                (a) -> assertCommand(a, "baz **/", ""),
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    73
                (a) -> assertCommand(a, "int v", "v ==> 0")
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    74
        );
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    75
    }
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    76
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
    77
    @Test
43586
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
    78
    public void testLessThan() {
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
    79
        test(
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
    80
                (a) -> assertCommand(a, "45", "$1 ==> 45"),
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
    81
                (a) -> assertCommand(a, "72", "$2 ==> 72"),
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
    82
                (a) -> assertCommand(a, "$1 < $2", "$3 ==> true"),
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
    83
                (a) -> assertCommand(a, "int a, b", "a ==> 0\n" +
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
    84
                        "b ==> 0"),
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
    85
                (a) -> assertCommand(a, "a < b", "$6 ==> false")
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
    86
        );
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
    87
    }
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
    88
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
    89
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    90
    public void oneLineOfError() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    91
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    92
                (a) -> assertCommand(a, "12+", null),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    93
                (a) -> assertCommandCheckOutput(a, "  true", (s) ->
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    94
                        assertTrue(s.contains("12+") && !s.contains("true"), "Output: '" + s + "'"))
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    95
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    96
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    97
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
    98
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    99
    public void defineVariables() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   100
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   101
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   102
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   103
                (a) -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   104
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   105
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   106
                (a) -> assertVariable(a, "double", "a", "1", "1.0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   107
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   108
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   109
                (a) -> evaluateExpression(a, "double", "2 * a", "2.0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   110
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   111
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   112
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   113
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   114
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   115
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   116
    public void defineMethods() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   117
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   118
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   119
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   120
                (a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   121
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   122
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   123
                (a) -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   124
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   125
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   126
                (a) -> assertMethod(a, "void g() {}", "()void", "g"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   127
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   128
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   129
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   130
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   131
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   132
    @Test
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   133
    public void defineTypes() {
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   134
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   135
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   136
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   137
                (a) -> assertClass(a, "class A { }", "class", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   138
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   139
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   140
                (a) -> assertClass(a, "interface A { }", "interface", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   141
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   142
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   143
                (a) -> assertClass(a, "enum A { }", "enum", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   144
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   145
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   146
                (a) -> assertClass(a, "@interface A { }", "@interface", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   147
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   148
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses())
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   149
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   150
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   151
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   152
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   153
    public void defineImports() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   154
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   155
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   156
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   157
                (a) -> assertImport(a, "import java.util.stream.Stream;", "", "java.util.stream.Stream"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   158
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   159
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   160
                (a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   161
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   162
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   163
                (a) -> assertImport(a, "import static java.lang.Math.PI;", "static", "java.lang.Math.PI"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   164
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   165
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   166
                (a) -> assertImport(a, "import static java.lang.Math.*;", "static", "java.lang.Math.*"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   167
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   168
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   169
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   170
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   171
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   172
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   173
    public void defineVar() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   174
        test(
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   175
                (a) -> assertCommand(a, "int x = 72", "x ==> 72"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   176
                (a) -> assertCommand(a, "x", "x ==> 72"),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   177
                (a) -> assertCommand(a, "/vars", "|    int x = 72")
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   178
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   179
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   180
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   181
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   182
    public void defineUnresolvedVar() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   183
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   184
                (a) -> assertCommand(a, "undefined x",
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   185
                        "|  created variable x, however, it cannot be referenced until class undefined is declared"),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   186
                (a) -> assertCommand(a, "/vars", "|    undefined x = (not-active)")
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   187
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   188
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   189
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   190
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   191
    public void testUnresolved() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   192
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   193
                (a) -> assertCommand(a, "int f() { return g() + x + new A().a; }",
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   194
                        "|  created method f(), however, it cannot be invoked until method g(), variable x, and class A are declared"),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   195
                (a) -> assertCommand(a, "f()",
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   196
                        "|  attempted to call method f() which cannot be invoked until method g(), variable x, and class A are declared"),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   197
                (a) -> assertCommandOutputStartsWith(a, "int g() { return x; }",
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   198
                        "|  created method g(), however, it cannot be invoked until variable x is declared"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   199
                (a) -> assertCommand(a, "g()", "|  attempted to call method g() which cannot be invoked until variable x is declared")
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   200
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   201
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   202
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   203
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   204
    public void testUnknownCommand() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   205
        test((a) -> assertCommand(a, "/unknown",
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   206
                "|  Invalid command: /unknown\n" +
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   207
                "|  Type /help for help."));
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   208
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   209
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   210
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   211
    public void testEmptyClassPath() {
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   212
        test(after -> assertCommand(after, "/env --class-path", "|  Argument to class-path missing."));
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   213
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   214
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   215
    @Test
43856
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43766
diff changeset
   216
    public void testInvalidClassPath() {
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43766
diff changeset
   217
        test(
43861
825bad9a162a 8174862: JShell tests: new JDK-8174797 testInvalidClassPath fails on Windows
rfield
parents: 43856
diff changeset
   218
                a -> assertCommand(a, "/env --class-path snurgefusal",
825bad9a162a 8174862: JShell tests: new JDK-8174797 testInvalidClassPath fails on Windows
rfield
parents: 43856
diff changeset
   219
                        "|  File 'snurgefusal' for '--class-path' is not found.")
43856
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43766
diff changeset
   220
        );
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43766
diff changeset
   221
    }
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43766
diff changeset
   222
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43766
diff changeset
   223
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   224
    public void testNoArgument() {
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   225
        test(
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   226
                (a) -> assertCommand(a, "/save",
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   227
                        "|  '/save' requires a filename argument."),
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   228
                (a) -> assertCommand(a, "/open",
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   229
                        "|  '/open' requires a filename argument."),
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 41514
diff changeset
   230
                (a) -> assertCommandOutputStartsWith(a, "/drop",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 41514
diff changeset
   231
                        "|  In the /drop argument, please specify an import, variable, method, or class to drop.")
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   232
        );
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   233
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   234
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   235
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   236
    public void testDebug() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   237
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   238
                (a) -> assertCommand(a, "/deb", "|  Debugging on"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   239
                (a) -> assertCommand(a, "/debug", "|  Debugging off"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   240
                (a) -> assertCommand(a, "/debug", "|  Debugging on"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   241
                (a) -> assertCommand(a, "/deb", "|  Debugging off")
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   242
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   243
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   244
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   245
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   246
    public void testDrop() {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   247
        test(false, new String[]{"--no-startup"},
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   248
                a -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   249
                a -> dropVariable(a, "/drop 1", "int a = 0", "|  dropped variable a"),
43759
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   250
                a -> assertMethod(a, "int b() { return 0; }", "()int", "b"),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   251
                a -> dropMethod(a, "/drop 2", "int b()", "|  dropped method b()"),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   252
                a -> assertClass(a, "class A {}", "class", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   253
                a -> dropClass(a, "/drop 3", "class A", "|  dropped class A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   254
                a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   255
                a -> dropImport(a, "/drop 4", "import java.util.stream.*", ""),
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40601
diff changeset
   256
                a -> assertCommand(a, "for (int i = 0; i < 10; ++i) {}", ""),
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40601
diff changeset
   257
                a -> assertCommand(a, "/drop 5", ""),
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40601
diff changeset
   258
                a -> assertCommand(a, "/list", ""),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   259
                a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   260
                a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   261
                a -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   262
                a -> assertCommandCheckOutput(a, "/imports", assertImports())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   263
        );
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   264
        test(false, new String[]{"--no-startup"},
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   265
                a -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   266
                a -> dropVariable(a, "/drop a", "int a = 0", "|  dropped variable a"),
43759
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   267
                a -> assertMethod(a, "int b() { return 0; }", "()int", "b"),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   268
                a -> dropMethod(a, "/drop b", "int b()", "|  dropped method b()"),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   269
                a -> assertClass(a, "class A {}", "class", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   270
                a -> dropClass(a, "/drop A", "class A", "|  dropped class A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   271
                a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   272
                a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   273
                a -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   274
                a -> assertCommandCheckOutput(a, "/imports", assertImports())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   275
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   276
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   277
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   278
    @Test
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   279
    public void testDropRange() {
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   280
        test(false, new String[]{"--no-startup"},
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   281
                a -> assertVariable(a, "int", "a"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   282
                a -> assertMethod(a, "int b() { return 0; }", "()int", "b"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   283
                a -> assertClass(a, "class A {}", "class", "A"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   284
                a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   285
                a -> assertCommand(a, "for (int i = 0; i < 10; ++i) {}", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   286
                a -> assertCommand(a, "/drop 3-5 b 1",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   287
                        "|  dropped class A\n" +
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   288
                        "|  dropped method b()\n" +
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   289
                        "|  dropped variable a\n"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   290
                a -> assertCommand(a, "/list", "")
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   291
        );
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   292
    }
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   293
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   294
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   295
    public void testDropNegative() {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   296
        test(false, new String[]{"--no-startup"},
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   297
                a -> assertCommandOutputStartsWith(a, "/drop 0", "|  No snippet with id: 0"),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   298
                a -> assertCommandOutputStartsWith(a, "/drop a", "|  No such snippet: a"),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   299
                a -> assertCommandCheckOutput(a, "/drop",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   300
                        assertStartsWith("|  In the /drop argument, please specify an import, variable, method, or class to drop.")),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   301
                a -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   302
                a -> assertCommand(a, "a", "a ==> 0"),
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40601
diff changeset
   303
                a -> assertCommand(a, "/drop 2", ""),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   304
                a -> assertCommand(a, "/drop 2",
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   305
                        "|  This command does not accept the snippet '2' : a\n" +
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   306
                        "|  See /types, /methods, /vars, or /list")
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   307
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   308
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   309
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   310
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   311
    public void testAmbiguousDrop() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   312
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   313
                a -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   314
                a -> assertMethod(a, "int a() { return 0; }", "()int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   315
                a -> assertClass(a, "class a {}", "class", "a"),
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   316
                a -> assertCommand(a, "/drop a",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   317
                        "|  dropped variable a\n" +
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   318
                        "|  dropped method a()\n" +
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   319
                        "|  dropped class a")
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   320
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   321
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   322
                a -> assertMethod(a, "int a() { return 0; }", "()int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   323
                a -> assertMethod(a, "double a(int a) { return 0; }", "(int)double", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   324
                a -> assertMethod(a, "double a(double a) { return 0; }", "(double)double", "a"),
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   325
                a -> assertCommand(a, "/drop a",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   326
                        "|  dropped method a()\n" +
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   327
                        "|  dropped method a(int)\n" +
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   328
                        "|  dropped method a(double)\n")
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   329
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   330
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   331
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   332
    @Test
42412
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   333
    public void testApplicationOfPost() {
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   334
        test(
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   335
                (a) -> assertCommand(a, "/set mode t normal -command", "|  Created new feedback mode: t"),
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   336
                (a) -> assertCommand(a, "/set feedback t", "|  Feedback mode: t"),
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   337
                (a) -> assertCommand(a, "/set format t post \"$%n\"", ""),
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   338
                (a) -> assertCommand(a, "/set prompt t \"+\" \"-\"", ""),
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   339
                (a) -> assertCommand(a, "/set prompt t", "|  /set prompt t \"+\" \"-\"$")
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   340
        );
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   341
    }
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   342
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   343
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   344
    public void testHelpLength() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   345
        Consumer<String> testOutput = (s) -> {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   346
            List<String> ss = Stream.of(s.split("\n"))
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   347
                    .filter(l -> !l.isEmpty())
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   348
                    .collect(Collectors.toList());
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   349
            assertTrue(ss.size() >= 10, "Help does not print enough lines:" + s);
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   350
        };
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   351
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   352
                (a) -> assertCommandCheckOutput(a, "/?", testOutput),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   353
                (a) -> assertCommandCheckOutput(a, "/help", testOutput),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   354
                (a) -> assertCommandCheckOutput(a, "/help /list", testOutput)
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   355
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   356
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   357
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   358
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   359
    public void testHelp() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   360
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   361
                (a) -> assertHelp(a, "/?", "/list", "/help", "/exit", "intro"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   362
                (a) -> assertHelp(a, "/help", "/list", "/help", "/exit", "intro"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   363
                (a) -> assertHelp(a, "/help short", "shortcuts", "<tab>"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   364
                (a) -> assertHelp(a, "/? /li", "/list -all", "snippets"),
42412
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   365
                (a) -> assertHelp(a, "/help /set prompt", "optionally contain '%s'", "quoted"),
44454
74af976d6798 8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents: 43861
diff changeset
   366
                (a) -> assertHelp(a, "/help /help", "/help <command>"),
74af976d6798 8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents: 43861
diff changeset
   367
                (a) -> assertHelp(a, "/help li", "/list -start"),
74af976d6798 8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents: 43861
diff changeset
   368
                (a) -> assertHelp(a, "/help fe", "/set feedback -retain")
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   369
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   370
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   371
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   372
    @Test
42412
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   373
    public void testHelpFormat() {
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   374
        test(
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   375
                (a) -> assertCommandCheckOutput(a, "/help", s -> {
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   376
                    String[] lines = s.split("\\R");
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   377
                    assertTrue(lines.length > 20,
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   378
                            "Too few lines of /help output: " + lines.length
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   379
                          + "\n" + s);
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   380
                    for (int i = 0; i < lines.length; ++i) {
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   381
                        String l = lines[i];
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   382
                        assertTrue(l.startsWith("| "),
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   383
                                "Expected /help line to start with | :\n" + l);
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   384
                        assertTrue(l.length() <= 80,
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   385
                                "/help line too long: " + l.length() + "\n" + l);
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   386
                    }
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   387
                 })
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   388
        );
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   389
    }
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   390
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   391
    private void assertHelp(boolean a, String command, String... find) {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   392
        assertCommandCheckOutput(a, command, s -> {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   393
            for (String f : find) {
42412
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   394
                assertTrue(s.contains(f),
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   395
                        "Expected output of " + command + " to contain: " + f
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   396
                      + "\n" + s);
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   397
            }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   398
        });
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   399
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   400
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   401
    // Check that each line of output contains the corresponding string from the list
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   402
    private void checkLineToList(String in, List<String> match) {
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   403
        String trimmed = in.trim();
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   404
        String[] res = trimmed.isEmpty()
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   405
                ? new String[0]
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   406
                : trimmed.split("\n");
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   407
        assertEquals(res.length, match.size(), "Got: " + Arrays.asList(res));
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   408
        for (int i = 0; i < match.size(); ++i) {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   409
            assertTrue(res[i].contains(match.get(i)));
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   410
        }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   411
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   412
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   413
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   414
    public void testListArgs() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   415
        String arg = "qqqq";
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   416
        List<String> startVarList = new ArrayList<>(START_UP);
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   417
        startVarList.add("int aardvark");
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   418
        startVarList.add("int weevil");
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   419
        test(
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   420
                a -> assertCommandCheckOutput(a, "/list -all",
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   421
                        s -> checkLineToList(s, START_UP)),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   422
                a -> assertCommandOutputStartsWith(a, "/list " + arg,
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   423
                        "|  No such snippet: " + arg),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   424
                a -> assertVariable(a, "int", "aardvark"),
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   425
                a -> assertVariable(a, "int", "weevil"),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   426
                a -> assertCommandOutputContains(a, "/list aardvark", "aardvark"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   427
                a -> assertCommandCheckOutput(a, "/list -start",
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   428
                        s -> checkLineToList(s, START_UP)),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   429
                a -> assertCommandCheckOutput(a, "/list -all",
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   430
                        s -> checkLineToList(s, startVarList)),
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   431
                a -> assertCommandOutputStartsWith(a, "/list s3",
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   432
                        "s3 : import"),
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   433
                a -> assertCommandCheckOutput(a, "/list 1-2 s3",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   434
                        s -> {
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   435
                            assertTrue(Pattern.matches(".*aardvark.*\\R.*weevil.*\\R.*s3.*import.*", s.trim()),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   436
                                    "No match: " + s);
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   437
                        }),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   438
                a -> assertCommandOutputStartsWith(a, "/list " + arg,
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   439
                        "|  No such snippet: " + arg)
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   440
        );
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   441
    }
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   442
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   443
    @Test
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   444
    public void testVarsArgs() {
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   445
        String arg = "qqqq";
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   446
        List<String> startVarList = new ArrayList<>();
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   447
        test(
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   448
                a -> assertCommandCheckOutput(a, "/vars -all",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   449
                        s -> checkLineToList(s, startVarList)),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   450
                a -> assertCommand(a, "/vars " + arg,
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   451
                        "|  No such snippet: " + arg),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   452
                a -> assertVariable(a, "int", "aardvark"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   453
                a -> assertMethod(a, "int f() { return 0; }", "()int", "f"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   454
                a -> assertVariable(a, "int", "a"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   455
                a -> assertVariable(a, "double", "a", "1", "1.0"),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   456
                a -> assertCommandOutputStartsWith(a, "/vars aardvark",
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   457
                        "|    int aardvark = 0"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   458
                a -> assertCommandCheckOutput(a, "/vars -start",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   459
                        s -> checkLineToList(s, startVarList)),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   460
                a -> assertCommandOutputStartsWith(a, "/vars -all",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   461
                        "|    int aardvark = 0\n|    int a = "),
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   462
                a -> assertCommandOutputStartsWith(a, "/vars 1-4",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   463
                        "|    int aardvark = 0\n|    int a = "),
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   464
                a -> assertCommandOutputStartsWith(a, "/vars f",
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   465
                        "|  This command does not accept the snippet 'f'"),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   466
                a -> assertCommand(a, "/var " + arg,
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   467
                        "|  No such snippet: " + arg)
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   468
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   469
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   470
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   471
    @Test
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   472
    public void testMethodsArgs() {
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   473
        String arg = "qqqq";
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   474
        List<String> printingMethodList = new ArrayList<>(PRINTING_CMD_METHOD);
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   475
        test(new String[]{"--startup", "PRINTING"},
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   476
                a -> assertCommandCheckOutput(a, "/methods -all",
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   477
                        s -> checkLineToList(s, printingMethodList)),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   478
                a -> assertCommandCheckOutput(a, "/methods -start",
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   479
                        s -> checkLineToList(s, printingMethodList)),
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   480
                a -> assertCommandCheckOutput(a, "/methods print println printf",
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   481
                        s -> checkLineToList(s, printingMethodList)),
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   482
                a -> assertCommandCheckOutput(a, "/methods println",
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   483
                        s -> assertEquals(s.trim().split("\n").length, 10)),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   484
                a -> assertCommandCheckOutput(a, "/methods",
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   485
                        s -> checkLineToList(s, printingMethodList)),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   486
                a -> assertCommandOutputStartsWith(a, "/methods " + arg,
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   487
                        "|  No such snippet: " + arg),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   488
                a -> assertMethod(a, "int f() { return 0; }", "()int", "f"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   489
                a -> assertVariable(a, "int", "aardvark"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   490
                a -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   491
                a -> assertMethod(a, "void g() {}", "()void", "g"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   492
                a -> assertCommandOutputStartsWith(a, "/methods " + arg,
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   493
                        "|  No such snippet: " + arg),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   494
                a -> assertCommandOutputStartsWith(a, "/methods aardvark",
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   495
                        "|  This command does not accept the snippet 'aardvark' : int aardvark"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   496
                a -> assertCommandCheckOutput(a, "/methods -start",
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   497
                        s -> checkLineToList(s, printingMethodList)),
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   498
                a -> assertCommandCheckOutput(a, "/methods print println printf",
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   499
                        s -> checkLineToList(s, printingMethodList)),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   500
                a -> assertCommandOutputStartsWith(a, "/methods g",
43759
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   501
                        "|    void g()"),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   502
                a -> assertCommandOutputStartsWith(a, "/methods f",
43759
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   503
                        "|    int f()\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   504
                        "|    void f(int)")
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   505
        );
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   506
    }
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   507
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   508
    @Test
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   509
    public void testMethodsWithErrors() {
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   510
        test(new String[]{"--no-startup"},
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   511
                a -> assertCommand(a, "double m(int x) { return x; }",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   512
                        "|  created method m(int)"),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   513
                a -> assertCommand(a, "GARBAGE junk() { return TRASH; }",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   514
                        "|  created method junk(), however, it cannot be referenced until class GARBAGE, and variable TRASH are declared"),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   515
                a -> assertCommand(a, "int w = 5;",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   516
                        "w ==> 5"),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   517
                a -> assertCommand(a, "int tyer() { return w; }",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   518
                        "|  created method tyer()"),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   519
                a -> assertCommand(a, "String w = \"hi\";",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   520
                        "w ==> \"hi\""),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   521
                a -> assertCommand(a, "/methods",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   522
                        "|    double m(int)\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   523
                        "|    GARBAGE junk()\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   524
                        "|       which cannot be referenced until class GARBAGE, and variable TRASH are declared\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   525
                        "|    int tyer()\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   526
                        "|       which cannot be invoked until this error is corrected: \n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   527
                        "|          incompatible types: java.lang.String cannot be converted to int\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   528
                        "|          int tyer() { return w; }\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   529
                        "|                              ^\n")
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   530
        );
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   531
    }
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   532
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   533
    @Test
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   534
    public void testTypesWithErrors() {
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   535
        test(new String[]{"--no-startup"},
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   536
                a -> assertCommand(a, "class C extends NONE { int x; }",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   537
                        "|  created class C, however, it cannot be referenced until class NONE is declared"),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   538
                a -> assertCommand(a, "class D { void m() { System.out.println(nada); } }",
43766
498b07dcf851 8174262: Error message misspelling: "instanciated"
rfield
parents: 43759
diff changeset
   539
                        "|  created class D, however, it cannot be instantiated or its methods invoked until variable nada is declared"),
43759
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   540
                a -> assertCommand(a, "/types",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   541
                        "|    class C\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   542
                        "|       which cannot be referenced until class NONE is declared\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   543
                        "|    class D\n" +
43766
498b07dcf851 8174262: Error message misspelling: "instanciated"
rfield
parents: 43759
diff changeset
   544
                        "|       which cannot be instantiated or its methods invoked until variable nada is declared\n")
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   545
        );
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   546
    }
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   547
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   548
    @Test
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   549
    public void testTypesArgs() {
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   550
        String arg = "qqqq";
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   551
        List<String> startTypeList = new ArrayList<>();
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   552
        test(
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   553
                a -> assertCommandCheckOutput(a, "/types -all",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   554
                        s -> checkLineToList(s, startTypeList)),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   555
                a -> assertCommandCheckOutput(a, "/types -start",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   556
                        s -> checkLineToList(s, startTypeList)),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   557
                a -> assertCommandOutputStartsWith(a, "/types " + arg,
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   558
                        "|  No such snippet: " + arg),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   559
                a -> assertVariable(a, "int", "aardvark"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   560
                (a) -> assertClass(a, "class A { }", "class", "A"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   561
                (a) -> assertClass(a, "interface A { }", "interface", "A"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   562
                a -> assertCommandOutputStartsWith(a, "/types -all",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   563
                        "|    class A\n" +
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   564
                        "|    interface A"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   565
                (a) -> assertClass(a, "enum E { }", "enum", "E"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   566
                (a) -> assertClass(a, "@interface B { }", "@interface", "B"),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   567
                a -> assertCommand(a, "/types aardvark",
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   568
                        "|  This command does not accept the snippet 'aardvark' : int aardvark;"),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   569
                a -> assertCommandOutputStartsWith(a, "/types A",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   570
                        "|    interface A"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   571
                a -> assertCommandOutputStartsWith(a, "/types E",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   572
                        "|    enum E"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   573
                a -> assertCommandOutputStartsWith(a, "/types B",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   574
                        "|    @interface B"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   575
                a -> assertCommandOutputStartsWith(a, "/types " + arg,
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   576
                        "|  No such snippet: " + arg),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   577
                a -> assertCommandCheckOutput(a, "/types -start",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   578
                        s -> checkLineToList(s, startTypeList))
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   579
        );
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   580
    }
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   581
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   582
    @Test
43274
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   583
    public void testBlankLinesInSnippetContinuation() {
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   584
        test(Locale.ROOT, false, new String[]{"--no-startup"}, "",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   585
                a -> assertCommand(a, "class C {",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   586
                        ""),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   587
                a -> assertCommand(a, "",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   588
                        ""),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   589
                a -> assertCommand(a, "",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   590
                        ""),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   591
                a -> assertCommand(a, "  int x;",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   592
                        ""),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   593
                a -> assertCommand(a, "",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   594
                        ""),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   595
                a -> assertCommand(a, "",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   596
                        ""),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   597
                a -> assertCommand(a, "}",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   598
                        "|  created class C"),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   599
                a -> assertCommand(a, "/list",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   600
                        "\n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   601
                        "   1 : class C {\n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   602
                        "       \n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   603
                        "       \n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   604
                        "         int x;\n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   605
                        "       \n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   606
                        "       \n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   607
                        "       }")
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   608
        );
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   609
    }
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   610
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   611
    @Test
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   612
    public void testCompoundStart() {
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   613
        test(new String[]{"--startup", "DEFAULT", "--startup", "PRINTING"},
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   614
                (a) -> assertCommand(a, "printf(\"%4.2f\", Math.PI)",
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   615
                        "", "", null, "3.14", "")
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   616
        );
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   617
    }
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   618
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   619
    @Test
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   620
    public void testJavaSeStart() {
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   621
        test(new String[]{"--startup", "JAVASE"},
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   622
                (a) -> assertCommand(a, "ZoneOffsetTransitionRule.TimeDefinition.WALL",
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   623
                        "$1 ==> WALL")
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   624
        );
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   625
    }
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   626
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   627
    @Test
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   628
    public void defineClasses() {
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   629
        test(
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   630
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   631
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   632
                (a) -> assertClass(a, "class A { }", "class", "A"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   633
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   634
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   635
                (a) -> assertClass(a, "interface A { }", "interface", "A"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   636
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   637
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   638
                (a) -> assertClass(a, "enum A { }", "enum", "A"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   639
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   640
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   641
                (a) -> assertClass(a, "@interface A { }", "@interface", "A"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   642
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   643
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses())
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   644
        );
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   645
    }
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   646
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   647
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   648
    public void testCommandPrefix() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   649
        test(a -> assertCommandCheckOutput(a, "/s",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   650
                      assertStartsWith("|  Command: '/s' is ambiguous: /save, /set")),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   651
             a -> assertCommand(a, "int var", "var ==> 0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   652
             a -> assertCommandCheckOutput(a, "/va",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   653
                      assertStartsWith("|    int var = 0")),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   654
             a -> assertCommandCheckOutput(a, "/save",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   655
                      assertStartsWith("|  '/save' requires a filename argument.")));
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   656
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   657
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   658
    @Test
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   659
    public void testOptionQ() {
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
   660
        test(Locale.ROOT, false, new String[]{"-q", "--no-startup"}, "",
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   661
                (a) -> assertCommand(a, "1+1", "$1 ==> 2"),
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   662
                (a) -> assertCommand(a, "int x = 5", "")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   663
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   664
    }
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   665
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   666
    @Test
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   667
    public void testOptionS() {
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
   668
        test(Locale.ROOT, false, new String[]{"-s", "--no-startup"}, "",
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   669
                (a) -> assertCommand(a, "1+1", "")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   670
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   671
    }
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   672
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   673
    @Test
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   674
    public void testOptionV() {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   675
        test(new String[]{"-v", "--no-startup"},
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   676
                (a) -> assertCommand(a, "1+1",
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   677
                        "$1 ==> 2\n" +
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   678
                        "|  created scratch variable $1 : int")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   679
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   680
    }
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   681
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   682
    @Test
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   683
    public void testOptionFeedback() {
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
   684
        test(Locale.ROOT, false, new String[]{"--feedback", "concise", "--no-startup"}, "",
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   685
                (a) -> assertCommand(a, "1+1", "$1 ==> 2"),
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   686
                (a) -> assertCommand(a, "int x = 5", "")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   687
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   688
    }
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   689
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   690
    @Test
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   691
    public void testCompoundOptions() {
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   692
        Consumer<String> confirmNoStartup = s -> {
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   693
                    assertEquals(0, Stream.of(s.split("\n"))
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   694
                            .filter(l -> !l.isEmpty())
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   695
                            .count(), "Expected no lines: " + s);
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   696
                };
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
   697
        test(Locale.ROOT, false, new String[]{"-nq"}, "",
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   698
                (a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup),
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   699
                (a) -> assertCommand(a, "1+1", "$1 ==> 2"),
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   700
                (a) -> assertCommand(a, "int x = 5", "")
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   701
        );
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
   702
        test(Locale.ROOT, false, new String[]{"-qn"}, "",
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   703
                (a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup),
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   704
                (a) -> assertCommand(a, "1+1", "$1 ==> 2"),
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   705
                (a) -> assertCommand(a, "int x = 5", "")
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   706
        );
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
   707
        test(Locale.ROOT, false, new String[]{"-ns"}, "",
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   708
                (a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup),
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   709
                (a) -> assertCommand(a, "1+1", "")
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   710
        );
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   711
    }
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   712
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   713
    @Test
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   714
    public void testOptionR() {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   715
        test(new String[]{"-R-Dthe.sound=blorp", "--no-startup"},
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   716
                (a) -> assertCommand(a, "System.getProperty(\"the.sound\")",
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   717
                        "$1 ==> \"blorp\"")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   718
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   719
    }
38531
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   720
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   721
    @Test
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   722
    public void testWrapSourceHandlerDiagCrash() {
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   723
        test(new String[]{"--add-exports", "jdk.javadoc/ALL-UNNAMED"},
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   724
                (a) -> assertCommand(a, "1+1", "$1 ==> 2")
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   725
         );
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   726
    }
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   727
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   728
    @Test
38531
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   729
    public void test8156910() {
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   730
        test(
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   731
                (a) -> assertCommandOutputContains(a, "System.out.println(\"%5d\", 10);", "%5d"),
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   732
                (a) -> assertCommandOutputContains(a, "1234", "==> 1234")
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   733
        );
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   734
    }
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   735
}