Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/tests/history.test @ 25

Last change on this file since 25 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 7.9 KB
Line 
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 
16if {[lsearch [namespace children] ::tcltest] == -1} {
17    package require tcltest
18    namespace import -force ::tcltest::*
19}
20
21# The history command might be autoloaded...
22if {[catch {history}]} {
23    testConstraint history 0
24} else {
25    testConstraint history 1
26}
27
28if {[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
41test history-1.1 {event option} history {history event -1} \
42        {set b [format {A test %s} string]}
43test history-1.2 {event option} history {history event $num} \
44        {set a 12345}
45test history-1.3 {event option} history {history event [expr $num+2]} \
46        {Another test}
47test history-1.4 {event option} history {history event set} \
48        {set b [format {A test %s} string]}
49test history-1.5 {event option} history {history e "* a*"} \
50        {set a 12345}
51test history-1.6 {event option} history {catch {history event *gorp} msg} 1
52test history-1.7 {event option} history {
53    catch {history event *gorp} msg
54    set msg
55} {no event matches "*gorp"}
56test history-1.8 {event option} history {history event} \
57        {set b [format {A test %s} string]}
58test history-1.9 {event option} history {catch {history event 123 456} msg} 1
59test 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
66if {[testConstraint history]} {
67    set a 0
68    history redo -2
69}
70test history-2.1 {redo option} history {set a} 12345
71if {[testConstraint history]} {
72    set b 0
73    history redo
74}
75test history-2.2 {redo option} history {set b} {A test string}
76test history-2.3 {redo option} history {catch {history redo -3 -4}} 1
77test 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
84if {[testConstraint history]} {
85    history add "set a 444" exec
86}
87test history-3.1 {add option} history {set a} 444
88test history-3.2 {add option} history {catch {history add "set a 444" execGorp}} 1
89test 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"}
93test history-3.4 {add option} history {catch {history add "set a 444" a} msg} 1
94test 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"}
98if {[testConstraint history]} {
99    history add "set a 555" e
100}
101test history-3.6 {add option} history {set a} 555
102if {[testConstraint history]} {
103    history add "set a 666"
104}
105test history-3.7 {add option} history {set a} 555
106test history-3.8 {add option} history {catch {history add "set a 666" e f} msg} 1
107test 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
114if {[testConstraint history]} {
115    history change "A test value"
116}
117test history-4.1 {change option} history {history event [expr {[history n]-1}]} \
118        "A test value"
119if {[testConstraint history]} {
120    history ch "Another test" -1
121}
122test history-4.2 {change option} history {history e} "Another test"
123test history-4.3 {change option} history {history event [expr {[history n]-1}]} \
124        "A test value"
125test history-4.4 {change option} history {catch {history change Foo 4 10}} 1
126test 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?"}
130test history-4.6 {change option} history {
131    catch {history change Foo [expr {[history n]-4}]}
132} 1
133if {[testConstraint history]} {
134    set num [expr {[history n]-4}]
135}
136test 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
143if {[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}
149test 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]]
155test 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]]
159test history-5.3 {info option} history {catch {history i 2 3}} 1
160test history-5.4 {info option} history {
161    catch {history i 2 3} msg
162    set msg
163} {wrong # args: should be "history info ?count?"}
164test 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
173if {[testConstraint history]} {
174    history add "foo1"
175    history add "foo2"
176    history add "foo3"
177    history keep 2
178}
179test history-6.1 {keep option} history {history event [expr [history n]-1]} foo3
180test history-6.2 {keep option} history {history event -1} foo2
181test history-6.3 {keep option} history {catch {history event -3}} 1
182test history-6.4 {keep option} history {
183    catch {history event -3} msg
184    set msg
185} {event "-3" is too far in the past}
186if {[testConstraint history]} {
187    history k 5
188}
189test history-6.5 {keep option} history {history event -1} foo2
190test history-6.6 {keep option} history {history event -2} {}
191test history-6.7 {keep option} history {history event -3} {}
192test history-6.8 {keep option} history {history event -4} {}
193test history-6.9 {keep option} history {catch {history event -5}} 1
194test history-6.10 {keep option} history {catch {history keep 4 6}} 1
195test history-6.11 {keep option} history {
196    catch {history keep 4 6} msg
197    set msg
198} {wrong # args: should be "history keep ?count?"}
199test history-6.12 {keep option} history {catch {history keep}} 0
200test history-6.13 {keep option} history {
201    history keep
202} {5}
203test history-6.14 {keep option} history {catch {history keep -3}} 1
204test history-6.15 {keep option} history {
205    catch {history keep -3} msg
206    set msg
207} {illegal keep count "-3"}
208test 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
215if {[testConstraint history]} {
216    set num [history n]
217    history add "Testing"
218    history add "Testing2"
219}
220test history-7.1 {nextid option} history {history event} "Testing"
221test history-7.2 {nextid option} history {history next} [expr $num+2]
222test history-7.3 {nextid option} history {catch {history nextid garbage}} 1
223test 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
230if {[testConstraint history]} {
231    set num [history n]
232    history add "Testing"
233    history add "Testing2"
234}
235test history-8.1 {clear option} history {catch {history clear junk}} 1
236test history-8.2 {clear option} history {history clear} {}
237if {[testConstraint history]} {
238    history add "Testing"
239}
240test history-8.3 {clear option} history {history} {     1  Testing}
241
242# miscellaneous
243
244test history-9.1 {miscellaneous} history {catch {history gorp} msg} 1
245test 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
252return
Note: See TracBrowser for help on using the repository browser.