langtools/test/jdk/jshell/PasteAndMeasurementsUITest.java
changeset 46923 0172e4350f65
equal deleted inserted replaced
46922:222cce44e577 46923:0172e4350f65
       
     1 /*
       
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /**
       
    25  * @test
       
    26  * @bug 8182297
       
    27  * @summary Verify that pasting multi-line snippets works properly.
       
    28  * @library /tools/lib
       
    29  * @modules
       
    30  *     java.base/java.lang:open
       
    31  *     java.base/java.io:open
       
    32  *     jdk.compiler/com.sun.tools.javac.api
       
    33  *     jdk.compiler/com.sun.tools.javac.main
       
    34  *     jdk.jshell/jdk.internal.jshell.tool.resources:open
       
    35  *     jdk.jshell/jdk.jshell:open
       
    36  * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
       
    37  * @build Compiler UITesting
       
    38  * @build PasteAndMeasurementsUITest
       
    39  * @run testng/othervm PasteAndMeasurementsUITest
       
    40  */
       
    41 
       
    42 import java.io.Console;
       
    43 import java.lang.reflect.Constructor;
       
    44 import java.lang.reflect.Field;
       
    45 
       
    46 import org.testng.annotations.Test;
       
    47 
       
    48 @Test
       
    49 public class PasteAndMeasurementsUITest extends UITesting {
       
    50 
       
    51     public void testPrevNextSnippet() throws Exception {
       
    52         System.setProperty(ANSI_SUPPORTED_PROPERTY, "true");
       
    53         Field cons = System.class.getDeclaredField("cons");
       
    54         cons.setAccessible(true);
       
    55         Constructor console = Console.class.getDeclaredConstructor();
       
    56         console.setAccessible(true);
       
    57         cons.set(null, console.newInstance());
       
    58         doRunTest((inputSink, out) -> {
       
    59             inputSink.write("void test1() {\nSystem.err.println(1);\n}\n" + LOC +
       
    60                             "void test2() {\nSystem.err.println(1);\n}\n" + LOC + LOC + LOC + LOC + LOC);
       
    61             waitOutput(out,       "\u001b\\[6nvoid test1\\(\\) \\{\n" +
       
    62                             "\u0006\u001b\\[6nSystem.err.println\\(1\\);\n" +
       
    63                             "\u0006\u001b\\[6n\\}\n" +
       
    64                             "\\|  created method test1\\(\\)\n" +
       
    65                             "\u0005\u001b\\[6nvoid test2\\(\\) \\{\n" +
       
    66                             "\u0006\u001b\\[6nSystem.err.println\\(1\\);\n" +
       
    67                             "\u0006\u001b\\[6n\\}\n" +
       
    68                             "\\|  created method test2\\(\\)\n" +
       
    69                             "\u0005\u001b\\[6n");
       
    70         });
       
    71     }
       
    72         private static final String ANSI_SUPPORTED_PROPERTY = "test.terminal.ansi.supported";
       
    73         private static final String LOC = "\033[12;1R";
       
    74 }