1 # Commands covered: history
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.
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.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 if {[lsearch [namespace children] ::tcltest] == -1} {
17 package require tcltest
18 namespace import -force ::tcltest::*
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
28 set num [history nextid]
30 history add {set a 12345}
31 history add {set b [format {A test %s} string]}
32 history add {Another test}
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} \
40 test history-1.3 {event option} {history event [expr $num+2]} \
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*"} \
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
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
57 } {wrong # args: should be "history event ?event?"}
63 test history-2.1 {redo option} {set a} 12345
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
71 } {wrong # args: should be "history redo ?event?"}
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
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
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
95 } {wrong # args: should be "history add event ?exec?"}
99 history change "A test value"
100 test history-4.1 {change option} {history event [expr {[history n]-1}]} \
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}]} \
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
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}]}
114 set num [expr {[history n]-4}]
115 test history-4.7 {change option} {
116 catch {history change Foo $num} msg
118 } "event \"$num\" is too far in the past"
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
131 c}} $num [expr $num+1] [expr $num+2]]
132 test history-5.2 {info option} {history i 2} [format {%6d set b 1234
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
140 } {wrong # args: should be "history info ?count?"}
141 test history-5.5 {info option} {history} [format {%6d set a {b
146 c}} $num [expr $num+1] [expr $num+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
160 } {event "-3" is too far in the past}
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
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} {
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
180 } {illegal keep count "-3"}
181 test history-6.16 {keep option} {
182 catch {history keep butter} msg
184 } {illegal keep count "butter"}
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
197 } {wrong # args: should be "history nextid"}
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}
211 test history-9.1 {miscellaneous} {catch {history gorp} msg} 1
212 test history-9.2 {miscellaneous} {
213 catch {history gorp} msg
215 } {bad option "gorp": must be add, change, clear, event, info, keep, nextid, or redo}
218 ::tcltest::cleanupTests