os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/rename.test
Update contrib.
1 # Commands covered: rename
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.
14 # RCS: @(#) $Id: rename.test,v 1.10 2001/09/12 20:28:50 dgp Exp $
16 if {[lsearch [namespace children] ::tcltest] == -1} {
17 package require tcltest
18 namespace import -force ::tcltest::*
21 # Must eliminate the "unknown" command while the test is running,
22 # especially if the test is being run in a program with its
23 # own special-purpose unknown command.
25 catch {rename unknown unknown.old}
28 proc r1 {} {return "procedure r1"}
30 test rename-1.1 {simple renaming} {
33 test rename-1.2 {simple renaming} {
34 list [catch r1 msg] $msg
35 } {1 {invalid command name "r1"}}
37 test rename-1.3 {simple renaming} {
38 list [catch r2 msg] $msg
39 } {1 {invalid command name "r2"}}
41 # The test below is tricky because it renames a built-in command.
42 # It's possible that the test procedure uses this command, so must
43 # restore the command before calling test again.
46 set a [catch list msg1]
49 set c [catch l.new msg2]
51 test rename-2.1 {renaming built-in command} {
52 list $a $msg1 $b $c $msg2 $d
53 } {1 {invalid command name "list"} {a b c} 1 {invalid command name "l.new"} {111 222}}
55 test rename-3.1 {error conditions} {
56 list [catch {rename r1} msg] $msg $errorCode
57 } {1 {wrong # args: should be "rename oldName newName"} NONE}
58 test rename-3.2 {error conditions} {
59 list [catch {rename r1 r2 r3} msg] $msg $errorCode
60 } {1 {wrong # args: should be "rename oldName newName"} NONE}
61 test rename-3.3 {error conditions} {
64 list [catch {rename r1 r2} msg] $msg
65 } {1 {can't rename to "r2": command already exists}}
66 test rename-3.4 {error conditions} {
69 list [catch {rename r1 r2} msg] $msg
70 } {1 {can't rename "r1": command doesn't exist}}
71 test rename-3.5 {error conditions} {
72 catch {rename _non_existent_command {}}
73 list [catch {rename _non_existent_command {}} msg] $msg
74 } {1 {can't delete "_non_existent_command": command doesn't exist}}
76 catch {rename unknown {}}
77 catch {rename unknown.old unknown}
80 if {[info command testdel] == "testdel"} {
81 test rename-4.1 {reentrancy issues with command deletion and renaming} {
83 testdel {} foo {lappend x deleted; rename bar {}; lappend x [info command bar]}
89 test rename-4.2 {reentrancy issues with command deletion and renaming} {
91 testdel {} foo {lappend x deleted; rename foo bar}
95 test rename-4.3 {reentrancy issues with command deletion and renaming} {
97 testdel {} foo {lappend x deleted; testdel {} foo {lappend x deleted2}}
102 } {deleted | deleted2}
103 test rename-4.4 {reentrancy issues with command deletion and renaming} {
105 testdel {} foo {lappend x deleted; rename foo bar}
107 lappend x | [info command bar]
109 test rename-4.5 {reentrancy issues with command deletion and renaming} {
110 set env(value) before
112 testdel foo cmd {set env(value) deleted}
116 test rename-4.6 {reentrancy issues with command deletion and renaming} {
120 set env(value) before
123 testdel foo cmd {set env(value) deleted; kill}
124 list [catch {foo eval {rename cmd {}}} msg] $msg $env(value)
126 test rename-4.7 {reentrancy issues with command deletion and renaming} {
130 set env(value) before
133 testdel foo cmd {set env(value) deleted; kill}
134 list [catch {interp delete foo} msg] $msg $env(value)
136 if {[info exists env(value)]} {
141 # Save the unknown procedure which is modified by the following test.
143 catch {rename unknown unknown.old}
145 test rename-5.1 {repeated rename deletion and redefinition of same command} {
146 set SAVED_UNKNOWN "proc unknown "
147 append SAVED_UNKNOWN "\{[info args unknown.old]\} "
148 append SAVED_UNKNOWN "\{[info body unknown.old]\}"
150 for {set i 0} {$i < 10} {incr i} {
152 tcl_wordBreakBefore "" 0
153 rename tcl_wordBreakBefore {}
158 catch {rename unknown {}}
159 catch {rename unknown.old unknown}
162 test rename-6.1 {old code invalidated (epoch incremented) when cmd with compile proc is renamed } {
169 proc incr {} {puts "new incr called!"}
172 } {wrong # args: should be "incr"}
174 if {[info commands incr.old] != {}} {
175 catch {rename incr {}}
176 catch {rename incr.old incr}
178 ::tcltest::cleanupTests