1 | # Commands covered: history |
---|
2 | # |
---|
3 | # This file contains a collection of tests for one or more of the Tcl |
---|
4 | # built-in commands. Sourcing this file into Tcl runs the tests and |
---|
5 | # generates output for errors. No output means no errors were found. |
---|
6 | # |
---|
7 | # Copyright (c) 1991-1993 The Regents of the University of California. |
---|
8 | # Copyright (c) 1994 Sun Microsystems, Inc. |
---|
9 | # Copyright (c) 1998-1999 by Scriptics Corporation. |
---|
10 | # |
---|
11 | # See the file "license.terms" for information on usage and redistribution |
---|
12 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | # |
---|
14 | # RCS: @(#) $Id: history.test,v 1.6 2004/05/19 12:43:03 dkf Exp $ |
---|
15 | |
---|
16 | if {[lsearch [namespace children] ::tcltest] == -1} { |
---|
17 | package require tcltest |
---|
18 | namespace import -force ::tcltest::* |
---|
19 | } |
---|
20 | |
---|
21 | # The history command might be autoloaded... |
---|
22 | if {[catch {history}]} { |
---|
23 | testConstraint history 0 |
---|
24 | } else { |
---|
25 | testConstraint history 1 |
---|
26 | } |
---|
27 | |
---|
28 | if {[testConstraint history]} { |
---|
29 | set num [history nextid] |
---|
30 | history keep 3 |
---|
31 | history add {set a 12345} |
---|
32 | history add {set b [format {A test %s} string]} |
---|
33 | history add {Another test} |
---|
34 | } else { |
---|
35 | # Dummy value, must be numeric |
---|
36 | set num 0 |
---|
37 | } |
---|
38 | |
---|
39 | # "history event" |
---|
40 | |
---|
41 | test history-1.1 {event option} history {history event -1} \ |
---|
42 | {set b [format {A test %s} string]} |
---|
43 | test history-1.2 {event option} history {history event $num} \ |
---|
44 | {set a 12345} |
---|
45 | test history-1.3 {event option} history {history event [expr $num+2]} \ |
---|
46 | {Another test} |
---|
47 | test history-1.4 {event option} history {history event set} \ |
---|
48 | {set b [format {A test %s} string]} |
---|
49 | test history-1.5 {event option} history {history e "* a*"} \ |
---|
50 | {set a 12345} |
---|
51 | test history-1.6 {event option} history {catch {history event *gorp} msg} 1 |
---|
52 | test history-1.7 {event option} history { |
---|
53 | catch {history event *gorp} msg |
---|
54 | set msg |
---|
55 | } {no event matches "*gorp"} |
---|
56 | test history-1.8 {event option} history {history event} \ |
---|
57 | {set b [format {A test %s} string]} |
---|
58 | test history-1.9 {event option} history {catch {history event 123 456} msg} 1 |
---|
59 | test history-1.10 {event option} history { |
---|
60 | catch {history event 123 456} msg |
---|
61 | set msg |
---|
62 | } {wrong # args: should be "history event ?event?"} |
---|
63 | |
---|
64 | # "history redo" |
---|
65 | |
---|
66 | if {[testConstraint history]} { |
---|
67 | set a 0 |
---|
68 | history redo -2 |
---|
69 | } |
---|
70 | test history-2.1 {redo option} history {set a} 12345 |
---|
71 | if {[testConstraint history]} { |
---|
72 | set b 0 |
---|
73 | history redo |
---|
74 | } |
---|
75 | test history-2.2 {redo option} history {set b} {A test string} |
---|
76 | test history-2.3 {redo option} history {catch {history redo -3 -4}} 1 |
---|
77 | test history-2.4 {redo option} history { |
---|
78 | catch {history redo -3 -4} msg |
---|
79 | set msg |
---|
80 | } {wrong # args: should be "history redo ?event?"} |
---|
81 | |
---|
82 | # "history add" |
---|
83 | |
---|
84 | if {[testConstraint history]} { |
---|
85 | history add "set a 444" exec |
---|
86 | } |
---|
87 | test history-3.1 {add option} history {set a} 444 |
---|
88 | test history-3.2 {add option} history {catch {history add "set a 444" execGorp}} 1 |
---|
89 | test history-3.3 {add option} history { |
---|
90 | catch {history add "set a 444" execGorp} msg |
---|
91 | set msg |
---|
92 | } {bad argument "execGorp": should be "exec"} |
---|
93 | test history-3.4 {add option} history {catch {history add "set a 444" a} msg} 1 |
---|
94 | test history-3.5 {add option} history { |
---|
95 | catch {history add "set a 444" a} msg |
---|
96 | set msg |
---|
97 | } {bad argument "a": should be "exec"} |
---|
98 | if {[testConstraint history]} { |
---|
99 | history add "set a 555" e |
---|
100 | } |
---|
101 | test history-3.6 {add option} history {set a} 555 |
---|
102 | if {[testConstraint history]} { |
---|
103 | history add "set a 666" |
---|
104 | } |
---|
105 | test history-3.7 {add option} history {set a} 555 |
---|
106 | test history-3.8 {add option} history {catch {history add "set a 666" e f} msg} 1 |
---|
107 | test history-3.9 {add option} history { |
---|
108 | catch {history add "set a 666" e f} msg |
---|
109 | set msg |
---|
110 | } {wrong # args: should be "history add event ?exec?"} |
---|
111 | |
---|
112 | # "history change" |
---|
113 | |
---|
114 | if {[testConstraint history]} { |
---|
115 | history change "A test value" |
---|
116 | } |
---|
117 | test history-4.1 {change option} history {history event [expr {[history n]-1}]} \ |
---|
118 | "A test value" |
---|
119 | if {[testConstraint history]} { |
---|
120 | history ch "Another test" -1 |
---|
121 | } |
---|
122 | test history-4.2 {change option} history {history e} "Another test" |
---|
123 | test history-4.3 {change option} history {history event [expr {[history n]-1}]} \ |
---|
124 | "A test value" |
---|
125 | test history-4.4 {change option} history {catch {history change Foo 4 10}} 1 |
---|
126 | test history-4.5 {change option} history { |
---|
127 | catch {history change Foo 4 10} msg |
---|
128 | set msg |
---|
129 | } {wrong # args: should be "history change newValue ?event?"} |
---|
130 | test history-4.6 {change option} history { |
---|
131 | catch {history change Foo [expr {[history n]-4}]} |
---|
132 | } 1 |
---|
133 | if {[testConstraint history]} { |
---|
134 | set num [expr {[history n]-4}] |
---|
135 | } |
---|
136 | test history-4.7 {change option} history { |
---|
137 | catch {history change Foo $num} msg |
---|
138 | set msg |
---|
139 | } "event \"$num\" is too far in the past" |
---|
140 | |
---|
141 | # "history info" |
---|
142 | |
---|
143 | if {[testConstraint history]} { |
---|
144 | set num [history n] |
---|
145 | history add set\ a\ {b\nc\ d\ e} |
---|
146 | history add {set b 1234} |
---|
147 | history add set\ c\ {a\nb\nc} |
---|
148 | } |
---|
149 | test history-5.1 {info option} history {history info} [format {%6d set a {b |
---|
150 | c d e} |
---|
151 | %6d set b 1234 |
---|
152 | %6d set c {a |
---|
153 | b |
---|
154 | c}} $num [expr $num+1] [expr $num+2]] |
---|
155 | test history-5.2 {info option} history {history i 2} [format {%6d set b 1234 |
---|
156 | %6d set c {a |
---|
157 | b |
---|
158 | c}} [expr $num+1] [expr $num+2]] |
---|
159 | test history-5.3 {info option} history {catch {history i 2 3}} 1 |
---|
160 | test history-5.4 {info option} history { |
---|
161 | catch {history i 2 3} msg |
---|
162 | set msg |
---|
163 | } {wrong # args: should be "history info ?count?"} |
---|
164 | test history-5.5 {info option} history {history} [format {%6d set a {b |
---|
165 | c d e} |
---|
166 | %6d set b 1234 |
---|
167 | %6d set c {a |
---|
168 | b |
---|
169 | c}} $num [expr $num+1] [expr $num+2]] |
---|
170 | |
---|
171 | # "history keep" |
---|
172 | |
---|
173 | if {[testConstraint history]} { |
---|
174 | history add "foo1" |
---|
175 | history add "foo2" |
---|
176 | history add "foo3" |
---|
177 | history keep 2 |
---|
178 | } |
---|
179 | test history-6.1 {keep option} history {history event [expr [history n]-1]} foo3 |
---|
180 | test history-6.2 {keep option} history {history event -1} foo2 |
---|
181 | test history-6.3 {keep option} history {catch {history event -3}} 1 |
---|
182 | test history-6.4 {keep option} history { |
---|
183 | catch {history event -3} msg |
---|
184 | set msg |
---|
185 | } {event "-3" is too far in the past} |
---|
186 | if {[testConstraint history]} { |
---|
187 | history k 5 |
---|
188 | } |
---|
189 | test history-6.5 {keep option} history {history event -1} foo2 |
---|
190 | test history-6.6 {keep option} history {history event -2} {} |
---|
191 | test history-6.7 {keep option} history {history event -3} {} |
---|
192 | test history-6.8 {keep option} history {history event -4} {} |
---|
193 | test history-6.9 {keep option} history {catch {history event -5}} 1 |
---|
194 | test history-6.10 {keep option} history {catch {history keep 4 6}} 1 |
---|
195 | test history-6.11 {keep option} history { |
---|
196 | catch {history keep 4 6} msg |
---|
197 | set msg |
---|
198 | } {wrong # args: should be "history keep ?count?"} |
---|
199 | test history-6.12 {keep option} history {catch {history keep}} 0 |
---|
200 | test history-6.13 {keep option} history { |
---|
201 | history keep |
---|
202 | } {5} |
---|
203 | test history-6.14 {keep option} history {catch {history keep -3}} 1 |
---|
204 | test history-6.15 {keep option} history { |
---|
205 | catch {history keep -3} msg |
---|
206 | set msg |
---|
207 | } {illegal keep count "-3"} |
---|
208 | test history-6.16 {keep option} history { |
---|
209 | catch {history keep butter} msg |
---|
210 | set msg |
---|
211 | } {illegal keep count "butter"} |
---|
212 | |
---|
213 | # "history nextid" |
---|
214 | |
---|
215 | if {[testConstraint history]} { |
---|
216 | set num [history n] |
---|
217 | history add "Testing" |
---|
218 | history add "Testing2" |
---|
219 | } |
---|
220 | test history-7.1 {nextid option} history {history event} "Testing" |
---|
221 | test history-7.2 {nextid option} history {history next} [expr $num+2] |
---|
222 | test history-7.3 {nextid option} history {catch {history nextid garbage}} 1 |
---|
223 | test history-7.4 {nextid option} history { |
---|
224 | catch {history nextid garbage} msg |
---|
225 | set msg |
---|
226 | } {wrong # args: should be "history nextid"} |
---|
227 | |
---|
228 | # "history clear" |
---|
229 | |
---|
230 | if {[testConstraint history]} { |
---|
231 | set num [history n] |
---|
232 | history add "Testing" |
---|
233 | history add "Testing2" |
---|
234 | } |
---|
235 | test history-8.1 {clear option} history {catch {history clear junk}} 1 |
---|
236 | test history-8.2 {clear option} history {history clear} {} |
---|
237 | if {[testConstraint history]} { |
---|
238 | history add "Testing" |
---|
239 | } |
---|
240 | test history-8.3 {clear option} history {history} { 1 Testing} |
---|
241 | |
---|
242 | # miscellaneous |
---|
243 | |
---|
244 | test history-9.1 {miscellaneous} history {catch {history gorp} msg} 1 |
---|
245 | test history-9.2 {miscellaneous} history { |
---|
246 | catch {history gorp} msg |
---|
247 | set msg |
---|
248 | } {bad option "gorp": must be add, change, clear, event, info, keep, nextid, or redo} |
---|
249 | |
---|
250 | # cleanup |
---|
251 | ::tcltest::cleanupTests |
---|
252 | return |
---|