36990
|
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 8147515
|
|
27 |
* @summary Tests for output customization
|
|
28 |
* @library /tools/lib
|
|
29 |
* @modules jdk.compiler/com.sun.tools.javac.api
|
|
30 |
* jdk.compiler/com.sun.tools.javac.main
|
|
31 |
* jdk.jdeps/com.sun.tools.javap
|
|
32 |
* jdk.jshell/jdk.internal.jshell.tool
|
|
33 |
* @build KullaTesting TestingInputStream toolbox.ToolBox Compiler
|
|
34 |
* @run testng ToolLocaleMessageTest
|
|
35 |
*/
|
|
36 |
|
|
37 |
import java.util.Locale;
|
|
38 |
import org.testng.annotations.Test;
|
|
39 |
import static org.testng.Assert.assertFalse;
|
|
40 |
import static org.testng.Assert.assertTrue;
|
|
41 |
|
|
42 |
@Test
|
|
43 |
public class ToolLocaleMessageTest extends ReplToolTesting {
|
|
44 |
|
|
45 |
void testLocale(ReplTest... tests) {
|
|
46 |
test(Locale.getDefault(), false, new String[]{"-nostartup"}, "", tests);
|
|
47 |
}
|
|
48 |
|
|
49 |
void assertCommandOK(boolean after, String cmd, String... contains) {
|
|
50 |
assertCommandCheckOutput(after, cmd, s -> {
|
|
51 |
assertFalse(s.contains("Exception"), "Output of '" + cmd + "' has Exception: " + s);
|
|
52 |
assertFalse(s.contains("ERROR:"), "Output of '" + cmd + "' has error: " + s);
|
|
53 |
for (String m : contains) {
|
|
54 |
assertTrue(s.contains(m), "Expected to find '" + m + "' in output of '" + cmd + "' -- output: " + s);
|
|
55 |
}
|
|
56 |
});
|
|
57 |
}
|
|
58 |
|
|
59 |
void assertCommandFail(boolean after, String cmd, String... contains) {
|
|
60 |
assertCommandCheckOutput(after, cmd, s -> {
|
|
61 |
assertFalse(s.contains("Exception"), "Output of '" + cmd + "' has Exception: " + s);
|
|
62 |
assertTrue(s.contains("ERROR:"), "Expected to find error in output of '" + cmd + "' has error: " + s);
|
|
63 |
for (String m : contains) {
|
|
64 |
assertTrue(s.contains(m), "Expected to find '" + m + "' in output of '" + cmd + "' -- output: " + s);
|
|
65 |
}
|
|
66 |
});
|
|
67 |
}
|
|
68 |
|
|
69 |
public void testTerminate() {
|
|
70 |
testLocale(
|
|
71 |
(a) -> assertCommandOK(a, "System.exit(1)", "/reload")
|
|
72 |
);
|
|
73 |
}
|
|
74 |
|
|
75 |
public void testSample() {
|
|
76 |
try {
|
|
77 |
testLocale(
|
|
78 |
(a) -> assertCommandOK(a, "/set newmode test command normal", "test"),
|
|
79 |
(a) -> assertCommandOK(a, "/set format test errorpre 'ERROR: '"),
|
|
80 |
(a) -> assertCommandOK(a, "/set feedback test", "test"),
|
|
81 |
|
|
82 |
(a) -> assertCommandFail(a, "/turkey", "/turkey"),
|
|
83 |
(a) -> assertCommandFail(a, "/s", "/set"),
|
|
84 |
(a) -> assertCommandOK(a, "void m() { blah(); }", "blah"),
|
|
85 |
(a) -> assertCommandOK(a, "void m() {}"),
|
|
86 |
(a) -> assertCommandOK(a, "class C {}"),
|
|
87 |
(a) -> assertCommandOK(a, "47"),
|
|
88 |
(a) -> assertCommandOK(a, "double d"),
|
|
89 |
(a) -> assertCommandOK(a, "/drop m", "m"),
|
|
90 |
(a) -> assertCommandOK(a, "void dup() {}"),
|
|
91 |
(a) -> assertCommandOK(a, "int dup"),
|
|
92 |
|
|
93 |
(a) -> assertCommandOK(a, "/set feedback normal", "normal")
|
|
94 |
);
|
|
95 |
} finally {
|
|
96 |
assertCommandOK(false, "/set feedback normal");
|
|
97 |
}
|
|
98 |
}
|
|
99 |
|
|
100 |
public void testCommand() {
|
|
101 |
try {
|
|
102 |
testLocale(
|
|
103 |
(a) -> assertCommandOK(a, "/set newmode test command normal", "test"),
|
|
104 |
(a) -> assertCommandOK(a, "/set format test errorpre 'ERROR: '"),
|
|
105 |
(a) -> assertCommandOK(a, "/set feedback test", "test"),
|
|
106 |
|
|
107 |
(a) -> assertCommandFail(a, "/list zebra"),
|
|
108 |
(a) -> assertCommandFail(a, "/set editor", "/set editor"),
|
|
109 |
(a) -> assertCommandFail(a, "/set snowball", "/set", "snowball"),
|
|
110 |
(a) -> assertCommandFail(a, "/set", "/set", "/help"),
|
|
111 |
(a) -> assertCommandFail(a, "/set f", "feedback"),
|
|
112 |
(a) -> assertCommandFail(a, "/classpath", "/classpath"),
|
|
113 |
(a) -> assertCommandFail(a, "/help rabbits", "rabbits"),
|
|
114 |
(a) -> assertCommandFail(a, "/drop"),
|
|
115 |
(a) -> assertCommandFail(a, "/drop rats"),
|
|
116 |
(a) -> assertCommandOK(a, "void dup() {}"),
|
|
117 |
(a) -> assertCommandOK(a, "int dup"),
|
|
118 |
(a) -> assertCommandFail(a, "/drop dup"),
|
|
119 |
(a) -> assertCommandFail(a, "/edit zebra", "zebra"),
|
|
120 |
(a) -> assertCommandFail(a, "/list zebra", "zebra", "/list"),
|
|
121 |
(a) -> assertCommandFail(a, "/open", "/open"),
|
|
122 |
(a) -> assertCommandFail(a, "/open zebra", "zebra", "/open"),
|
|
123 |
(a) -> assertCommandFail(a, "/reload zebra", "zebra", "/reload"),
|
|
124 |
(a) -> assertCommandFail(a, "/save", "/save"),
|
|
125 |
(a) -> assertCommandFail(a, "/-99"),
|
|
126 |
|
|
127 |
(a) -> assertCommandOK(a, "/set feedback normal", "normal")
|
|
128 |
);
|
|
129 |
} finally {
|
|
130 |
assertCommandOK(false, "/set feedback normal");
|
|
131 |
}
|
|
132 |
}
|
|
133 |
|
|
134 |
public void testHelp() {
|
|
135 |
testLocale(
|
|
136 |
(a) -> assertCommandOK(a, "/help", "/list", "/save", "/set", "[restore]"),
|
|
137 |
(a) -> assertCommandOK(a, "/help /list", "start", "all"),
|
|
138 |
(a) -> assertCommandOK(a, "/help /edit", "/set editor"),
|
|
139 |
(a) -> assertCommandOK(a, "/help /drop", "/drop"),
|
|
140 |
(a) -> assertCommandOK(a, "/help /save", "all", "start"),
|
|
141 |
(a) -> assertCommandOK(a, "/help /open", "/open"),
|
|
142 |
(a) -> assertCommandOK(a, "/help /reload", "restore"),
|
|
143 |
(a) -> assertCommandOK(a, "/help /help", "intro"),
|
|
144 |
(a) -> assertCommandOK(a, "/help /set", "newmode"),
|
|
145 |
(a) -> assertCommandOK(a, "/help /?", "intro"),
|
|
146 |
(a) -> assertCommandOK(a, "/help intro", "/help"),
|
|
147 |
(a) -> assertCommandOK(a, "/help /set format", "import", "case", "{value}", "added"),
|
|
148 |
(a) -> assertCommandOK(a, "/help /set feedback", "newmode"),
|
|
149 |
(a) -> assertCommandOK(a, "/help /set newmode", "feedback"),
|
|
150 |
(a) -> assertCommandOK(a, "/help /set prompt", "/set prompt"),
|
|
151 |
(a) -> assertCommandOK(a, "/help /set editor", "/edit")
|
|
152 |
);
|
|
153 |
}
|
|
154 |
|
|
155 |
public void testFeedbackError() {
|
|
156 |
try {
|
|
157 |
testLocale(
|
|
158 |
(a) -> assertCommandOK(a, "/set newmode tee command foo", "foo"),
|
|
159 |
(a) -> assertCommandOK(a, "/set newmode tee flurb", "command", "quiet"),
|
|
160 |
(a) -> assertCommandOK(a, "/set newmode te2", "te2"),
|
|
161 |
(a) -> assertCommandOK(a, "/set newmode te2 command", "te2"),
|
|
162 |
(a) -> assertCommandOK(a, "/set newmode te command normal", "te"),
|
|
163 |
(a) -> assertCommandOK(a, "/set format te errorpre 'ERROR: '"),
|
|
164 |
(a) -> assertCommandOK(a, "/set feedback te"),
|
|
165 |
|
|
166 |
(a) -> assertCommandFail(a, "/set "),
|
|
167 |
(a) -> assertCommandFail(a, "/set xyz", "xyz"),
|
|
168 |
(a) -> assertCommandFail(a, "/set f", "/set", "f"),
|
|
169 |
(a) -> assertCommandFail(a, "/set feedback"),
|
|
170 |
(a) -> assertCommandFail(a, "/set feedback xyz"),
|
|
171 |
(a) -> assertCommandFail(a, "/set format"),
|
|
172 |
(a) -> assertCommandFail(a, "/set format xyz"),
|
|
173 |
(a) -> assertCommandFail(a, "/set format t"),
|
|
174 |
(a) -> assertCommandFail(a, "/set format te"),
|
|
175 |
(a) -> assertCommandFail(a, "/set format te fld"),
|
|
176 |
(a) -> assertCommandFail(a, "/set format te fld aaa", "aaa"),
|
|
177 |
(a) -> assertCommandFail(a, "/set format te fld 'aaa' frog"),
|
|
178 |
(a) -> assertCommandFail(a, "/set format te fld 'aaa' import-frog"),
|
|
179 |
(a) -> assertCommandFail(a, "/set format te fld 'aaa' import-import"),
|
|
180 |
(a) -> assertCommandFail(a, "/set format te fld 'aaa' import,added"),
|
|
181 |
(a) -> assertCommandFail(a, "/set newmode"),
|
|
182 |
(a) -> assertCommandFail(a, "/set newmode te"),
|
|
183 |
(a) -> assertCommandFail(a, "/set newmode x xyz"),
|
|
184 |
(a) -> assertCommandFail(a, "/set newmode x quiet y"),
|
|
185 |
(a) -> assertCommandFail(a, "/set prompt"),
|
|
186 |
(a) -> assertCommandFail(a, "/set prompt te"),
|
|
187 |
(a) -> assertCommandFail(a, "/set prompt te aaa xyz", "aaa"),
|
|
188 |
(a) -> assertCommandFail(a, "/set prompt te 'aaa' xyz", "xyz"),
|
|
189 |
(a) -> assertCommandFail(a, "/set prompt"),
|
|
190 |
(a) -> assertCommandFail(a, "/set prompt te"),
|
|
191 |
(a) -> assertCommandFail(a, "/set prompt te aaa"),
|
|
192 |
(a) -> assertCommandFail(a, "/set prompt te 'aaa'"),
|
|
193 |
|
|
194 |
(a) -> assertCommandOK(a, "/set feedback normal")
|
|
195 |
);
|
|
196 |
} finally {
|
|
197 |
assertCommandOK(false, "/set feedback normal");
|
|
198 |
}
|
|
199 |
}
|
|
200 |
|
|
201 |
|
|
202 |
}
|