test/langtools/jdk/jshell/ToolTabCommandTest.java
author jlahoda
Thu, 02 Nov 2017 10:09:34 +0100
changeset 47484 d0cb66d8cbf1
parent 47216 71c04702a3d5
child 47840 e0f08a49f3e3
permissions -rw-r--r--
8189595: jshell tool: line redrawn on each completion Reviewed-by: rfield
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     1
/*
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     4
 *
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     8
 *
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    14
 *
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    18
 *
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    21
 * questions.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    22
 */
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    23
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    24
/**
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    25
 * @test
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    26
 * @bug 8177076
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    27
 * @modules
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    28
 *     jdk.compiler/com.sun.tools.javac.api
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    29
 *     jdk.compiler/com.sun.tools.javac.main
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    30
 *     jdk.jshell/jdk.internal.jshell.tool.resources:open
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    31
 *     jdk.jshell/jdk.jshell:open
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    32
 * @library /tools/lib
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    33
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
44570
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents: 44459
diff changeset
    34
 * @build Compiler UITesting
46185
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 45501
diff changeset
    35
 * @build ToolTabCommandTest
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 45501
diff changeset
    36
 * @run testng ToolTabCommandTest
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    37
 */
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    38
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    39
import java.util.regex.Pattern;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    40
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    41
import org.testng.annotations.Test;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    42
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    43
@Test
46185
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 45501
diff changeset
    44
public class ToolTabCommandTest extends UITesting {
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    45
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    46
    public void testCommand() throws Exception {
45501
a13e5e2ee35e 8180306: jshell tool: /help -- confusing identifier in feedback mode examples
rfield
parents: 45215
diff changeset
    47
        // set terminal height so that help output won't hit page breaks
a13e5e2ee35e 8180306: jshell tool: /help -- confusing identifier in feedback mode examples
rfield
parents: 45215
diff changeset
    48
        System.setProperty("test.terminal.height", "1000000");
a13e5e2ee35e 8180306: jshell tool: /help -- confusing identifier in feedback mode examples
rfield
parents: 45215
diff changeset
    49
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    50
        doRunTest((inputSink, out) -> {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    51
            inputSink.write("1\n");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    52
            waitOutput(out, "\u0005");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    53
            inputSink.write("/\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    54
            waitOutput(out, ".*/edit.*/list.*\n\n" + Pattern.quote(getResource("jshell.console.see.synopsis")) + "\n\r\u0005/");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    55
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    56
            waitOutput(out,   ".*\n/edit\n" + Pattern.quote(getResource("help.edit.summary")) +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    57
                            "\n.*\n/list\n" + Pattern.quote(getResource("help.list.summary")) +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    58
                            ".*\n\n" + Pattern.quote(getResource("jshell.console.see.full.documentation")) + "\n\r\u0005/");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    59
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    60
            waitOutput(out,  "/!\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    61
                            Pattern.quote(getResource("help.bang")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    62
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    63
                            Pattern.quote(getResource("jshell.console.see.next.command.doc")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    64
                            "\r\u0005/");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    65
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    66
            waitOutput(out,  "/-<n>\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    67
                            Pattern.quote(getResource("help.previous")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    68
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    69
                            Pattern.quote(getResource("jshell.console.see.next.command.doc")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    70
                            "\r\u0005/");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    71
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44811
diff changeset
    72
            inputSink.write("ed\011");
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44811
diff changeset
    73
            waitOutput(out, "edit $");
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    74
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    75
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    76
            waitOutput(out, ".*-all.*" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    77
                            "\n\n" + Pattern.quote(getResource("jshell.console.see.synopsis")) + "\n\r\u0005/");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    78
            inputSink.write("\011");
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44811
diff changeset
    79
            waitOutput(out, Pattern.quote(getResource("help.edit.summary")) + "\n\n" +
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44811
diff changeset
    80
                            Pattern.quote(getResource("jshell.console.see.full.documentation")) + "\n\r\u0005/edit ");
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    81
            inputSink.write("\011");
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44811
diff changeset
    82
            waitOutput(out, Pattern.quote(getResource("help.edit").replaceAll("\t", "    ")));
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    83
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    84
            inputSink.write("\u0003/env \011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    85
            waitOutput(out, "\u0005/env -\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    86
                            "-add-exports    -add-modules    -class-path     -module-path    \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    87
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    88
                            Pattern.quote(getResource("jshell.console.see.synopsis")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    89
                            "\r\u0005/env -");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    90
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    91
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    92
            waitOutput(out, Pattern.quote(getResource("help.env.summary")) + "\n\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    93
                            Pattern.quote(getResource("jshell.console.see.full.documentation")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    94
                            "\r\u0005/env -");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    95
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    96
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    97
            waitOutput(out, Pattern.quote(getResource("help.env").replaceAll("\t", "    ")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    98
                            "\r\u0005/env -");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    99
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   100
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   101
            waitOutput(out, "-add-exports    -add-modules    -class-path     -module-path    \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   102
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   103
                            Pattern.quote(getResource("jshell.console.see.synopsis")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   104
                            "\r\u0005/env -");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   105
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   106
            inputSink.write("\u0003/exit \011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   107
            waitOutput(out, Pattern.quote(getResource("help.exit.summary")) + "\n\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   108
                            Pattern.quote(getResource("jshell.console.see.full.documentation")) + "\n\r\u0005/exit ");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   109
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   110
            waitOutput(out, Pattern.quote(getResource("help.exit")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   111
                            "\r\u0005/exit ");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   112
            inputSink.write("\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   113
            waitOutput(out, Pattern.quote(getResource("help.exit.summary")) + "\n\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   114
                            Pattern.quote(getResource("jshell.console.see.full.documentation")) + "\n\r\u0005/exit ");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   115
            inputSink.write("\u0003/doesnotexist\011");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   116
            waitOutput(out, "\u0005/doesnotexist\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   117
                            Pattern.quote(getResource("jshell.console.no.such.command")) + "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   118
                            "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   119
                            "\r\u0005/doesnotexist");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   120
        });
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   121
    }
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   122
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   123
}