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