test/langtools/jdk/jshell/ToolSimpleTest.java
author rfield
Mon, 03 Jun 2019 08:21:04 -0700
changeset 55156 1c291d1c272c
parent 53227 f15d443f9731
permissions -rw-r--r--
8199623: JShell: corralling not restored on drop 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
/*
48610
a587f95313f1 8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents: 48349
diff changeset
     2
 * Copyright (c) 2016, 2018, 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
55156
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
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 8177466 8172154 8192979 8191842 8198573 8198801 8210596 8210959 8215099 8199623
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
52938
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents: 52214
diff changeset
    33
 * @run testng/othervm ToolSimpleTest
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    34
 */
52214
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
    35
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
    36
import java.util.ArrayList;
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    37
import java.util.Arrays;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    38
import java.util.List;
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
    39
import java.util.Locale;
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    40
import java.util.function.Consumer;
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
    41
import java.util.regex.Pattern;
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    42
import java.util.stream.Collectors;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    43
import java.util.stream.Stream;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    44
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    45
import org.testng.annotations.Test;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    46
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    47
import static org.testng.Assert.assertEquals;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    48
import static org.testng.Assert.assertTrue;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    49
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    50
public class ToolSimpleTest extends ReplToolTesting {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    51
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
    52
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    53
    public void testRemaining() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    54
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    55
                (a) -> assertCommand(a, "int z; z =", "z ==> 0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    56
                (a) -> assertCommand(a, "5", "z ==> 5"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    57
                (a) -> assertCommand(a, "/*nada*/; int q =", ""),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    58
                (a) -> assertCommand(a, "77", "q ==> 77"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    59
                (a) -> assertCommand(a, "//comment;", ""),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    60
                (a) -> assertCommand(a, "int v;", "v ==> 0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    61
                (a) -> assertCommand(a, "int v; int c",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    62
                        "v ==> 0\n" +
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    63
                        "c ==> 0")
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
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    66
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
    67
    @Test
38835
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    68
    public void testOpenComment() {
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    69
        test(
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    70
                (a) -> assertCommand(a, "int z = /* blah", ""),
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    71
                (a) -> assertCommand(a, "baz */ 5", "z ==> 5"),
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    72
                (a) -> assertCommand(a, "/** hoge ", ""),
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    73
                (a) -> assertCommand(a, "baz **/", ""),
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    74
                (a) -> assertCommand(a, "int v", "v ==> 0")
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
    }
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 38539
diff changeset
    77
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
    78
    @Test
52213
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    79
    public void testSwitchExpression() {
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    80
        test(false, new String[]{"--enable-preview", "--no-startup"},
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    81
                (a) -> assertCommand(a, "enum Day {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY }", "|  created enum Day"),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    82
                (a) -> assertCommand(a, "Day day = Day.FRIDAY;", "day ==> FRIDAY"),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    83
                (a) -> assertCommand(a, "switch (day) {", ""),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    84
                (a) -> assertCommand(a, "case MONDAY, FRIDAY, SUNDAY -> 6;", ""),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    85
                (a) -> assertCommand(a, "case TUESDAY -> 7;", ""),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    86
                (a) -> assertCommand(a, "case THURSDAY, SATURDAY -> 8;", ""),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    87
                (a) -> assertCommand(a, "case WEDNESDAY -> 9;", ""),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    88
                (a) -> assertCommandOutputContains(a, "}", " ==> 6")
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    89
                );
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    90
    }
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    91
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    92
    @Test
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    93
    public void testSwitchExpressionCompletion() {
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    94
        test(false, new String[]{"--enable-preview", "--no-startup"},
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    95
                (a) -> assertCommand(a, "enum Day {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY }", "|  created enum Day"),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    96
                (a) -> assertCommand(a, "Day day = Day.FRIDAY;", "day ==> FRIDAY"),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    97
                (a) -> assertCommand(a, "switch (day) {", ""),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    98
                (a) -> assertCommand(a, "case MONDAY, FRIDAY, SUNDAY -> 6;", ""),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
    99
                (a) -> assertCommand(a, "case TUESDAY -> 7;", ""),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
   100
                (a) -> assertCommand(a, "case THURSDAY, SATURDAY -> 8;", ""),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
   101
                (a) -> assertCommand(a, "case WEDNESDAY -> 9;", ""),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
   102
                (a) -> assertCommand(a, "} +", ""),
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
   103
                (a) -> assertCommandOutputContains(a, "1000", " ==> 1006")
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
   104
                );
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
   105
    }
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
   106
51c0b3936f01 8210923: JShell: support for switch expressions
rfield
parents: 51766
diff changeset
   107
    @Test
43586
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
   108
    public void testLessThan() {
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
   109
        test(
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
   110
                (a) -> assertCommand(a, "45", "$1 ==> 45"),
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
   111
                (a) -> assertCommand(a, "72", "$2 ==> 72"),
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
   112
                (a) -> assertCommand(a, "$1 < $2", "$3 ==> true"),
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
   113
                (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
   114
                        "b ==> 0"),
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
   115
                (a) -> assertCommand(a, "a < b", "$6 ==> false")
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
   116
        );
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
   117
    }
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
   118
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 43274
diff changeset
   119
    @Test
49515
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   120
    public void testChainedThrow() {
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   121
        test(
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   122
                (a) -> assertCommand(a, "void p() throws Exception { ((String) null).toString(); }",
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   123
                        "|  created method p()"),
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   124
                (a) -> assertCommand(a, "void n() throws Exception { try { p(); } catch (Exception ex) { throw new IOException(\"bar\", ex); }}",
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   125
                        "|  created method n()"),
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   126
                (a) -> assertCommand(a, "void m() { try { n(); } catch (Exception ex) { throw new RuntimeException(\"foo\", ex); }}",
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   127
                        "|  created method m()"),
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   128
                (a) -> assertCommand(a, "m()",
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   129
                          "|  Exception java.lang.RuntimeException: foo\n"
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   130
                        + "|        at m (#3:1)\n"
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   131
                        + "|        at (#4:1)\n"
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   132
                        + "|  Caused by: java.io.IOException: bar\n"
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   133
                        + "|        at n (#2:1)\n"
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   134
                        + "|        ...\n"
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   135
                        + "|  Caused by: java.lang.NullPointerException\n"
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   136
                        + "|        at p (#1:1)\n"
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   137
                        + "|        ..."),
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   138
                (a) -> assertCommand(a, "/drop p",
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   139
                        "|  dropped method p()"),
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   140
                (a) -> assertCommand(a, "m()",
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   141
                        "|  attempted to call method n() which cannot be invoked until method p() is declared")
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   142
        );
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   143
    }
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   144
083318155ad1 8198801: JShell: user exception chained cause not retained
rfield
parents: 48940
diff changeset
   145
    @Test
52214
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   146
    public void testThrowWithPercent() {
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   147
        test(
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   148
                (a) -> assertCommandCheckOutput(a,
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   149
                        "URI u = new URI(\"http\", null, \"h\", -1, \"a\" + (char)0x04, null, null);", (s) ->
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   150
                                assertTrue(s.contains("URISyntaxException") && !s.contains("JShellTool"),
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   151
                                        "Output: '" + s + "'")),
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   152
                (a) -> assertCommandCheckOutput(a,
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   153
                        "throw new Exception(\"%z\")", (s) ->
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   154
                                assertTrue(s.contains("java.lang.Exception") && !s.contains("UnknownFormatConversionException"),
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   155
                                        "Output: '" + s + "'"))
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   156
        );
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   157
    }
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   158
b3c7c5a62521 8210959: JShell fails and exits when statement throws an exception whose message contains a '%'.
rfield
parents: 52213
diff changeset
   159
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   160
    public void oneLineOfError() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   161
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   162
                (a) -> assertCommand(a, "12+", null),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   163
                (a) -> assertCommandCheckOutput(a, "  true", (s) ->
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   164
                        assertTrue(s.contains("12+") && !s.contains("true"), "Output: '" + s + "'"))
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   165
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   166
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   167
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   168
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   169
    public void defineVariables() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   170
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   171
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   172
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   173
                (a) -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   174
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   175
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   176
                (a) -> assertVariable(a, "double", "a", "1", "1.0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   177
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   178
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   179
                (a) -> evaluateExpression(a, "double", "2 * a", "2.0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   180
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   181
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   182
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   183
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   184
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   185
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   186
    public void defineMethods() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   187
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   188
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   189
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   190
                (a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   191
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   192
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   193
                (a) -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   194
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   195
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   196
                (a) -> assertMethod(a, "void g() {}", "()void", "g"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   197
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   198
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   199
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   200
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   201
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   202
    @Test
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   203
    public void defineTypes() {
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   204
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   205
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   206
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   207
                (a) -> assertClass(a, "class A { }", "class", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   208
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   209
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   210
                (a) -> assertClass(a, "interface A { }", "interface", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   211
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   212
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   213
                (a) -> assertClass(a, "enum A { }", "enum", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   214
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   215
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   216
                (a) -> assertClass(a, "@interface A { }", "@interface", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   217
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   218
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses())
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   219
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   220
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   221
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   222
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   223
    public void defineImports() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   224
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   225
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   226
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   227
                (a) -> assertImport(a, "import java.util.stream.Stream;", "", "java.util.stream.Stream"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   228
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   229
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   230
                (a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   231
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   232
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   233
                (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
   234
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   235
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   236
                (a) -> assertImport(a, "import static java.lang.Math.*;", "static", "java.lang.Math.*"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   237
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   238
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   239
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   240
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   241
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   242
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   243
    public void defineVar() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   244
        test(
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   245
                (a) -> assertCommand(a, "int x = 72", "x ==> 72"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   246
                (a) -> assertCommand(a, "x", "x ==> 72"),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   247
                (a) -> assertCommand(a, "/vars", "|    int x = 72")
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   248
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   249
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   250
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   251
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   252
    public void defineUnresolvedVar() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   253
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   254
                (a) -> assertCommand(a, "undefined x",
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   255
                        "|  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
   256
                (a) -> assertCommand(a, "/vars", "|    undefined x = (not-active)")
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   257
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   258
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   259
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   260
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   261
    public void testUnresolved() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   262
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   263
                (a) -> assertCommand(a, "int f() { return g() + x + new A().a; }",
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   264
                        "|  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
   265
                (a) -> assertCommand(a, "f()",
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   266
                        "|  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
   267
                (a) -> assertCommandOutputStartsWith(a, "int g() { return x; }",
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   268
                        "|  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
   269
                (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
   270
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   271
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   272
55156
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   273
    // 8199623
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   274
    @Test
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   275
    public void testTwoForkedDrop() {
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   276
        test(
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   277
                (a) -> assertCommand(a, "void p() throws Exception { ((String) null).toString(); }",
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   278
                        "|  created method p()"),
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   279
                (a) -> assertCommand(a, "void n() throws Exception { try { p(); } catch (Exception ex) { throw new IOException(\"bar\", ex); }} ",
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   280
                        "|  created method n()"),
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   281
                (a) -> assertCommand(a, "void m() { try { n(); } catch (Exception ex) { throw new RuntimeException(\"foo\", ex); }}",
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   282
                        "|  created method m()"),
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   283
                (a) -> assertCommand(a, "void c() throws Throwable { p(); }",
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   284
                        "|  created method c()"),
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   285
                (a) -> assertCommand(a, "/drop p",
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   286
                        "|  dropped method p()"),
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   287
                (a) -> assertCommand(a, "m()",
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   288
                        "|  attempted to call method n() which cannot be invoked until method p() is declared"),
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   289
                (a) -> assertCommand(a, "/meth n",
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   290
                        "|    void n()\n" +
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   291
                        "|       which cannot be invoked until method p() is declared"),
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   292
                (a) -> assertCommand(a, "/meth m",
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   293
                        "|    void m()"),
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   294
                (a) -> assertCommand(a, "/meth c",
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   295
                        "|    void c()\n" +
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   296
                                "|       which cannot be invoked until method p() is declared")
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   297
        );
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   298
    }
1c291d1c272c 8199623: JShell: corralling not restored on drop
rfield
parents: 53227
diff changeset
   299
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   300
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   301
    public void testUnknownCommand() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   302
        test((a) -> assertCommand(a, "/unknown",
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   303
                "|  Invalid command: /unknown\n" +
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   304
                "|  Type /help for help."));
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   305
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   306
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   307
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   308
    public void testEmptyClassPath() {
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   309
        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
   310
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   311
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   312
    @Test
43856
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43766
diff changeset
   313
    public void testInvalidClassPath() {
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43766
diff changeset
   314
        test(
43861
825bad9a162a 8174862: JShell tests: new JDK-8174797 testInvalidClassPath fails on Windows
rfield
parents: 43856
diff changeset
   315
                a -> assertCommand(a, "/env --class-path snurgefusal",
48259
c0bf7d8af037 8191636: [Windows] jshell tool: Wrong character in /env class-path command crashes jshell
jlahoda
parents: 47837
diff changeset
   316
                        "|  File 'snurgefusal' for '--class-path' is not found."),
c0bf7d8af037 8191636: [Windows] jshell tool: Wrong character in /env class-path command crashes jshell
jlahoda
parents: 47837
diff changeset
   317
                a -> assertCommand(a, "/env --class-path ?",
c0bf7d8af037 8191636: [Windows] jshell tool: Wrong character in /env class-path command crashes jshell
jlahoda
parents: 47837
diff changeset
   318
                        "|  File '?' for '--class-path' is not found.")
43856
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43766
diff changeset
   319
        );
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43766
diff changeset
   320
    }
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43766
diff changeset
   321
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43766
diff changeset
   322
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   323
    public void testNoArgument() {
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   324
        test(
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   325
                (a) -> assertCommand(a, "/save",
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   326
                        "|  '/save' requires a filename argument."),
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   327
                (a) -> assertCommand(a, "/open",
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   328
                        "|  '/open' requires a filename argument."),
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 41514
diff changeset
   329
                (a) -> assertCommandOutputStartsWith(a, "/drop",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 41514
diff changeset
   330
                        "|  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
   331
        );
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   332
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   333
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   334
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   335
    public void testDebug() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   336
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   337
                (a) -> assertCommand(a, "/deb", "|  Debugging on"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   338
                (a) -> assertCommand(a, "/debug", "|  Debugging off"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   339
                (a) -> assertCommand(a, "/debug", "|  Debugging on"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   340
                (a) -> assertCommand(a, "/deb", "|  Debugging off")
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   341
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   342
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   343
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   344
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   345
    public void testDrop() {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   346
        test(false, new String[]{"--no-startup"},
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   347
                a -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   348
                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
   349
                a -> assertMethod(a, "int b() { return 0; }", "()int", "b"),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   350
                a -> dropMethod(a, "/drop 2", "int b()", "|  dropped method b()"),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   351
                a -> assertClass(a, "class A {}", "class", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   352
                a -> dropClass(a, "/drop 3", "class A", "|  dropped class A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   353
                a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   354
                a -> dropImport(a, "/drop 4", "import java.util.stream.*", ""),
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40601
diff changeset
   355
                a -> assertCommand(a, "for (int i = 0; i < 10; ++i) {}", ""),
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40601
diff changeset
   356
                a -> assertCommand(a, "/drop 5", ""),
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40601
diff changeset
   357
                a -> assertCommand(a, "/list", ""),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   358
                a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   359
                a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   360
                a -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   361
                a -> assertCommandCheckOutput(a, "/imports", assertImports())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   362
        );
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   363
        test(false, new String[]{"--no-startup"},
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   364
                a -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   365
                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
   366
                a -> assertMethod(a, "int b() { return 0; }", "()int", "b"),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   367
                a -> dropMethod(a, "/drop b", "int b()", "|  dropped method b()"),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   368
                a -> assertClass(a, "class A {}", "class", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   369
                a -> dropClass(a, "/drop A", "class A", "|  dropped class A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   370
                a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   371
                a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   372
                a -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   373
                a -> assertCommandCheckOutput(a, "/imports", assertImports())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   374
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   375
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   376
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   377
    @Test
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   378
    public void testDropRange() {
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   379
        test(false, new String[]{"--no-startup"},
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   380
                a -> assertVariable(a, "int", "a"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   381
                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
   382
                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
   383
                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
   384
                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
   385
                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
   386
                        "|  dropped class A\n" +
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   387
                        "|  dropped method b()\n" +
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   388
                        "|  dropped variable a\n"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   389
                a -> assertCommand(a, "/list", "")
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   390
        );
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   391
    }
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   392
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   393
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   394
    public void testDropNegative() {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   395
        test(false, new String[]{"--no-startup"},
48349
3d4e8f5a2a69 8179858: jshell tool: sync nomenclature from reference to online /help
rfield
parents: 48292
diff changeset
   396
                a -> assertCommandOutputStartsWith(a, "/drop 0", "|  No snippet with ID: 0"),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   397
                a -> assertCommandOutputStartsWith(a, "/drop a", "|  No such snippet: a"),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   398
                a -> assertCommandCheckOutput(a, "/drop",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   399
                        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
   400
                a -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   401
                a -> assertCommand(a, "a", "a ==> 0"),
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40601
diff changeset
   402
                a -> assertCommand(a, "/drop 2", ""),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   403
                a -> assertCommand(a, "/drop 2",
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   404
                        "|  This command does not accept the snippet '2' : a\n" +
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   405
                        "|  See /types, /methods, /vars, or /list")
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   406
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   407
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   408
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   409
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   410
    public void testAmbiguousDrop() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   411
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   412
                a -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   413
                a -> assertMethod(a, "int a() { return 0; }", "()int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   414
                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
   415
                a -> assertCommand(a, "/drop a",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   416
                        "|  dropped variable a\n" +
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   417
                        "|  dropped method a()\n" +
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   418
                        "|  dropped class a")
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   419
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   420
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   421
                a -> assertMethod(a, "int a() { return 0; }", "()int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   422
                a -> assertMethod(a, "double a(int a) { return 0; }", "(int)double", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   423
                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
   424
                a -> assertCommand(a, "/drop a",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   425
                        "|  dropped method a()\n" +
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   426
                        "|  dropped method a(int)\n" +
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   427
                        "|  dropped method a(double)\n")
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   428
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   429
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   430
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   431
    @Test
42412
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   432
    public void testApplicationOfPost() {
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   433
        test(
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   434
                (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
   435
                (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
   436
                (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
   437
                (a) -> assertCommand(a, "/set prompt t \"+\" \"-\"", ""),
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   438
                (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
   439
        );
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   440
    }
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   441
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   442
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   443
    public void testHelpLength() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   444
        Consumer<String> testOutput = (s) -> {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   445
            List<String> ss = Stream.of(s.split("\n"))
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   446
                    .filter(l -> !l.isEmpty())
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   447
                    .collect(Collectors.toList());
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   448
            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
   449
        };
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   450
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   451
                (a) -> assertCommandCheckOutput(a, "/?", testOutput),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   452
                (a) -> assertCommandCheckOutput(a, "/help", testOutput),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   453
                (a) -> assertCommandCheckOutput(a, "/help /list", testOutput)
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   454
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   455
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   456
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   457
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   458
    public void testHelp() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   459
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   460
                (a) -> assertHelp(a, "/?", "/list", "/help", "/exit", "intro"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   461
                (a) -> assertHelp(a, "/help", "/list", "/help", "/exit", "intro"),
53058
83840e83476a 8215099: jshell tool: /help representation of ctrl/meta characters inconsistent
rfield
parents: 52938
diff changeset
   462
                (a) -> assertHelp(a, "/help short", "shortcuts", "Tab"),
83840e83476a 8215099: jshell tool: /help representation of ctrl/meta characters inconsistent
rfield
parents: 52938
diff changeset
   463
                (a) -> assertHelp(a, "/help keys", "line", "Shift", "imports", "history"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   464
                (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
   465
                (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
   466
                (a) -> assertHelp(a, "/help /help", "/help <command>"),
74af976d6798 8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents: 43861
diff changeset
   467
                (a) -> assertHelp(a, "/help li", "/list -start"),
74af976d6798 8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents: 43861
diff changeset
   468
                (a) -> assertHelp(a, "/help fe", "/set feedback -retain")
37007
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
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   471
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   472
    @Test
48273
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   473
    public void testHelpStart() {
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   474
        test(
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   475
                (a) -> assertCommandCheckOutput(a, "/help /exit",
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   476
                        s -> assertTrue(s.replaceAll("\\r\\n?", "\n").startsWith(
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   477
                                "|  \n" +
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   478
                                "|                                   /exit\n" +
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   479
                                "|                                   =====\n" +
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   480
                                "|  "
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   481
                        ))
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   482
                )
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   483
        );
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   484
    }
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   485
e2065f7505eb 8192979: jshell tool: Online help text for commands is confusing
rfield
parents: 47837
diff changeset
   486
    @Test
42412
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   487
    public void testHelpFormat() {
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   488
        test(
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   489
                (a) -> assertCommandCheckOutput(a, "/help", s -> {
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   490
                    String[] lines = s.split("\\R");
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   491
                    assertTrue(lines.length > 20,
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   492
                            "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
   493
                          + "\n" + s);
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   494
                    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
   495
                        String l = lines[i];
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   496
                        assertTrue(l.startsWith("| "),
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   497
                                "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
   498
                        assertTrue(l.length() <= 80,
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   499
                                "/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
   500
                    }
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   501
                 })
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   502
        );
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   503
    }
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   504
45602
7aeef976cb06 8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents: 45215
diff changeset
   505
    @Test
7aeef976cb06 8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents: 45215
diff changeset
   506
    public void testConfusedUserPseudoCommands() {
7aeef976cb06 8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents: 45215
diff changeset
   507
        test(
7aeef976cb06 8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents: 45215
diff changeset
   508
                (a) -> assertHelp(a, "/-<n>", "last snippet", "digits"),
7aeef976cb06 8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents: 45215
diff changeset
   509
                (a) -> assertHelp(a, "/<id>", "last snippet", "digits")
7aeef976cb06 8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents: 45215
diff changeset
   510
        );
7aeef976cb06 8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents: 45215
diff changeset
   511
    }
7aeef976cb06 8180510: jshell tool: crash on entering pseudo-commands: /<id> or /-<n>
rfield
parents: 45215
diff changeset
   512
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   513
    private void assertHelp(boolean a, String command, String... find) {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   514
        assertCommandCheckOutput(a, command, s -> {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   515
            for (String f : find) {
42412
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   516
                assertTrue(s.contains(f),
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   517
                        "Expected output of " + command + " to contain: " + f
ca6f4f1914b2 8169828: jdk/jshell/ExternalEditorTest.java testStatementMush() fails frequently on all platform
rfield
parents: 41937
diff changeset
   518
                      + "\n" + s);
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   519
            }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   520
        });
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   521
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   522
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   523
    // 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
   524
    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
   525
        String trimmed = in.trim();
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   526
        String[] res = trimmed.isEmpty()
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   527
                ? new String[0]
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   528
                : trimmed.split("\n");
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   529
        assertEquals(res.length, match.size(), "Got: " + Arrays.asList(res));
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   530
        for (int i = 0; i < match.size(); ++i) {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   531
            assertTrue(res[i].contains(match.get(i)));
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   532
        }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   533
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   534
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   535
    @Test
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   536
    public void testListArgs() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   537
        String arg = "qqqq";
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   538
        List<String> startVarList = new ArrayList<>(START_UP);
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   539
        startVarList.add("int aardvark");
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   540
        startVarList.add("int weevil");
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   541
        test(
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   542
                a -> assertCommandCheckOutput(a, "/list -all",
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   543
                        s -> checkLineToList(s, START_UP)),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   544
                a -> assertCommandOutputStartsWith(a, "/list " + arg,
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   545
                        "|  No such snippet: " + arg),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   546
                a -> assertVariable(a, "int", "aardvark"),
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   547
                a -> assertVariable(a, "int", "weevil"),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   548
                a -> assertCommandOutputContains(a, "/list aardvark", "aardvark"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   549
                a -> assertCommandCheckOutput(a, "/list -start",
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   550
                        s -> checkLineToList(s, START_UP)),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   551
                a -> assertCommandCheckOutput(a, "/list -all",
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   552
                        s -> checkLineToList(s, startVarList)),
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   553
                a -> assertCommandOutputStartsWith(a, "/list s3",
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   554
                        "s3 : import"),
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   555
                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
   556
                        s -> {
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   557
                            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
   558
                                    "No match: " + s);
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   559
                        }),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   560
                a -> assertCommandOutputStartsWith(a, "/list " + arg,
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   561
                        "|  No such snippet: " + arg)
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   562
        );
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   563
    }
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   564
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   565
    @Test
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   566
    public void testVarsArgs() {
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   567
        String arg = "qqqq";
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   568
        List<String> startVarList = new ArrayList<>();
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   569
        test(
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   570
                a -> assertCommandCheckOutput(a, "/vars -all",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   571
                        s -> checkLineToList(s, startVarList)),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   572
                a -> assertCommand(a, "/vars " + arg,
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   573
                        "|  No such snippet: " + arg),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   574
                a -> assertVariable(a, "int", "aardvark"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   575
                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
   576
                a -> assertVariable(a, "int", "a"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   577
                a -> assertVariable(a, "double", "a", "1", "1.0"),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   578
                a -> assertCommandOutputStartsWith(a, "/vars aardvark",
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   579
                        "|    int aardvark = 0"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   580
                a -> assertCommandCheckOutput(a, "/vars -start",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   581
                        s -> checkLineToList(s, startVarList)),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   582
                a -> assertCommandOutputStartsWith(a, "/vars -all",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   583
                        "|    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
   584
                a -> assertCommandOutputStartsWith(a, "/vars 1-4",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44454
diff changeset
   585
                        "|    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
   586
                a -> assertCommandOutputStartsWith(a, "/vars f",
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   587
                        "|  This command does not accept the snippet 'f'"),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   588
                a -> assertCommand(a, "/var " + arg,
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   589
                        "|  No such snippet: " + arg)
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   590
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   591
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   592
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   593
    @Test
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   594
    public void testMethodsArgs() {
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   595
        String arg = "qqqq";
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   596
        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
   597
        test(new String[]{"--startup", "PRINTING"},
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   598
                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
   599
                        s -> checkLineToList(s, printingMethodList)),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   600
                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
   601
                        s -> checkLineToList(s, printingMethodList)),
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   602
                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
   603
                        s -> checkLineToList(s, printingMethodList)),
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   604
                a -> assertCommandCheckOutput(a, "/methods println",
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   605
                        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
   606
                a -> assertCommandCheckOutput(a, "/methods",
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   607
                        s -> checkLineToList(s, printingMethodList)),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   608
                a -> assertCommandOutputStartsWith(a, "/methods " + arg,
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   609
                        "|  No such snippet: " + arg),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   610
                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
   611
                a -> assertVariable(a, "int", "aardvark"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   612
                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
   613
                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
   614
                a -> assertCommandOutputStartsWith(a, "/methods " + arg,
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   615
                        "|  No such snippet: " + arg),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   616
                a -> assertCommandOutputStartsWith(a, "/methods aardvark",
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   617
                        "|  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
   618
                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
   619
                        s -> checkLineToList(s, printingMethodList)),
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   620
                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
   621
                        s -> checkLineToList(s, printingMethodList)),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   622
                a -> assertCommandOutputStartsWith(a, "/methods g",
43759
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   623
                        "|    void g()"),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   624
                a -> assertCommandOutputStartsWith(a, "/methods f",
43759
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   625
                        "|    int f()\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   626
                        "|    void f(int)")
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   627
        );
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   628
    }
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   629
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   630
    @Test
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   631
    public void testMethodsWithErrors() {
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   632
        test(new String[]{"--no-startup"},
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   633
                a -> assertCommand(a, "double m(int x) { return x; }",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   634
                        "|  created method m(int)"),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   635
                a -> assertCommand(a, "GARBAGE junk() { return TRASH; }",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   636
                        "|  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
   637
                a -> assertCommand(a, "int w = 5;",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   638
                        "w ==> 5"),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   639
                a -> assertCommand(a, "int tyer() { return w; }",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   640
                        "|  created method tyer()"),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   641
                a -> assertCommand(a, "String w = \"hi\";",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   642
                        "w ==> \"hi\""),
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   643
                a -> assertCommand(a, "/methods",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   644
                        "|    double m(int)\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   645
                        "|    GARBAGE junk()\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   646
                        "|       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
   647
                        "|    int tyer()\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   648
                        "|       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
   649
                        "|          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
   650
                        "|          int tyer() { return w; }\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   651
                        "|                              ^\n")
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   652
        );
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   653
    }
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   654
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   655
    @Test
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   656
    public void testTypesWithErrors() {
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   657
        test(new String[]{"--no-startup"},
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   658
                a -> assertCommand(a, "class C extends NONE { int x; }",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   659
                        "|  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
   660
                a -> assertCommand(a, "class D { void m() { System.out.println(nada); } }",
43766
498b07dcf851 8174262: Error message misspelling: "instanciated"
rfield
parents: 43759
diff changeset
   661
                        "|  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
   662
                a -> assertCommand(a, "/types",
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   663
                        "|    class C\n" +
61535ac55add 8173916: jshell tool: /methods signature confusing/non-standard format
rfield
parents: 43586
diff changeset
   664
                        "|       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
   665
                        "|    class D\n" +
43766
498b07dcf851 8174262: Error message misspelling: "instanciated"
rfield
parents: 43759
diff changeset
   666
                        "|       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
   667
        );
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   668
    }
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   669
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   670
    @Test
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   671
    public void testTypesArgs() {
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   672
        String arg = "qqqq";
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   673
        List<String> startTypeList = new ArrayList<>();
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   674
        test(
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   675
                a -> assertCommandCheckOutput(a, "/types -all",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   676
                        s -> checkLineToList(s, startTypeList)),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   677
                a -> assertCommandCheckOutput(a, "/types -start",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   678
                        s -> checkLineToList(s, startTypeList)),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   679
                a -> assertCommandOutputStartsWith(a, "/types " + arg,
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   680
                        "|  No such snippet: " + arg),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   681
                a -> assertVariable(a, "int", "aardvark"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   682
                (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
   683
                (a) -> assertClass(a, "interface A { }", "interface", "A"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   684
                a -> assertCommandOutputStartsWith(a, "/types -all",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   685
                        "|    class A\n" +
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   686
                        "|    interface A"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   687
                (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
   688
                (a) -> assertClass(a, "@interface B { }", "@interface", "B"),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   689
                a -> assertCommand(a, "/types aardvark",
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   690
                        "|  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
   691
                a -> assertCommandOutputStartsWith(a, "/types A",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   692
                        "|    interface A"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   693
                a -> assertCommandOutputStartsWith(a, "/types E",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   694
                        "|    enum E"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   695
                a -> assertCommandOutputStartsWith(a, "/types B",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   696
                        "|    @interface B"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   697
                a -> assertCommandOutputStartsWith(a, "/types " + arg,
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   698
                        "|  No such snippet: " + arg),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   699
                a -> assertCommandCheckOutput(a, "/types -start",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   700
                        s -> checkLineToList(s, startTypeList))
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   701
        );
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   702
    }
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   703
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   704
    @Test
43274
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   705
    public void testBlankLinesInSnippetContinuation() {
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   706
        test(Locale.ROOT, false, new String[]{"--no-startup"}, "",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   707
                a -> assertCommand(a, "class C {",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   708
                        ""),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   709
                a -> assertCommand(a, "",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   710
                        ""),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   711
                a -> assertCommand(a, "",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   712
                        ""),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   713
                a -> assertCommand(a, "  int x;",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   714
                        ""),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   715
                a -> assertCommand(a, "",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   716
                        ""),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   717
                a -> assertCommand(a, "",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   718
                        ""),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   719
                a -> assertCommand(a, "}",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   720
                        "|  created class C"),
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   721
                a -> assertCommand(a, "/list",
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   722
                        "\n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   723
                        "   1 : class C {\n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   724
                        "       \n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   725
                        "       \n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   726
                        "         int x;\n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   727
                        "       \n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   728
                        "       \n" +
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   729
                        "       }")
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   730
        );
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   731
    }
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   732
6b5ed4f9fb81 8173073: jshell tool: blank lines removed from multi-line snippets
rfield
parents: 43038
diff changeset
   733
    @Test
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   734
    public void testCompoundStart() {
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   735
        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
   736
                (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
   737
                        "", "", null, "3.14", "")
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   738
        );
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   739
    }
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   740
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   741
    @Test
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   742
    public void testJavaSeStart() {
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   743
        test(new String[]{"--startup", "JAVASE"},
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   744
                (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
   745
                        "$1 ==> WALL")
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   746
        );
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   747
    }
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   748
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42969
diff changeset
   749
    @Test
47837
ef7aad81c3d6 8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents: 47268
diff changeset
   750
    public void testJavaSeSetStart() {
ef7aad81c3d6 8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents: 47268
diff changeset
   751
        test(
ef7aad81c3d6 8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents: 47268
diff changeset
   752
                (a) -> assertCommand(a, "/set sta JAVASE", ""),
ef7aad81c3d6 8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents: 47268
diff changeset
   753
                (a) -> assertCommand(a, "/reset", "|  Resetting state."),
ef7aad81c3d6 8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents: 47268
diff changeset
   754
                (a) -> assertCommandCheckOutput(a, "/li -a",
ef7aad81c3d6 8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents: 47268
diff changeset
   755
                            s -> assertTrue(s.split("import ").length > 160,
ef7aad81c3d6 8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents: 47268
diff changeset
   756
                            "not enough imports for JAVASE:\n" + s))
ef7aad81c3d6 8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents: 47268
diff changeset
   757
        );
ef7aad81c3d6 8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents: 47268
diff changeset
   758
    }
ef7aad81c3d6 8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents: 47268
diff changeset
   759
ef7aad81c3d6 8172154: jshell tool: make all IMPORTS.jsh generated at build time
rfield
parents: 47268
diff changeset
   760
    @Test
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   761
    public void defineClasses() {
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   762
        test(
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   763
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   764
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   765
                (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
   766
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   767
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   768
                (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
   769
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   770
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   771
                (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
   772
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   773
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   774
                (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
   775
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   776
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses())
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   777
        );
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   778
    }
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   779
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   780
    @Test
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   781
    public void testCommandPrefix() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   782
        test(a -> assertCommandCheckOutput(a, "/s",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   783
                      assertStartsWith("|  Command: '/s' is ambiguous: /save, /set")),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   784
             a -> assertCommand(a, "int var", "var ==> 0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   785
             a -> assertCommandCheckOutput(a, "/va",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   786
                      assertStartsWith("|    int var = 0")),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   787
             a -> assertCommandCheckOutput(a, "/save",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   788
                      assertStartsWith("|  '/save' requires a filename argument.")));
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   789
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   790
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   791
    @Test
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   792
    public void testOptionQ() {
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
   793
        test(Locale.ROOT, false, new String[]{"-q", "--no-startup"}, "",
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   794
                (a) -> assertCommand(a, "1+1", "$1 ==> 2"),
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   795
                (a) -> assertCommand(a, "int x = 5", "")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   796
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   797
    }
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   798
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   799
    @Test
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   800
    public void testOptionS() {
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
   801
        test(Locale.ROOT, false, new String[]{"-s", "--no-startup"}, "",
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   802
                (a) -> assertCommand(a, "1+1", "")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   803
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   804
    }
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   805
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   806
    @Test
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   807
    public void testOptionV() {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   808
        test(new String[]{"-v", "--no-startup"},
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   809
                (a) -> assertCommand(a, "1+1",
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   810
                        "$1 ==> 2\n" +
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   811
                        "|  created scratch variable $1 : int")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   812
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   813
    }
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   814
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   815
    @Test
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   816
    public void testOptionFeedback() {
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
   817
        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
   818
                (a) -> assertCommand(a, "1+1", "$1 ==> 2"),
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   819
                (a) -> assertCommand(a, "int x = 5", "")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   820
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   821
    }
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   822
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   823
    @Test
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   824
    public void testCompoundOptions() {
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   825
        Consumer<String> confirmNoStartup = s -> {
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   826
                    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
   827
                            .filter(l -> !l.isEmpty())
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   828
                            .count(), "Expected no lines: " + s);
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   829
                };
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
   830
        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
   831
                (a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup),
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   832
                (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
   833
                (a) -> assertCommand(a, "int x = 5", "")
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   834
        );
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
   835
        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
   836
                (a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup),
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   837
                (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
   838
                (a) -> assertCommand(a, "int x = 5", "")
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   839
        );
41937
1313399705e9 8161969: jshell tool: /var value is not truncated per feedback setting
rfield
parents: 41635
diff changeset
   840
        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
   841
                (a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup),
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   842
                (a) -> assertCommand(a, "1+1", "")
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   843
        );
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   844
    }
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   845
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   846
    @Test
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   847
    public void testOptionR() {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38835
diff changeset
   848
        test(new String[]{"-R-Dthe.sound=blorp", "--no-startup"},
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   849
                (a) -> assertCommand(a, "System.getProperty(\"the.sound\")",
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   850
                        "$1 ==> \"blorp\"")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   851
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   852
    }
38531
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   853
42969
a48d4f74d322 8168615: JShell API: jdk.jshell.spi should be a pluggable ServiceLoader SPI
rfield
parents: 42412
diff changeset
   854
    @Test
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   855
    public void testWrapSourceHandlerDiagCrash() {
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   856
        test(new String[]{"--add-exports", "jdk.javadoc/ALL-UNNAMED"},
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   857
                (a) -> assertCommand(a, "1+1", "$1 ==> 2")
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   858
         );
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   859
    }
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   860
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   861
    @Test
38531
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   862
    public void test8156910() {
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   863
        test(
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   864
                (a) -> assertCommandOutputContains(a, "System.out.println(\"%5d\", 10);", "%5d"),
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   865
                (a) -> assertCommandOutputContains(a, "1234", "==> 1234")
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   866
        );
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   867
    }
47268
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   868
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   869
    @Test
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   870
    public void testIntersection() {
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   871
        test(
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   872
                (a) -> assertCommandOutputContains(a, "<Z extends Runnable&CharSequence> Z get1() { return null; }", "get1()"),
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   873
                (a) -> assertCommandOutputContains(a, "var g1 = get1()", "g1"),
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   874
                (a) -> assertCommand(a, "/vars g1", "|    CharSequence&Runnable g1 = null"),
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   875
                (a) -> assertCommandOutputContains(a, "<Z extends Number&CharSequence> Z get2() { return null; }", "get2()"),
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   876
                (a) -> assertCommandOutputContains(a, "var g2 = get2()", "g2"),
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   877
                (a) -> assertCommand(a, "/vars g2", "|    Number&CharSequence g2 = null")
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   878
        );
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   879
    }
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   880
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   881
    @Test
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   882
    public void testAnonymous() {
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   883
        test(
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   884
                (a) -> assertCommandOutputContains(a, "var r1 = new Object() {}", "r1"),
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   885
                (a) -> assertCommandOutputContains(a, "/vars r1", "|    <anonymous class extending Object> r1 = "),
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   886
                (a) -> assertCommandOutputContains(a, "var r2 = new Runnable() { public void run() { } }", "r2"),
48610
a587f95313f1 8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents: 48349
diff changeset
   887
                (a) -> assertCommandOutputContains(a, "/vars r2", "|    <anonymous class implementing Runnable> r2 = "),
a587f95313f1 8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents: 48349
diff changeset
   888
                (a) -> assertCommandOutputContains(a, "import java.util.stream.*;", ""),
a587f95313f1 8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents: 48349
diff changeset
   889
                (a) -> assertCommandOutputContains(a, "var list = Stream.of(1, 2, 3).map(j -> new Object() { int i = j; }).collect(Collectors.toList());",
a587f95313f1 8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents: 48349
diff changeset
   890
                                                      "list"),
a587f95313f1 8191842: JShell: Inferred type information is lost when assigning types to a \"var\"
jlahoda
parents: 48349
diff changeset
   891
                (a) -> assertCommandOutputContains(a, "/vars list", "|    List<<anonymous class extending Object>> list = ")
47268
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   892
        );
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   893
    }
48940
ca22f8cb0c9b 8198573: JShell: class replace loses instances
rfield
parents: 48610
diff changeset
   894
ca22f8cb0c9b 8198573: JShell: class replace loses instances
rfield
parents: 48610
diff changeset
   895
    // This is mainly interesting in the TestLocalSimpleTest case (8198573)
ca22f8cb0c9b 8198573: JShell: class replace loses instances
rfield
parents: 48610
diff changeset
   896
    @Test
ca22f8cb0c9b 8198573: JShell: class replace loses instances
rfield
parents: 48610
diff changeset
   897
    public void testUpdateFalsePositive() {
ca22f8cb0c9b 8198573: JShell: class replace loses instances
rfield
parents: 48610
diff changeset
   898
        test(
ca22f8cb0c9b 8198573: JShell: class replace loses instances
rfield
parents: 48610
diff changeset
   899
                a -> assertClass(a, "class A { int a() { int error = 0; return error; } }", "class", "A"),
ca22f8cb0c9b 8198573: JShell: class replace loses instances
rfield
parents: 48610
diff changeset
   900
                a -> assertVariable(a, "A", "a", "new A()", "A@.+"),
ca22f8cb0c9b 8198573: JShell: class replace loses instances
rfield
parents: 48610
diff changeset
   901
                a -> assertVariable(a, "int", "error", "4711", "4711"),
ca22f8cb0c9b 8198573: JShell: class replace loses instances
rfield
parents: 48610
diff changeset
   902
                a -> assertCommandOutputContains(a, "a", "A@")
ca22f8cb0c9b 8198573: JShell: class replace loses instances
rfield
parents: 48610
diff changeset
   903
        );
ca22f8cb0c9b 8198573: JShell: class replace loses instances
rfield
parents: 48610
diff changeset
   904
    }
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   905
}