1 /*
2  * Copyright (c) 2017, 2018, 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 8178109 8192863
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 org.testng.annotations.Test;
40 
41 @Test
42 public class ToolTabCommandTest extends UITesting {
43 
ToolTabCommandTest()44     public ToolTabCommandTest() {
45         super(true);
46     }
47 
testCommand()48     public void testCommand() throws Exception {
49         // set terminal height so that help output won't hit page breaks
50         System.setProperty("test.terminal.height", "1000000");
51 
52         doRunTest((inputSink, out) -> {
53             inputSink.write("1\n");
54             waitOutput(out, PROMPT);
55             inputSink.write("/" + TAB);
56             waitOutput(out, ".*/edit.*/list.*\n\n" + resource("jshell.console.see.synopsis") +
57                             REDRAW_PROMPT + "/");
58             inputSink.write(TAB);
59             waitOutput(out,   ".*\n/edit\n" + resource("help.edit.summary") +
60                             "\n.*\n/list\n" + resource("help.list.summary") +
61                             ".*\n\n" + resource("jshell.console.see.full.documentation") +
62                             REDRAW_PROMPT + "/");
63             inputSink.write(TAB);
64             waitOutput(out,  "/!\n" +
65                             resource("help.bang") + "\n" +
66                             "\n" +
67                             resource("jshell.console.see.next.command.doc") +
68                             REDRAW_PROMPT + "/");
69             inputSink.write(TAB);
70             waitOutput(out,  "/-<n>\n" +
71                             resource("help.previous") + "\n" +
72                             "\n" +
73                             resource("jshell.console.see.next.command.doc") +
74                             REDRAW_PROMPT + "/");
75 
76             inputSink.write("ed" + TAB);
77             waitOutput(out, "edit $");
78 
79             inputSink.write(TAB);
80             waitOutput(out, ".*-all.*" +
81                             "\n\n" + resource("jshell.console.see.synopsis") +
82                             REDRAW_PROMPT + "/");
83             inputSink.write(TAB);
84             waitOutput(out, resource("help.edit.summary") + "\n\n" +
85                             resource("jshell.console.see.full.documentation") +
86                             REDRAW_PROMPT + "/edit ");
87             inputSink.write(TAB);
88             waitOutput(out, resource("help.edit"));
89 
90             inputSink.write(INTERRUPT + "/env " + TAB);
91             waitOutput(out, PROMPT + "/env \n" +
92                             "-add-exports    -add-modules    -class-path     -module-path    \n" +
93                             "\n" +
94                             resource("jshell.console.see.synopsis") +
95                             REDRAW_PROMPT + "/env -");
96 
97             inputSink.write(TAB);
98             waitOutput(out, resource("help.env.summary") + "\n\n" +
99                             resource("jshell.console.see.full.documentation") +
100                             REDRAW_PROMPT + "/env -");
101 
102             inputSink.write(TAB);
103             waitOutput(out, resource("help.env") +
104                             REDRAW_PROMPT + "/env -");
105 
106             inputSink.write(TAB);
107             waitOutput(out, "-add-exports    -add-modules    -class-path     -module-path    \n" +
108                             "\n" +
109                             resource("jshell.console.see.synopsis") +
110                             REDRAW_PROMPT + "/env -");
111 
112             inputSink.write(INTERRUPT + "/exit " + TAB);
113             waitOutput(out, resource("help.exit.summary") + "\n\n" +
114                             resource("jshell.console.see.full.documentation") +
115                             REDRAW_PROMPT + "/exit ");
116             inputSink.write(TAB);
117             waitOutput(out, resource("help.exit") +
118                             REDRAW_PROMPT + "/exit ");
119             inputSink.write(TAB);
120             waitOutput(out, resource("help.exit.summary") + "\n\n" +
121                             resource("jshell.console.see.full.documentation") +
122                             REDRAW_PROMPT + "/exit ");
123             inputSink.write(INTERRUPT);
124             inputSink.write("int zebraStripes = 11\n");
125             waitOutput(out, "\\u001B\\[\\?2004lzebraStripes ==> 11\n\\u001B\\[\\?2004h" + PROMPT);
126             inputSink.write("/exit zeb" + TAB);
127             waitOutput(out, "braStr.*es");
128             inputSink.write(INTERRUPT + "/doesnotexist" + TAB);
129             waitOutput(out, PROMPT + "/doesnotexist\n" +
130                             resource("jshell.console.no.such.command") + "\n" +
131                             REDRAW_PROMPT + "/doesnotexist");
132         });
133     }
134 
testRerunCommands()135     public void testRerunCommands() throws Exception {
136         // set terminal height so that help output won't hit page breaks
137         System.setProperty("test.terminal.height", "1000000");
138 
139         doRunTest((inputSink, out) -> {
140             inputSink.write("1\n");
141             waitOutput(out, PROMPT);
142             inputSink.write("2\n");
143             waitOutput(out, PROMPT);
144 
145             inputSink.write("/1" + TAB);
146             waitOutput(out, resource("help.rerun.summary") + "\n\n" +
147                             resource("jshell.console.see.full.documentation") +
148                             REDRAW_PROMPT + "/1");
149             inputSink.write(TAB);
150             waitOutput(out, resource("help.rerun") +
151                             REDRAW_PROMPT + "/1");
152             inputSink.write(TAB);
153             waitOutput(out, resource("help.rerun.summary") + "\n\n" +
154                             resource("jshell.console.see.full.documentation") +
155                             REDRAW_PROMPT + "/1");
156 
157             inputSink.write(INTERRUPT);
158             inputSink.write("/-1" + TAB);
159             waitOutput(out, resource("help.rerun.summary") + "\n\n" +
160                             resource("jshell.console.see.full.documentation") +
161                             REDRAW_PROMPT + "/-1");
162             inputSink.write(TAB);
163             waitOutput(out, resource("help.rerun") +
164                             REDRAW_PROMPT + "/-1");
165             inputSink.write(TAB);
166             waitOutput(out, resource("help.rerun.summary") + "\n\n" +
167                             resource("jshell.console.see.full.documentation") +
168                             REDRAW_PROMPT + "/-1");
169         });
170     }
171 
testHelp()172     public void testHelp() throws Exception {
173         // set terminal height so that help output won't hit page breaks
174         System.setProperty("test.terminal.height", "1000000");
175 
176         doRunTest((inputSink, out) -> {
177             inputSink.write("/help " + TAB);
178             waitOutput(out, ".*/edit.*/list.*intro.*\n\n" + resource("jshell.console.see.synopsis") +
179                             REDRAW_PROMPT + "/");
180             inputSink.write(TAB);
181             waitOutput(out,   ".*\n/edit\n" + resource("help.edit.summary") +
182                             "\n.*\n/list\n" + resource("help.list.summary") +
183                             "\n.*\nintro\n" + resource("help.intro.summary") +
184                             ".*\n\n" + resource("jshell.console.see.full.documentation") +
185                             REDRAW_PROMPT + "/");
186             inputSink.write("/env" + TAB);
187             waitOutput(out,   "help /env ");
188             inputSink.write(TAB);
189             waitOutput(out,   ".*\n/env\n" + resource("help.env.summary") +
190                             ".*\n\n" + resource("jshell.console.see.full.documentation") +
191                             REDRAW_PROMPT + "/help /env ");
192             inputSink.write(TAB);
193             waitOutput(out,   ".*\n/env\n" + resource("help.env") +
194                             REDRAW_PROMPT + "/help /env ");
195             inputSink.write(INTERRUPT + "/help intro" + TAB);
196             waitOutput(out,   "help intro ");
197             inputSink.write(TAB);
198             waitOutput(out,   ".*\nintro\n" + resource("help.intro.summary") +
199                             ".*\n\n" + resource("jshell.console.see.full.documentation") +
200                             REDRAW_PROMPT + "/help intro ");
201             inputSink.write(TAB);
202             waitOutput(out,   ".*\nintro\n" + resource("help.intro") +
203                             REDRAW_PROMPT + "/help intro ");
204             inputSink.write(INTERRUPT + "/help /set " + TAB);
205             waitOutput(out, ".*format.*truncation.*\n\n" + resource("jshell.console.see.synopsis") +
206                             REDRAW_PROMPT + "/help /set ");
207             inputSink.write(TAB);
208             waitOutput(out,   ".*\n/set format\n" + resource("help.set.format.summary") +
209                             "\n.*\n/set truncation\n" + resource("help.set.truncation.summary") +
210                             ".*\n\n" + resource("jshell.console.see.full.documentation") +
211                             REDRAW_PROMPT + "/help /set ");
212             inputSink.write("truncation" + TAB);
213             waitOutput(out,   ".*truncation\n" + resource("jshell.console.see.synopsis") +
214                             REDRAW_PROMPT + "/help /set truncation");
215             inputSink.write(TAB);
216             waitOutput(out,   ".*/set truncation\n" + resource("help.set.truncation.summary") + "\n" +
217                             "\n" + resource("jshell.console.see.full.documentation") +
218                             REDRAW_PROMPT + "/help /set truncation");
219             inputSink.write(TAB);
220             waitOutput(out,   ".*/set truncation\n" + resource("help.set.truncation") +
221                            "\r" + PROMPT + "/help /set truncation");
222             inputSink.write(INTERRUPT + "/help env " + TAB);
223             waitOutput(out,   ".*\n/env\n" + resource("help.env.summary") +
224                             ".*\n\n" + resource("jshell.console.see.full.documentation") +
225                             REDRAW_PROMPT + "/help env ");
226             inputSink.write(INTERRUPT + "/help set truncation" + TAB);
227             waitOutput(out,   ".*truncation\n" + resource("jshell.console.see.synopsis") +
228                             REDRAW_PROMPT + "/help set truncation");
229             inputSink.write(TAB);
230             waitOutput(out,   ".*\n/set truncation\n" + resource("help.set.truncation.summary") +
231                             ".*\n\n" + resource("jshell.console.see.full.documentation") +
232                             REDRAW_PROMPT + "/help set truncation");
233         });
234     }
235 }
236