OSDN Git Service

Updated to tcl 8.4.1
[pf3gnuchains/sourceware.git] / tcl / tests / history.test
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$
15   
16 if {[lsearch [namespace children] ::tcltest] == -1} {
17     package require tcltest
18     namespace import -force ::tcltest::*
19 }
20
21 if {[catch {history}]} {
22     puts stdout "This version of Tcl was built without the history command;\n"
23     puts stdout "history tests will be skipped.\n"
24     ::tcltest::cleanupTests
25     return
26 }
27
28 set num [history nextid]
29 history keep 3
30 history add {set a 12345}
31 history add {set b [format {A test %s} string]}
32 history add {Another test}
33
34 # "history event"
35
36 test history-1.1 {event option} {history event -1} \
37         {set b [format {A test %s} string]}
38 test history-1.2 {event option} {history event $num} \
39         {set a 12345}
40 test history-1.3 {event option} {history event [expr $num+2]} \
41         {Another test}
42 test history-1.4 {event option} {history event set} \
43         {set b [format {A test %s} string]}
44 test history-1.5 {event option} {history e "* a*"} \
45         {set a 12345}
46 test history-1.6 {event option} {catch {history event *gorp} msg} 1
47 test history-1.7 {event option} {
48     catch {history event *gorp} msg
49     set msg
50 } {no event matches "*gorp"}
51 test history-1.8 {event option} {history event} \
52         {set b [format {A test %s} string]}
53 test history-1.9 {event option} {catch {history event 123 456} msg} 1
54 test history-1.10 {event option} {
55     catch {history event 123 456} msg
56     set msg
57 } {wrong # args: should be "history event ?event?"}
58
59 # "history redo"
60
61 set a 0
62 history redo -2
63 test history-2.1 {redo option} {set a} 12345
64 set b 0
65 history redo
66 test history-2.2 {redo option} {set b} {A test string}
67 test history-2.3 {redo option} {catch {history redo -3 -4}} 1
68 test history-2.4 {redo option} {
69     catch {history redo -3 -4} msg
70     set msg
71 } {wrong # args: should be "history redo ?event?"}
72
73 # "history add"
74
75 history add "set a 444" exec
76 test history-3.1 {add option} {set a} 444
77 test history-3.2 {add option} {catch {history add "set a 444" execGorp}} 1
78 test history-3.3 {add option} {
79     catch {history add "set a 444" execGorp} msg
80     set msg
81 } {bad argument "execGorp": should be "exec"}
82 test history-3.4 {add option} {catch {history add "set a 444" a} msg} 1
83 test history-3.5 {add option} {
84     catch {history add "set a 444" a} msg
85     set msg
86 } {bad argument "a": should be "exec"}
87 history add "set a 555" e
88 test history-3.6 {add option} {set a} 555
89 history add "set a 666"
90 test history-3.7 {add option} {set a} 555
91 test history-3.8 {add option} {catch {history add "set a 666" e f} msg} 1
92 test history-3.9 {add option} {
93     catch {history add "set a 666" e f} msg
94     set msg
95 } {wrong # args: should be "history add event ?exec?"}
96
97 # "history change"
98
99 history change "A test value"
100 test history-4.1 {change option} {history event [expr {[history n]-1}]} \
101         "A test value"
102 history ch "Another test" -1
103 test history-4.2 {change option} {history e} "Another test"
104 test history-4.3 {change option} {history event [expr {[history n]-1}]} \
105         "A test value"
106 test history-4.4 {change option} {catch {history change Foo 4 10}} 1
107 test history-4.5 {change option} {
108     catch {history change Foo 4 10} msg
109     set msg
110 } {wrong # args: should be "history change newValue ?event?"}
111 test history-4.6 {change option} {
112     catch {history change Foo [expr {[history n]-4}]}
113 } 1
114 set num [expr {[history n]-4}]
115 test history-4.7 {change option} {
116     catch {history change Foo $num} msg
117     set msg
118 } "event \"$num\" is too far in the past"
119
120 # "history info"
121
122 set num [history n]
123 history add set\ a\ {b\nc\ d\ e}
124 history add {set b 1234}
125 history add set\ c\ {a\nb\nc}
126 test history-5.1 {info option} {history info} [format {%6d  set a {b
127         c d e}
128 %6d  set b 1234
129 %6d  set c {a
130         b
131         c}} $num [expr $num+1] [expr $num+2]]
132 test history-5.2 {info option} {history i 2} [format {%6d  set b 1234
133 %6d  set c {a
134         b
135         c}} [expr $num+1] [expr $num+2]]
136 test history-5.3 {info option} {catch {history i 2 3}} 1
137 test history-5.4 {info option} {
138     catch {history i 2 3} msg
139     set msg
140 } {wrong # args: should be "history info ?count?"}
141 test history-5.5 {info option} {history} [format {%6d  set a {b
142         c d e}
143 %6d  set b 1234
144 %6d  set c {a
145         b
146         c}} $num [expr $num+1] [expr $num+2]]
147
148 # "history keep"
149
150 history add "foo1"
151 history add "foo2"
152 history add "foo3"
153 history keep 2
154 test history-6.1 {keep option} {history event [expr [history n]-1]} foo3
155 test history-6.2 {keep option} {history event -1} foo2
156 test history-6.3 {keep option} {catch {history event -3}} 1
157 test history-6.4 {keep option} {
158     catch {history event -3} msg
159     set msg
160 } {event "-3" is too far in the past}
161 history k 5
162 test history-6.5 {keep option} {history event -1} foo2
163 test history-6.6 {keep option} {history event -2} {}
164 test history-6.7 {keep option} {history event -3} {}
165 test history-6.8 {keep option} {history event -4} {}
166 test history-6.9 {keep option} {catch {history event -5}} 1
167 test history-6.10 {keep option} {catch {history keep 4 6}} 1
168 test history-6.11 {keep option} {
169     catch {history keep 4 6} msg
170     set msg
171 } {wrong # args: should be "history keep ?count?"}
172 test history-6.12 {keep option} {catch {history keep}} 0
173 test history-6.13 {keep option} {
174     history keep
175 } {5}
176 test history-6.14 {keep option} {catch {history keep -3}} 1
177 test history-6.15 {keep option} {
178     catch {history keep -3} msg
179     set msg
180 } {illegal keep count "-3"}
181 test history-6.16 {keep option} {
182     catch {history keep butter} msg
183     set msg
184 } {illegal keep count "butter"}
185
186 # "history nextid"
187
188 set num [history n]
189 history add "Testing"
190 history add "Testing2"
191 test history-7.1 {nextid option} {history event} "Testing"
192 test history-7.2 {nextid option} {history next} [expr $num+2]
193 test history-7.3 {nextid option} {catch {history nextid garbage}} 1
194 test history-7.4 {nextid option} {
195     catch {history nextid garbage} msg
196     set msg
197 } {wrong # args: should be "history nextid"}
198
199 # "history clear"
200
201 set num [history n]
202 history add "Testing"
203 history add "Testing2"
204 test history-8.1 {clear option} {catch {history clear junk}} 1
205 test history-8.2 {clear option} {history clear} {}
206 history add "Testing"
207 test history-8.3 {clear option} {history} {     1  Testing}
208
209 # miscellaneous
210
211 test history-9.1 {miscellaneous} {catch {history gorp} msg} 1
212 test history-9.2 {miscellaneous} {
213     catch {history gorp} msg
214     set msg
215 } {bad option "gorp": must be add, change, clear, event, info, keep, nextid, or redo}
216
217 # cleanup
218 ::tcltest::cleanupTests
219 return
220
221
222
223
224
225
226
227
228
229
230
231