|
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 8148316 8148317 |
|
27 * @summary Tests for output customization |
|
28 * @library /tools/lib |
|
29 * @build KullaTesting TestingInputStream ToolBox Compiler |
|
30 * @run testng ToolFormatTest |
|
31 */ |
|
32 import org.testng.annotations.Test; |
|
33 |
|
34 @Test |
|
35 public class ToolFormatTest extends ReplToolTesting { |
|
36 |
|
37 public void testSetFormat() { |
|
38 try { |
|
39 test( |
|
40 (a) -> assertCommandOutputStartsWith(a, "/set newmode test command", "| Created new feedback mode: test"), |
|
41 (a) -> assertCommand(a, "/set field test pre '$ '", ""), |
|
42 (a) -> assertCommand(a, "/set field test post ''", ""), |
|
43 (a) -> assertCommand(a, "/set field test action 'ADD ' added-primary", ""), |
|
44 (a) -> assertCommand(a, "/set field test action 'MOD ' modified-primary", ""), |
|
45 (a) -> assertCommand(a, "/set field test action 'REP ' replaced-primary", ""), |
|
46 (a) -> assertCommand(a, "/set field test action 'UP-ADD ' added-update", ""), |
|
47 (a) -> assertCommand(a, "/set field test action 'UP-MOD ' modified-update", ""), |
|
48 (a) -> assertCommand(a, "/set field test action 'UP-REP ' replaced-update", ""), |
|
49 (a) -> assertCommand(a, "/set field test resolve 'OK' ok-*", ""), |
|
50 (a) -> assertCommand(a, "/set field test resolve 'DEF' defined-*", ""), |
|
51 (a) -> assertCommand(a, "/set field test resolve 'NODEF' notdefined-*", ""), |
|
52 (a) -> assertCommand(a, "/set field test name ':%s ' ", ""), |
|
53 (a) -> assertCommand(a, "/set field test type '[%s]' ", ""), |
|
54 (a) -> assertCommand(a, "/set field test result '=%s ' ", ""), |
|
55 (a) -> assertCommand(a, "/set format test '{pre}{action}{type}{name}{result}{resolve}' *-*-*", ""), |
|
56 (a) -> assertCommand(a, "/set format test '{pre}HI this is enum' enum", ""), |
|
57 (a) -> assertCommand(a, "/set feedback test", "$ Feedback mode: test"), |
|
58 (a) -> assertCommand(a, "class D {}", "$ ADD :D OK"), |
|
59 (a) -> assertCommand(a, "void m() {}", "$ ADD []:m OK"), |
|
60 (a) -> assertCommand(a, "interface EX extends EEX {}", "$ ADD :EX NODEF"), |
|
61 (a) -> assertCommand(a, "56", "$ ADD [int]:$4 =56 OK"), |
|
62 (a) -> assertCommand(a, "class D { int hh; }", "$ REP :D OK$ OVERWROTE-UPDATE:D OK"), |
|
63 (a) -> assertCommandOutputStartsWith(a, "/set feedback normal", "| Feedback mode: normal") |
|
64 ); |
|
65 } finally { |
|
66 assertCommandCheckOutput(false, "/set feedback normal", s -> { |
|
67 }); |
|
68 } |
|
69 } |
|
70 |
|
71 public void testNewModeQuiet() { |
|
72 try { |
|
73 test( |
|
74 (a) -> assertCommandOutputStartsWith(a, "/set newmode nmq quiet normal", "| Created new feedback mode: nmq"), |
|
75 (a) -> assertCommand(a, "/set feedback nmq", ""), |
|
76 (a) -> assertCommand(a, "/se ne nmq2 q nor", ""), |
|
77 (a) -> assertCommand(a, "/se fee nmq2", ""), |
|
78 (a) -> assertCommand(a, "/set newmode nmc command normal", ""), |
|
79 (a) -> assertCommandOutputStartsWith(a, "/set feedback nmc", "| Feedback mode: nmc"), |
|
80 (a) -> assertCommandOutputStartsWith(a, "/set newmode nm", "| Created new feedback mode: nm"), |
|
81 (a) -> assertCommandOutputStartsWith(a, "/set feedback nm", "| Feedback mode: nm") |
|
82 ); |
|
83 } finally { |
|
84 assertCommandCheckOutput(false, "/set feedback normal", s -> { |
|
85 }); |
|
86 } |
|
87 } |
|
88 |
|
89 public void testSetError() { |
|
90 try { |
|
91 test( |
|
92 (a) -> assertCommandOutputStartsWith(a, "/set newmode te command normal", "| Created new feedback mode: te"), |
|
93 (a) -> assertCommand(a, "/set field te errorpre 'ERROR: '", ""), |
|
94 (a) -> assertCommandOutputStartsWith(a, "/set feedback te", ""), |
|
95 (a) -> assertCommandCheckOutput(a, "/set ", assertStartsWith("ERROR: The /set command requires arguments")), |
|
96 (a) -> assertCommandCheckOutput(a, "/set xyz", assertStartsWith("ERROR: Not a valid argument to /set")), |
|
97 (a) -> assertCommandCheckOutput(a, "/set f", assertStartsWith("ERROR: Ambiguous argument to /set")), |
|
98 (a) -> assertCommandCheckOutput(a, "/set feedback", assertStartsWith("ERROR: Expected a feedback mode")), |
|
99 (a) -> assertCommandCheckOutput(a, "/set feedback xyz", assertStartsWith("ERROR: Does not match any current feedback mode")), |
|
100 (a) -> assertCommandCheckOutput(a, "/set format", assertStartsWith("ERROR: Expected a feedback mode")), |
|
101 (a) -> assertCommandCheckOutput(a, "/set format xyz", assertStartsWith("ERROR: Does not match any current feedback mode")), |
|
102 (a) -> assertCommandCheckOutput(a, "/set format te", assertStartsWith("ERROR: Expected format missing")), |
|
103 (a) -> assertCommandCheckOutput(a, "/set format te aaa", assertStartsWith("ERROR: Format 'aaa' must be quoted")), |
|
104 (a) -> assertCommandCheckOutput(a, "/set format te 'aaa'", assertStartsWith("ERROR: At least one selector required")), |
|
105 (a) -> assertCommandCheckOutput(a, "/set format te 'aaa' frog", assertStartsWith("ERROR: Not a valid case")), |
|
106 (a) -> assertCommandCheckOutput(a, "/set format te 'aaa' import-frog", assertStartsWith("ERROR: Not a valid action")), |
|
107 (a) -> assertCommandCheckOutput(a, "/set newmode", assertStartsWith("ERROR: Expected new feedback mode")), |
|
108 (a) -> assertCommandCheckOutput(a, "/set newmode te", assertStartsWith("ERROR: Expected a new feedback mode name")), |
|
109 (a) -> assertCommandCheckOutput(a, "/set newmode x xyz", assertStartsWith("ERROR: Specify either 'command' or 'quiet'")), |
|
110 (a) -> assertCommandCheckOutput(a, "/set newmode x quiet y", assertStartsWith("ERROR: Does not match any current feedback mode")), |
|
111 (a) -> assertCommandCheckOutput(a, "/set prompt", assertStartsWith("ERROR: Expected a feedback mode")), |
|
112 (a) -> assertCommandCheckOutput(a, "/set prompt te", assertStartsWith("ERROR: Expected format missing")), |
|
113 (a) -> assertCommandCheckOutput(a, "/set prompt te aaa xyz", assertStartsWith("ERROR: Format 'aaa' must be quoted")), |
|
114 (a) -> assertCommandCheckOutput(a, "/set prompt te 'aaa' xyz", assertStartsWith("ERROR: Format 'xyz' must be quoted")), |
|
115 (a) -> assertCommandCheckOutput(a, "/set prompt", assertStartsWith("ERROR: Expected a feedback mode")), |
|
116 (a) -> assertCommandCheckOutput(a, "/set prompt te", assertStartsWith("ERROR: Expected format missing")), |
|
117 (a) -> assertCommandCheckOutput(a, "/set prompt te aaa", assertStartsWith("ERROR: Format 'aaa' must be quoted")), |
|
118 (a) -> assertCommandCheckOutput(a, "/set prompt te 'aaa'", assertStartsWith("ERROR: Expected format missing")), |
|
119 (a) -> assertCommandCheckOutput(a, "/set field", assertStartsWith("ERROR: Expected a feedback mode")), |
|
120 (a) -> assertCommandCheckOutput(a, "/set field xyz", assertStartsWith("ERROR: Does not match any current feedback mode: xyz")), |
|
121 (a) -> assertCommandCheckOutput(a, "/set field te xyz", assertStartsWith("ERROR: Not a valid field: xyz, must be one of: when")), |
|
122 (a) -> assertCommandCheckOutput(a, "/set field te action", assertStartsWith("ERROR: Expected format missing")), |
|
123 (a) -> assertCommandCheckOutput(a, "/set field te action 'act'", assertStartsWith("ERROR: At least one selector required")) |
|
124 ); |
|
125 } finally { |
|
126 assertCommandCheckOutput(false, "/set feedback normal", s -> { |
|
127 }); |
|
128 } |
|
129 } |
|
130 |
|
131 public void testSetHelp() { |
|
132 try { |
|
133 test( |
|
134 (a) -> assertCommandOutputContains(a, "/help /set", "command to launch"), |
|
135 (a) -> assertCommandOutputContains(a, "/help /set format", "vardecl"), |
|
136 (a) -> assertCommandOutputContains(a, "/hel /se for", "vardecl"), |
|
137 (a) -> assertCommandOutputContains(a, "/help /set editor", "temporary file") |
|
138 ); |
|
139 } finally { |
|
140 assertCommandCheckOutput(false, "/set feedback normal", s -> { |
|
141 }); |
|
142 } |
|
143 } |
|
144 |
|
145 public void testSetHelpError() { |
|
146 try { |
|
147 test( |
|
148 (a) -> assertCommandOutputStartsWith(a, "/set newmode te command normal", "| Created new feedback mode: te"), |
|
149 (a) -> assertCommand(a, "/set field te errorpre 'ERROR: '", ""), |
|
150 (a) -> assertCommandOutputStartsWith(a, "/set feedback te", "| Feedback mode: te"), |
|
151 (a) -> assertCommandOutputContains(a, "/help /set xyz", "ERROR: Not a valid argument to /set: xyz"), |
|
152 (a) -> assertCommandOutputContains(a, "/help /set f", "ERROR: Ambiguous argument to /set: f") |
|
153 ); |
|
154 } finally { |
|
155 assertCommandCheckOutput(false, "/set feedback normal", s -> { |
|
156 }); |
|
157 } |
|
158 } |
|
159 } |