langtools/test/jdk/jshell/ToolSimpleTest.java
author rfield
Wed, 18 May 2016 11:35:10 -0700
changeset 38520 17e72b872ffd
parent 38514 f7df9ab653b0
child 38531 c449daa25b45
permissions -rw-r--r--
8157185: jshell tool: ambiguous format -- distinguished arguments should be options Reviewed-by: vromero
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
/*
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
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
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
    26
 * @bug 8153716 8143955 8151754 8150382 8153920
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    27
 * @summary Simple jshell tool tests
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.api
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    29
 *          jdk.compiler/com.sun.tools.javac.main
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    30
 *          jdk.jdeps/com.sun.tools.javap
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    31
 *          jdk.jshell/jdk.internal.jshell.tool
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    32
 * @build KullaTesting TestingInputStream
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    33
 * @run testng ToolSimpleTest
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    34
 */
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    35
import java.util.Arrays;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    36
import java.util.ArrayList;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    37
import java.util.List;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    38
import java.util.function.Consumer;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    39
import java.util.stream.Collectors;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    40
import java.util.stream.Stream;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    41
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    42
import org.testng.annotations.Test;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    43
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    44
import static org.testng.Assert.assertEquals;
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    45
import static org.testng.Assert.assertTrue;
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
@Test
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    48
public class ToolSimpleTest extends ReplToolTesting {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
    49
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    50
    public void testRemaining() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    51
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    52
                (a) -> assertCommand(a, "int z; z =", "z ==> 0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    53
                (a) -> assertCommand(a, "5", "z ==> 5"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    54
                (a) -> assertCommand(a, "/*nada*/; int q =", ""),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    55
                (a) -> assertCommand(a, "77", "q ==> 77"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    56
                (a) -> assertCommand(a, "//comment;", ""),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    57
                (a) -> assertCommand(a, "int v;", "v ==> 0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    58
                (a) -> assertCommand(a, "int v; int c",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    59
                        "v ==> 0\n" +
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    60
                        "c ==> 0")
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    61
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    62
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    63
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    64
    public void oneLineOfError() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    65
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    66
                (a) -> assertCommand(a, "12+", null),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    67
                (a) -> assertCommandCheckOutput(a, "  true", (s) ->
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    68
                        assertTrue(s.contains("12+") && !s.contains("true"), "Output: '" + s + "'"))
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    69
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    70
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    71
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    72
    public void defineVariables() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    73
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    74
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    75
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    76
                (a) -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    77
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    78
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    79
                (a) -> assertVariable(a, "double", "a", "1", "1.0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    80
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    81
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    82
                (a) -> evaluateExpression(a, "double", "2 * a", "2.0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    83
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    84
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    85
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    86
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    87
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    88
    public void defineMethods() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    89
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    90
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    91
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    92
                (a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    93
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    94
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    95
                (a) -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    96
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    97
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    98
                (a) -> assertMethod(a, "void g() {}", "()void", "g"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    99
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   100
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   101
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   102
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   103
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   104
    public void defineTypes() {
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   105
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   106
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   107
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   108
                (a) -> assertClass(a, "class A { }", "class", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   109
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   110
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   111
                (a) -> assertClass(a, "interface A { }", "interface", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   112
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   113
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   114
                (a) -> assertClass(a, "enum A { }", "enum", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   115
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   116
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   117
                (a) -> assertClass(a, "@interface A { }", "@interface", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   118
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   119
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses())
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   120
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   121
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   122
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   123
    public void defineImports() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   124
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   125
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   126
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   127
                (a) -> assertImport(a, "import java.util.stream.Stream;", "", "java.util.stream.Stream"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   128
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   129
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   130
                (a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   131
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   132
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   133
                (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
   134
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   135
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   136
                (a) -> assertImport(a, "import static java.lang.Math.*;", "static", "java.lang.Math.*"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   137
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   138
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   139
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   140
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   141
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   142
    public void defineVar() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   143
        test(
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   144
                (a) -> assertCommand(a, "int x = 72", "x ==> 72"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   145
                (a) -> assertCommand(a, "x", "x ==> 72"),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   146
                (a) -> assertCommand(a, "/vars", "|    int x = 72")
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   147
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   148
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   149
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   150
    @Test(enabled = false) // TODO 8153897
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   151
    public void defineUnresolvedVar() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   152
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   153
                (a) -> assertCommand(a, "undefined x",
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   154
                        "|  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
   155
                (a) -> assertCommand(a, "/vars", "|    undefined x = (not-active)")
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   156
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   157
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   158
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   159
    public void testUnresolved() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   160
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   161
                (a) -> assertCommand(a, "int f() { return g() + x + new A().a; }",
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   162
                        "|  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
   163
                (a) -> assertCommand(a, "f()",
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   164
                        "|  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
   165
                (a) -> assertCommandOutputStartsWith(a, "int g() { return x; }",
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   166
                        "|  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
   167
                (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
   168
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   169
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   170
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   171
    public void testUnknownCommand() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   172
        test((a) -> assertCommand(a, "/unknown",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   173
                "|  No such command or snippet id: /unknown\n" +
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   174
                "|  Type /help for help."));
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   175
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   176
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   177
    public void testEmptyClassPath() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   178
        test(after -> assertCommand(after, "/classpath", "|  The /classpath command requires a path argument."));
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   179
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   180
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   181
    public void testNoArgument() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   182
        String[] commands = {"/save", "/open", "/set start"};
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   183
        test(Stream.of(commands)
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   184
                .map(cmd -> {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   185
                    String c = cmd;
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   186
                    final String finalC = c;
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   187
                    return (ReplTest) after -> assertCommand(after, cmd,
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   188
                            "|  '" + finalC + "' requires a filename argument.");
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   189
                })
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   190
                .toArray(ReplTest[]::new));
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   191
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   192
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   193
    public void testDebug() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   194
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   195
                (a) -> assertCommand(a, "/deb", "|  Debugging on"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   196
                (a) -> assertCommand(a, "/debug", "|  Debugging off"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   197
                (a) -> assertCommand(a, "/debug", "|  Debugging on"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   198
                (a) -> assertCommand(a, "/deb", "|  Debugging off")
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   199
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   200
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   201
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   202
    public void testDrop() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   203
        test(false, new String[]{"-nostartup"},
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   204
                a -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   205
                a -> dropVariable(a, "/drop 1", "int a = 0", "|  dropped variable a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   206
                a -> assertMethod(a, "int b() { return 0; }", "()I", "b"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   207
                a -> dropMethod(a, "/drop 2", "b ()I", "|  dropped method b()"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   208
                a -> assertClass(a, "class A {}", "class", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   209
                a -> dropClass(a, "/drop 3", "class A", "|  dropped class A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   210
                a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   211
                a -> dropImport(a, "/drop 4", "import java.util.stream.*", ""),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   212
                a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   213
                a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   214
                a -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   215
                a -> assertCommandCheckOutput(a, "/imports", assertImports())
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
        test(false, new String[]{"-nostartup"},
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   218
                a -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   219
                a -> dropVariable(a, "/drop a", "int a = 0", "|  dropped variable a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   220
                a -> assertMethod(a, "int b() { return 0; }", "()I", "b"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   221
                a -> dropMethod(a, "/drop b", "b ()I", "|  dropped method b()"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   222
                a -> assertClass(a, "class A {}", "class", "A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   223
                a -> dropClass(a, "/drop A", "class A", "|  dropped class A"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   224
                a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   225
                a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   226
                a -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   227
                a -> assertCommandCheckOutput(a, "/imports", assertImports())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   228
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   229
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   230
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   231
    public void testDropNegative() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   232
        test(false, new String[]{"-nostartup"},
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   233
                a -> assertCommandOutputStartsWith(a, "/drop 0", "|  No applicable definition or id found named: 0"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   234
                a -> assertCommandOutputStartsWith(a, "/drop a", "|  No applicable definition or id found named: a"),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   235
                a -> assertCommandCheckOutput(a, "/drop",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   236
                        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
   237
                a -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   238
                a -> assertCommand(a, "a", "a ==> 0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   239
                a -> assertCommand(a, "/drop 2", "|  The argument did not specify an active import, variable, method, or class to drop.")
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   240
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   241
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   242
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   243
    public void testAmbiguousDrop() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   244
        Consumer<String> check = s -> {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   245
            assertTrue(s.startsWith("|  The argument references more than one import, variable, method, or class"), s);
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   246
            int lines = s.split("\n").length;
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   247
            assertEquals(lines, 5, "Expected 3 ambiguous keys, but found: " + (lines - 2) + "\n" + s);
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   248
        };
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   249
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   250
                a -> assertVariable(a, "int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   251
                a -> assertMethod(a, "int a() { return 0; }", "()int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   252
                a -> assertClass(a, "class a {}", "class", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   253
                a -> assertCommandCheckOutput(a, "/drop a", check),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   254
                a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   255
                a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   256
                a -> assertCommandCheckOutput(a, "/types", assertClasses()),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   257
                a -> assertCommandCheckOutput(a, "/imports", assertImports())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   258
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   259
        test(
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   260
                a -> assertMethod(a, "int a() { return 0; }", "()int", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   261
                a -> assertMethod(a, "double a(int a) { return 0; }", "(int)double", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   262
                a -> assertMethod(a, "double a(double a) { return 0; }", "(double)double", "a"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   263
                a -> assertCommandCheckOutput(a, "/drop a", check),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   264
                a -> assertCommandCheckOutput(a, "/methods", assertMethods())
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   265
        );
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   266
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   267
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   268
    public void testHelpLength() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   269
        Consumer<String> testOutput = (s) -> {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   270
            List<String> ss = Stream.of(s.split("\n"))
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   271
                    .filter(l -> !l.isEmpty())
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   272
                    .collect(Collectors.toList());
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   273
            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
   274
        };
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   275
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   276
                (a) -> assertCommandCheckOutput(a, "/?", testOutput),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   277
                (a) -> assertCommandCheckOutput(a, "/help", testOutput),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   278
                (a) -> assertCommandCheckOutput(a, "/help /list", testOutput)
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   279
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   280
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   281
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   282
    public void testHelp() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   283
        test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   284
                (a) -> assertHelp(a, "/?", "/list", "/help", "/exit", "intro"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   285
                (a) -> assertHelp(a, "/help", "/list", "/help", "/exit", "intro"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   286
                (a) -> assertHelp(a, "/help short", "shortcuts", "<tab>"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   287
                (a) -> assertHelp(a, "/? /li", "/list -all", "snippets"),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   288
                (a) -> assertHelp(a, "/help /help", "/help <command>")
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   289
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   290
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   291
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   292
    private void assertHelp(boolean a, String command, String... find) {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   293
        assertCommandCheckOutput(a, command, s -> {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   294
            for (String f : find) {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   295
                assertTrue(s.contains(f), "Expected output of " + command + " to contain: " + f);
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   296
            }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   297
        });
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   298
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   299
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   300
    // 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
   301
    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
   302
        String trimmed = in.trim();
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   303
        String[] res = trimmed.isEmpty()
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   304
                ? new String[0]
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   305
                : trimmed.split("\n");
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   306
        assertEquals(res.length, match.size(), "Got: " + Arrays.asList(res));
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   307
        for (int i = 0; i < match.size(); ++i) {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   308
            assertTrue(res[i].contains(match.get(i)));
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   309
        }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   310
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   311
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   312
    public void testListArgs() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   313
        String arg = "qqqq";
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   314
        List<String> startVarList = new ArrayList<>(START_UP);
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   315
        startVarList.add("int aardvark");
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   316
        test(
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   317
                a -> assertCommandCheckOutput(a, "/list -all",
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   318
                        s -> checkLineToList(s, START_UP)),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   319
                a -> assertCommandOutputStartsWith(a, "/list " + arg,
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   320
                        "|  No applicable definition or id found named: " + arg),
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   321
                a -> assertVariable(a, "int", "aardvark"),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   322
                a -> assertCommandOutputContains(a, "/list aardvark", "aardvark"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   323
                a -> assertCommandCheckOutput(a, "/list -start",
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   324
                        s -> checkLineToList(s, START_UP)),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   325
                a -> assertCommandCheckOutput(a, "/list -all",
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   326
                        s -> checkLineToList(s, startVarList)),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   327
                a -> assertCommandCheckOutput(a, "/list printf",
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   328
                        s -> assertTrue(s.contains("void printf"))),
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   329
                a -> assertCommandOutputStartsWith(a, "/list " + arg,
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   330
                        "|  No applicable definition or id found named: " + arg)
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   331
        );
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   332
    }
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   333
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   334
    public void testVarsArgs() {
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   335
        String arg = "qqqq";
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   336
        List<String> startVarList = new ArrayList<>();
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   337
        test(
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   338
                a -> assertCommandCheckOutput(a, "/vars -all",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   339
                        s -> checkLineToList(s, startVarList)),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   340
                a -> assertCommandOutputStartsWith(a, "/vars " + arg,
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   341
                        "|  No applicable definition or id found named: " + arg),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   342
                a -> assertVariable(a, "int", "aardvark"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   343
                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
   344
                a -> assertVariable(a, "int", "a"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   345
                a -> assertVariable(a, "double", "a", "1", "1.0"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   346
                a -> assertCommandOutputStartsWith(a, "/vars aardvark", "|    int aardvark = 0"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   347
                a -> assertCommandCheckOutput(a, "/vars -start",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   348
                        s -> checkLineToList(s, startVarList)),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   349
                a -> assertCommandOutputStartsWith(a, "/vars -all",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   350
                        "|    int aardvark = 0\n|    int a = "),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   351
                a -> assertCommandOutputStartsWith(a, "/vars printf",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   352
                        "|  No applicable definition or id found named: printf"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   353
                a -> assertCommandOutputStartsWith(a, "/vars " + arg,
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   354
                        "|  No applicable definition or id found named: " + arg)
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   355
        );
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   356
    }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   357
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   358
    public void testMethodsArgs() {
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   359
        String arg = "qqqq";
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   360
        List<String> startMethodList = new ArrayList<>(START_UP_CMD_METHOD);
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   361
        test(
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   362
                a -> assertCommandCheckOutput(a, "/methods -all",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   363
                        s -> checkLineToList(s, startMethodList)),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   364
                a -> assertCommandCheckOutput(a, "/methods -start",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   365
                        s -> checkLineToList(s, startMethodList)),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   366
                a -> assertCommandCheckOutput(a, "/methods printf",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   367
                        s -> checkLineToList(s, startMethodList)),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   368
                a -> assertCommandCheckOutput(a, "/methods",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   369
                        s -> checkLineToList(s, startMethodList)),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   370
                a -> assertCommandOutputStartsWith(a, "/methods " + arg,
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   371
                        "|  No applicable definition or id found named: " + arg),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   372
                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
   373
                a -> assertVariable(a, "int", "aardvark"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   374
                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
   375
                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
   376
                a -> assertCommandOutputStartsWith(a, "/methods " + arg,
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   377
                        "|  No applicable definition or id found named: " + arg),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   378
                a -> assertCommandOutputStartsWith(a, "/methods aardvark",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   379
                        "|  No applicable definition or id found named: aardvark"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   380
                a -> assertCommandCheckOutput(a, "/methods -start",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   381
                        s -> checkLineToList(s, startMethodList)),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   382
                a -> assertCommandCheckOutput(a, "/methods printf",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   383
                        s -> checkLineToList(s, startMethodList)),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   384
                a -> assertCommandOutputStartsWith(a, "/methods g",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   385
                        "|    g ()void"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   386
                a -> assertCommandOutputStartsWith(a, "/methods f",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   387
                        "|    f ()int\n" +
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   388
                        "|    f (int)void")
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   389
        );
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   390
    }
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   391
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   392
    public void testTypesArgs() {
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   393
        String arg = "qqqq";
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   394
        List<String> startTypeList = new ArrayList<>();
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   395
        test(
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   396
                a -> assertCommandCheckOutput(a, "/types -all",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   397
                        s -> checkLineToList(s, startTypeList)),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   398
                a -> assertCommandCheckOutput(a, "/types -start",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   399
                        s -> checkLineToList(s, startTypeList)),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   400
                a -> assertCommandOutputStartsWith(a, "/types " + arg,
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   401
                        "|  No applicable definition or id found named: " + arg),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   402
                a -> assertVariable(a, "int", "aardvark"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   403
                (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
   404
                (a) -> assertClass(a, "interface A { }", "interface", "A"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   405
                a -> assertCommandOutputStartsWith(a, "/types -all",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   406
                        "|    class A\n" +
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   407
                        "|    interface A"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   408
                (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
   409
                (a) -> assertClass(a, "@interface B { }", "@interface", "B"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   410
                a -> assertCommandOutputStartsWith(a, "/types aardvark",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   411
                        "|  No applicable definition or id found named: aardvark"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   412
                a -> assertCommandOutputStartsWith(a, "/types A",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   413
                        "|    interface A"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   414
                a -> assertCommandOutputStartsWith(a, "/types E",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   415
                        "|    enum E"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   416
                a -> assertCommandOutputStartsWith(a, "/types B",
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   417
                        "|    @interface B"),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   418
                a -> assertCommandOutputStartsWith(a, "/types " + arg,
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   419
                        "|  No applicable definition or id found named: " + arg),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   420
                a -> assertCommandCheckOutput(a, "/types -start",
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   421
                        s -> checkLineToList(s, startTypeList))
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   422
        );
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   423
    }
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   424
    public void defineClasses() {
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   425
        test(
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   426
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   427
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   428
                (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
   429
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   430
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   431
                (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
   432
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   433
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   434
                (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
   435
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   436
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   437
                (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
   438
                (a) -> assertCommandCheckOutput(a, "/list", assertList()),
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   439
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses())
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   440
        );
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37745
diff changeset
   441
    }
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   442
    public void testCommandPrefix() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   443
        test(a -> assertCommandCheckOutput(a, "/s",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   444
                      assertStartsWith("|  Command: '/s' is ambiguous: /save, /set")),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   445
             a -> assertCommand(a, "int var", "var ==> 0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   446
             a -> assertCommandCheckOutput(a, "/va",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   447
                      assertStartsWith("|    int var = 0")),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   448
             a -> assertCommandCheckOutput(a, "/save",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   449
                      assertStartsWith("|  '/save' requires a filename argument.")));
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   450
    }
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   451
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   452
    public void testHeadlessEditPad() {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   453
        String prevHeadless = System.getProperty("java.awt.headless");
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   454
        try {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   455
            System.setProperty("java.awt.headless", "true");
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   456
            test(
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   457
                (a) -> assertCommandOutputStartsWith(a, "/edit printf", "|  Cannot launch editor -- unexpected exception:")
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
        } finally {
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   460
            System.setProperty("java.awt.headless", prevHeadless==null? "false" : prevHeadless);
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   461
        }
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   462
    }
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   463
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   464
    public void testOptionQ() {
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   465
        test(new String[]{"-q", "-nostartup"},
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   466
                (a) -> assertCommand(a, "1+1", "$1 ==> 2"),
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   467
                (a) -> assertCommand(a, "int x = 5", "")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   468
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   469
    }
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   470
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   471
    public void testOptionQq() {
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   472
        test(new String[]{"-qq", "-nostartup"},
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   473
                (a) -> assertCommand(a, "1+1", "")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   474
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   475
    }
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   476
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   477
    public void testOptionV() {
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   478
        test(new String[]{"-v", "-nostartup"},
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   479
                (a) -> assertCommand(a, "1+1",
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   480
                        "$1 ==> 2\n" +
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   481
                        "|  created scratch variable $1 : int")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   482
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   483
    }
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   484
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   485
    public void testOptionFeedback() {
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   486
        test(new String[]{"-feedback", "concise", "-nostartup"},
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   487
                (a) -> assertCommand(a, "1+1", "$1 ==> 2"),
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   488
                (a) -> assertCommand(a, "int x = 5", "")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   489
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   490
    }
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   491
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   492
    public void testOptionR() {
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   493
        test(new String[]{"-R-Dthe.sound=blorp", "-nostartup"},
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   494
                (a) -> assertCommand(a, "System.getProperty(\"the.sound\")",
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   495
                        "$1 ==> \"blorp\"")
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   496
        );
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 37389
diff changeset
   497
    }
37007
6023a9a9d58a 8153716: JShell tool: should warn when failed to launch editor
rfield
parents:
diff changeset
   498
}