test/langtools/jdk/jshell/HistoryUITest.java
author coleenp
Wed, 15 Nov 2017 08:14:31 -0500
changeset 47894 352b17f62ff7
parent 47216 71c04702a3d5
child 48275 b2190c70a1ac
permissions -rw-r--r--
8191315: Add serviceability/sa/TestRevPtrsForInvokeDynamic.java to ProblemList.txt Reviewed-by: dholmes, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44570
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
     1
/*
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
     4
 *
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
     8
 *
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    14
 *
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    18
 *
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    21
 * questions.
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    22
 */
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    23
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    24
/**
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    25
 * @test
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    26
 * @bug 8178077
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    27
 * @summary Check the UI behavior of editing history.
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    28
 * @modules
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    29
 *     jdk.compiler/com.sun.tools.javac.api
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    30
 *     jdk.compiler/com.sun.tools.javac.main
44811
32c15978a3af 8178035: MergedTabShiftTabTest sometimes time outs
jlahoda
parents: 44570
diff changeset
    31
 *     jdk.jshell/jdk.internal.jshell.tool.resources:open
44570
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    32
 *     jdk.jshell/jdk.jshell:open
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    33
 * @library /tools/lib
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    34
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    35
 * @build Compiler UITesting
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    36
 * @build HistoryUITest
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    37
 * @run testng HistoryUITest
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    38
 */
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    39
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    40
import org.testng.annotations.Test;
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    41
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    42
@Test
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    43
public class HistoryUITest extends UITesting {
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    44
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    45
    public void testPrevNextSnippet() throws Exception {
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    46
        doRunTest((inputSink, out) -> {
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    47
            inputSink.write("void test1() {\nSystem.err.println(1);\n}\n");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    48
            waitOutput(out, "\u0005");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    49
            inputSink.write("void test2() {\nSystem.err.println(2);\n}\n");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    50
            waitOutput(out, "\u0005");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    51
            inputSink.write(CTRL_UP);
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    52
            waitOutput(out, "^void test2\\(\\) \\{");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    53
            inputSink.write(CTRL_UP);
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    54
            waitOutput(out, "^" + clearOut("2() {") + "1\\(\\) \\{");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    55
            inputSink.write(CTRL_DOWN);
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    56
            waitOutput(out, "^" + clearOut("1() {") + "2\\(\\) \\{");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    57
            inputSink.write(ENTER);
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    58
            waitOutput(out, "^\n\u0006");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    59
            inputSink.write(UP);
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    60
            waitOutput(out, "^}");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    61
            inputSink.write(UP);
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    62
            waitOutput(out, "^" + clearOut("}") + "System.err.println\\(2\\);");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    63
            inputSink.write(UP);
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    64
            waitOutput(out, "^" + clearOut("System.err.println(2);") + "void test2\\(\\) \\{");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    65
            inputSink.write(UP);
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    66
            waitOutput(out, "^\u0007");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    67
            inputSink.write(DOWN);
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    68
            waitOutput(out, "^" + clearOut("void test2() {") + "System.err.println\\(2\\);");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    69
            inputSink.write(DOWN);
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    70
            waitOutput(out, "^" + clearOut("System.err.println(2);") + "}");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    71
            inputSink.write(DOWN);
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    72
            waitOutput(out, "^" + clearOut("}"));
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    73
            inputSink.write(DOWN);
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    74
            waitOutput(out, "^\u0007");
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    75
        });
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    76
    }
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    77
    //where:
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    78
        private static final String CTRL_UP = "\033[1;5A";
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    79
        private static final String CTRL_DOWN = "\033[1;5B";
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    80
        private static final String UP = "\033[A";
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    81
        private static final String DOWN = "\033[B";
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    82
        private static final String ENTER = "\n";
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    83
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents:
diff changeset
    84
}