ToolRetainTest.java revision 3428:d44729b76ebc
1/*
2 * Copyright (c) 2016, 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 8157200
27 * @summary Tests of what information is retained across jshell tool runs
28 * @modules jdk.jshell/jdk.internal.jshell.tool
29 * @build ToolRetainTest ReplToolTesting
30 * @run testng ToolRetainTest
31 */
32
33import org.testng.annotations.Test;
34
35@Test
36public class ToolRetainTest extends ReplToolTesting {
37
38    public void testRetainMode() {
39        test(
40                (a) -> assertCommand(a, "/set mode trm -quiet", "|  Created new feedback mode: trm"),
41                (a) -> assertCommand(a, "/set feedback trm", ""),
42                (a) -> assertCommand(a, "/set format trm display '{name}:{value}'", ""),
43                (a) -> assertCommand(a, "int x = 45", "x:45"),
44                (a) -> assertCommand(a, "/retain mode trm", ""),
45                (a) -> assertCommand(a, "/exit", "")
46        );
47        test(
48                (a) -> assertCommand(a, "/set feedback trm", ""),
49                (a) -> assertCommand(a, "int x = 45", "x:45")
50        );
51    }
52
53    public void testRetain2Mode() {
54        test(
55                (a) -> assertCommand(a, "/set mode trm1 -quiet", "|  Created new feedback mode: trm1"),
56                (a) -> assertCommand(a, "/retain mode trm1", ""),
57                (a) -> assertCommand(a, "/retain feedback trm1", ""),
58                (a) -> assertCommand(a, "/set format trm1 display '{name}:{value}'", ""),
59                (a) -> assertCommand(a, "int x = 66", "x:66"),
60                (a) -> assertCommand(a, "/retain mode trm1", ""),
61                (a) -> assertCommand(a, "/exit", "")
62        );
63        test(
64                (a) -> assertCommand(a, "/set mode trm2 -quiet", ""),
65                (a) -> assertCommand(a, "/set format trm2 display '{name}={value}'", ""),
66                (a) -> assertCommand(a, "int x = 45", "x:45"),
67                (a) -> assertCommand(a, "/retain mode trm2", ""),
68                (a) -> assertCommand(a, "/exit", "")
69        );
70        test(
71                (a) -> assertCommand(a, "int x = 99", "x:99"),
72                (a) -> assertCommand(a, "/set feedback trm2", ""),
73                (a) -> assertCommand(a, "int z = 77", "z=77")
74        );
75    }
76
77    public void testRetainFeedback() {
78        test(
79                (a) -> assertCommand(a, "/retain feedback verbose", "|  Feedback mode: verbose"),
80                (a) -> assertCommand(a, "/exit", "")
81        );
82        test(
83                (a) -> assertCommandOutputContains(a, "int h =8", "|  created variable h : int")
84        );
85    }
86
87    public void testRetainFeedbackBlank() {
88        test(
89                (a) -> assertCommand(a, "/set feedback verbose", "|  Feedback mode: verbose"),
90                (a) -> assertCommand(a, "/retain feedback", ""),
91                (a) -> assertCommand(a, "/exit", "")
92        );
93        test(
94                (a) -> assertCommandOutputContains(a, "int qw = 5", "|  created variable qw : int")
95        );
96    }
97
98    public void testRetainEditor() {
99        test(
100                (a) -> assertCommand(a, "/retain editor nonexistent", "|  Editor set to: nonexistent"),
101                (a) -> assertCommand(a, "/exit", "")
102        );
103        test(
104                (a) -> assertCommandOutputContains(a, "int h =8", ""),
105                (a) -> assertCommandOutputContains(a, "/edit h", "Edit Error:")
106        );
107    }
108
109    public void testRetainEditorBlank() {
110        test(
111                (a) -> assertCommand(a, "/set editor nonexistent", "|  Editor set to: nonexistent"),
112                (a) -> assertCommand(a, "/retain editor", ""),
113                (a) -> assertCommand(a, "/exit", "")
114        );
115        test(
116                (a) -> assertCommandOutputContains(a, "int h =8", ""),
117                (a) -> assertCommandOutputContains(a, "/edit h", "Edit Error:")
118        );
119    }
120
121    public void testRetainModeNeg() {
122        test(
123                (a) -> assertCommandOutputStartsWith(a, "/retain mode verbose",
124                        "|  Not valid with a predefined mode"),
125                (a) -> assertCommandOutputStartsWith(a, "/retain mode ????",
126                        "|  Expected a feedback mode name: ????")
127        );
128    }
129
130    public void testRetainFeedbackNeg() {
131        test(
132                (a) -> assertCommandOutputStartsWith(a, "/retain feedback babble1",
133                        "|  Does not match any current feedback mode"),
134                (a) -> assertCommand(a, "/set mode trfn",
135                        "|  Created new feedback mode: trfn"),
136                (a) -> assertCommandOutputContains(a, "/retain feedback trfn",
137                        "is predefined or has been retained"),
138                (a) -> assertCommandOutputStartsWith(a, "/retain feedback !!!!",
139                        "|  Expected a feedback mode name: !!!!")
140        );
141    }
142
143    public void testNoRetainMode() {
144        test(
145                (a) -> assertCommand(a, "/set mode trm -quiet", "|  Created new feedback mode: trm"),
146                (a) -> assertCommand(a, "/set feedback trm", ""),
147                (a) -> assertCommand(a, "/set format trm display '{name}:{value}'", ""),
148                (a) -> assertCommand(a, "int x = 45", "x:45"),
149                (a) -> assertCommand(a, "/exit", "")
150        );
151        test(
152                (a) -> assertCommandOutputStartsWith(a, "/set feedback trm",
153                        "|  Does not match any current feedback mode"),
154                (a) -> assertCommandOutputContains(a, "int x = 45", "==> 45")
155        );
156    }
157
158    public void testNoRetainFeedback() {
159        test(
160                (a) -> assertCommand(a, "/set feedback verbose", "|  Feedback mode: verbose"),
161                (a) -> assertCommand(a, "/exit", "")
162        );
163        test(
164                (a) -> assertCommand(a, "int h =8", "h ==> 8")
165        );
166    }
167
168}
169