sl@0
|
1 |
# Commands covered: rename
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# This file contains a collection of tests for one or more of the Tcl
|
sl@0
|
4 |
# built-in commands. Sourcing this file into Tcl runs the tests and
|
sl@0
|
5 |
# generates output for errors. No output means no errors were found.
|
sl@0
|
6 |
#
|
sl@0
|
7 |
# Copyright (c) 1991-1993 The Regents of the University of California.
|
sl@0
|
8 |
# Copyright (c) 1994 Sun Microsystems, Inc.
|
sl@0
|
9 |
# Copyright (c) 1998-1999 by Scriptics Corporation.
|
sl@0
|
10 |
#
|
sl@0
|
11 |
# See the file "license.terms" for information on usage and redistribution
|
sl@0
|
12 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
13 |
#
|
sl@0
|
14 |
# RCS: @(#) $Id: rename.test,v 1.10 2001/09/12 20:28:50 dgp Exp $
|
sl@0
|
15 |
|
sl@0
|
16 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
17 |
package require tcltest
|
sl@0
|
18 |
namespace import -force ::tcltest::*
|
sl@0
|
19 |
}
|
sl@0
|
20 |
|
sl@0
|
21 |
# Must eliminate the "unknown" command while the test is running,
|
sl@0
|
22 |
# especially if the test is being run in a program with its
|
sl@0
|
23 |
# own special-purpose unknown command.
|
sl@0
|
24 |
|
sl@0
|
25 |
catch {rename unknown unknown.old}
|
sl@0
|
26 |
|
sl@0
|
27 |
catch {rename r2 {}}
|
sl@0
|
28 |
proc r1 {} {return "procedure r1"}
|
sl@0
|
29 |
rename r1 r2
|
sl@0
|
30 |
test rename-1.1 {simple renaming} {
|
sl@0
|
31 |
r2
|
sl@0
|
32 |
} {procedure r1}
|
sl@0
|
33 |
test rename-1.2 {simple renaming} {
|
sl@0
|
34 |
list [catch r1 msg] $msg
|
sl@0
|
35 |
} {1 {invalid command name "r1"}}
|
sl@0
|
36 |
rename r2 {}
|
sl@0
|
37 |
test rename-1.3 {simple renaming} {
|
sl@0
|
38 |
list [catch r2 msg] $msg
|
sl@0
|
39 |
} {1 {invalid command name "r2"}}
|
sl@0
|
40 |
|
sl@0
|
41 |
# The test below is tricky because it renames a built-in command.
|
sl@0
|
42 |
# It's possible that the test procedure uses this command, so must
|
sl@0
|
43 |
# restore the command before calling test again.
|
sl@0
|
44 |
|
sl@0
|
45 |
rename list l.new
|
sl@0
|
46 |
set a [catch list msg1]
|
sl@0
|
47 |
set b [l.new a b c]
|
sl@0
|
48 |
rename l.new list
|
sl@0
|
49 |
set c [catch l.new msg2]
|
sl@0
|
50 |
set d [list 111 222]
|
sl@0
|
51 |
test rename-2.1 {renaming built-in command} {
|
sl@0
|
52 |
list $a $msg1 $b $c $msg2 $d
|
sl@0
|
53 |
} {1 {invalid command name "list"} {a b c} 1 {invalid command name "l.new"} {111 222}}
|
sl@0
|
54 |
|
sl@0
|
55 |
test rename-3.1 {error conditions} {
|
sl@0
|
56 |
list [catch {rename r1} msg] $msg $errorCode
|
sl@0
|
57 |
} {1 {wrong # args: should be "rename oldName newName"} NONE}
|
sl@0
|
58 |
test rename-3.2 {error conditions} {
|
sl@0
|
59 |
list [catch {rename r1 r2 r3} msg] $msg $errorCode
|
sl@0
|
60 |
} {1 {wrong # args: should be "rename oldName newName"} NONE}
|
sl@0
|
61 |
test rename-3.3 {error conditions} {
|
sl@0
|
62 |
proc r1 {} {}
|
sl@0
|
63 |
proc r2 {} {}
|
sl@0
|
64 |
list [catch {rename r1 r2} msg] $msg
|
sl@0
|
65 |
} {1 {can't rename to "r2": command already exists}}
|
sl@0
|
66 |
test rename-3.4 {error conditions} {
|
sl@0
|
67 |
catch {rename r1 {}}
|
sl@0
|
68 |
catch {rename r2 {}}
|
sl@0
|
69 |
list [catch {rename r1 r2} msg] $msg
|
sl@0
|
70 |
} {1 {can't rename "r1": command doesn't exist}}
|
sl@0
|
71 |
test rename-3.5 {error conditions} {
|
sl@0
|
72 |
catch {rename _non_existent_command {}}
|
sl@0
|
73 |
list [catch {rename _non_existent_command {}} msg] $msg
|
sl@0
|
74 |
} {1 {can't delete "_non_existent_command": command doesn't exist}}
|
sl@0
|
75 |
|
sl@0
|
76 |
catch {rename unknown {}}
|
sl@0
|
77 |
catch {rename unknown.old unknown}
|
sl@0
|
78 |
catch {rename bar {}}
|
sl@0
|
79 |
|
sl@0
|
80 |
if {[info command testdel] == "testdel"} {
|
sl@0
|
81 |
test rename-4.1 {reentrancy issues with command deletion and renaming} {
|
sl@0
|
82 |
set x {}
|
sl@0
|
83 |
testdel {} foo {lappend x deleted; rename bar {}; lappend x [info command bar]}
|
sl@0
|
84 |
rename foo bar
|
sl@0
|
85 |
lappend x |
|
sl@0
|
86 |
rename bar {}
|
sl@0
|
87 |
set x
|
sl@0
|
88 |
} {| deleted {}}
|
sl@0
|
89 |
test rename-4.2 {reentrancy issues with command deletion and renaming} {
|
sl@0
|
90 |
set x {}
|
sl@0
|
91 |
testdel {} foo {lappend x deleted; rename foo bar}
|
sl@0
|
92 |
rename foo {}
|
sl@0
|
93 |
set x
|
sl@0
|
94 |
} {deleted}
|
sl@0
|
95 |
test rename-4.3 {reentrancy issues with command deletion and renaming} {
|
sl@0
|
96 |
set x {}
|
sl@0
|
97 |
testdel {} foo {lappend x deleted; testdel {} foo {lappend x deleted2}}
|
sl@0
|
98 |
rename foo {}
|
sl@0
|
99 |
lappend x |
|
sl@0
|
100 |
rename foo {}
|
sl@0
|
101 |
set x
|
sl@0
|
102 |
} {deleted | deleted2}
|
sl@0
|
103 |
test rename-4.4 {reentrancy issues with command deletion and renaming} {
|
sl@0
|
104 |
set x {}
|
sl@0
|
105 |
testdel {} foo {lappend x deleted; rename foo bar}
|
sl@0
|
106 |
rename foo {}
|
sl@0
|
107 |
lappend x | [info command bar]
|
sl@0
|
108 |
} {deleted | {}}
|
sl@0
|
109 |
test rename-4.5 {reentrancy issues with command deletion and renaming} {
|
sl@0
|
110 |
set env(value) before
|
sl@0
|
111 |
interp create foo
|
sl@0
|
112 |
testdel foo cmd {set env(value) deleted}
|
sl@0
|
113 |
interp delete foo
|
sl@0
|
114 |
set env(value)
|
sl@0
|
115 |
} {deleted}
|
sl@0
|
116 |
test rename-4.6 {reentrancy issues with command deletion and renaming} {
|
sl@0
|
117 |
proc kill args {
|
sl@0
|
118 |
interp delete foo
|
sl@0
|
119 |
}
|
sl@0
|
120 |
set env(value) before
|
sl@0
|
121 |
interp create foo
|
sl@0
|
122 |
foo alias kill kill
|
sl@0
|
123 |
testdel foo cmd {set env(value) deleted; kill}
|
sl@0
|
124 |
list [catch {foo eval {rename cmd {}}} msg] $msg $env(value)
|
sl@0
|
125 |
} {0 {} deleted}
|
sl@0
|
126 |
test rename-4.7 {reentrancy issues with command deletion and renaming} {
|
sl@0
|
127 |
proc kill args {
|
sl@0
|
128 |
interp delete foo
|
sl@0
|
129 |
}
|
sl@0
|
130 |
set env(value) before
|
sl@0
|
131 |
interp create foo
|
sl@0
|
132 |
foo alias kill kill
|
sl@0
|
133 |
testdel foo cmd {set env(value) deleted; kill}
|
sl@0
|
134 |
list [catch {interp delete foo} msg] $msg $env(value)
|
sl@0
|
135 |
} {0 {} deleted}
|
sl@0
|
136 |
if {[info exists env(value)]} {
|
sl@0
|
137 |
unset env(value)
|
sl@0
|
138 |
}
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
# Save the unknown procedure which is modified by the following test.
|
sl@0
|
142 |
|
sl@0
|
143 |
catch {rename unknown unknown.old}
|
sl@0
|
144 |
|
sl@0
|
145 |
test rename-5.1 {repeated rename deletion and redefinition of same command} {
|
sl@0
|
146 |
set SAVED_UNKNOWN "proc unknown "
|
sl@0
|
147 |
append SAVED_UNKNOWN "\{[info args unknown.old]\} "
|
sl@0
|
148 |
append SAVED_UNKNOWN "\{[info body unknown.old]\}"
|
sl@0
|
149 |
|
sl@0
|
150 |
for {set i 0} {$i < 10} {incr i} {
|
sl@0
|
151 |
eval $SAVED_UNKNOWN
|
sl@0
|
152 |
tcl_wordBreakBefore "" 0
|
sl@0
|
153 |
rename tcl_wordBreakBefore {}
|
sl@0
|
154 |
rename unknown {}
|
sl@0
|
155 |
}
|
sl@0
|
156 |
} {}
|
sl@0
|
157 |
|
sl@0
|
158 |
catch {rename unknown {}}
|
sl@0
|
159 |
catch {rename unknown.old unknown}
|
sl@0
|
160 |
|
sl@0
|
161 |
|
sl@0
|
162 |
test rename-6.1 {old code invalidated (epoch incremented) when cmd with compile proc is renamed } {
|
sl@0
|
163 |
proc x {} {
|
sl@0
|
164 |
set a 123
|
sl@0
|
165 |
set b [incr a]
|
sl@0
|
166 |
}
|
sl@0
|
167 |
x
|
sl@0
|
168 |
rename incr incr.old
|
sl@0
|
169 |
proc incr {} {puts "new incr called!"}
|
sl@0
|
170 |
catch {x} msg
|
sl@0
|
171 |
set msg
|
sl@0
|
172 |
} {wrong # args: should be "incr"}
|
sl@0
|
173 |
|
sl@0
|
174 |
if {[info commands incr.old] != {}} {
|
sl@0
|
175 |
catch {rename incr {}}
|
sl@0
|
176 |
catch {rename incr.old incr}
|
sl@0
|
177 |
}
|
sl@0
|
178 |
::tcltest::cleanupTests
|
sl@0
|
179 |
return
|