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 8177076 8185840
  27  * @modules
  28  *     jdk.compiler/com.sun.tools.javac.api
  29  *     jdk.compiler/com.sun.tools.javac.main
  30  *     jdk.jshell/jdk.internal.jshell.tool.resources:open
  31  *     jdk.jshell/jdk.jshell:open
  32  * @library /tools/lib
  33  * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
  34  * @build Compiler UITesting
  35  * @build ToolTabCommandTest
  36  * @run testng ToolTabCommandTest
  37  */
  38 
  39 import java.util.regex.Pattern;
  40 
  41 import org.testng.annotations.Test;
  42 
  43 @Test
  44 public class ToolTabCommandTest extends UITesting {
  45 
  46     public void testCommand() throws Exception {
  47         // set terminal height so that help output won't hit page breaks
  48         System.setProperty("test.terminal.height", "1000000");
  49 
  50         doRunTest((inputSink, out) -> {
  51             inputSink.write("1\n");
  52             waitOutput(out, "\u0005");
  53             inputSink.write("/\011");
  54             waitOutput(out, ".*/edit.*/list.*\n\n" + Pattern.quote(getResource("jshell.console.see.synopsis")) + "\n\r\u0005/");
  55             inputSink.write("\011");
  56             waitOutput(out,   ".*\n/edit\n" + Pattern.quote(getResource("help.edit.summary")) +
  57                             "\n.*\n/list\n" + Pattern.quote(getResource("help.list.summary")) +
  58                             ".*\n\n" + Pattern.quote(getResource("jshell.console.see.full.documentation")) + "\n\r\u0005/");
  59             inputSink.write("\011");
  60             waitOutput(out,  "/!\n" +
  61                             Pattern.quote(getResource("help.bang")) + "\n" +
  62                             "\n" +
  63                             Pattern.quote(getResource("jshell.console.see.next.command.doc")) + "\n" +
  64                             "\r\u0005/");
  65             inputSink.write("\011");
  66             waitOutput(out,  "/-<n>\n" +
  67                             Pattern.quote(getResource("help.previous")) + "\n" +
  68                             "\n" +
  69                             Pattern.quote(getResource("jshell.console.see.next.command.doc")) + "\n" +
  70                             "\r\u0005/");
  71 
  72             inputSink.write("ed\011");
  73             waitOutput(out, "edit $");
  74 
  75             inputSink.write("\011");
  76             waitOutput(out, ".*-all.*" +
  77                             "\n\n" + Pattern.quote(getResource("jshell.console.see.synopsis")) + "\n\r\u0005/");
  78             inputSink.write("\011");
  79             waitOutput(out, Pattern.quote(getResource("help.edit.summary")) + "\n\n" +
  80                             Pattern.quote(getResource("jshell.console.see.full.documentation")) + "\n\r\u0005/edit ");
  81             inputSink.write("\011");
  82             waitOutput(out, Pattern.quote(getResource("help.edit").replaceAll("\t", "    ")));
  83 
  84             inputSink.write("\u0003/env \011");
  85             waitOutput(out, "\u0005/env -\n" +
  86                             "-add-exports    -add-modules    -class-path     -module-path    \n" +
  87                             "\n" +
  88                             Pattern.quote(getResource("jshell.console.see.synopsis")) + "\n" +
  89                             "\r\u0005/env -");
  90 
  91             inputSink.write("\011");
  92             waitOutput(out, Pattern.quote(getResource("help.env.summary")) + "\n\n" +
  93                             Pattern.quote(getResource("jshell.console.see.full.documentation")) + "\n" +
  94                             "\r\u0005/env -");
  95 
  96             inputSink.write("\011");
  97             waitOutput(out, Pattern.quote(getResource("help.env").replaceAll("\t", "    ")) + "\n" +
  98                             "\r\u0005/env -");
  99 
 100             inputSink.write("\011");
 101             waitOutput(out, "-add-exports    -add-modules    -class-path     -module-path    \n" +
 102                             "\n" +
 103                             Pattern.quote(getResource("jshell.console.see.synopsis")) + "\n" +
 104                             "\r\u0005/env -");
 105 
 106             inputSink.write("\u0003/exit \011");
 107             waitOutput(out, Pattern.quote(getResource("help.exit.summary")) + "\n\n" +
 108                             Pattern.quote(getResource("jshell.console.see.full.documentation")) + "\n\r\u0005/exit ");
 109             inputSink.write("\011");
 110             waitOutput(out, Pattern.quote(getResource("help.exit").replaceAll("\t", "    ")) + "\n" +
 111                             "\r\u0005/exit ");
 112             inputSink.write("\011");
 113             waitOutput(out, Pattern.quote(getResource("help.exit.summary")) + "\n\n" +
 114                             Pattern.quote(getResource("jshell.console.see.full.documentation")) + "\n\r\u0005/exit ");
 115             inputSink.write("\u0003");
 116             inputSink.write("int zebraStripes = 11\n");
 117             waitOutput(out, "zebraStripes ==> 11\n\u0005");
 118             inputSink.write("/exit zeb\011");
 119             waitOutput(out, "braStr.*es");
 120             inputSink.write("\u0003/doesnotexist\011");
 121             waitOutput(out, "\u0005/doesnotexist\n" +
 122                             Pattern.quote(getResource("jshell.console.no.such.command")) + "\n" +
 123                             "\n" +
 124                             "\r\u0005/doesnotexist");
 125         });
 126     }
 127 
 128 }