diff options
Diffstat (limited to 'tests/rename.test')
| -rw-r--r-- | tests/rename.test | 87 |
1 files changed, 44 insertions, 43 deletions
diff --git a/tests/rename.test b/tests/rename.test index 1fa0441..cd90b55 100644 --- a/tests/rename.test +++ b/tests/rename.test @@ -1,35 +1,32 @@ # Commands covered: rename # -# This file contains a collection of tests for one or more of the Tcl built-in -# commands. Sourcing this file into Tcl runs the tests and generates output -# for errors. No output means no errors were found. +# This file contains a collection of tests for one or more of the Tcl +# built-in commands. Sourcing this file into Tcl runs the tests and +# generates output for errors. No output means no errors were found. # # Copyright (c) 1991-1993 The Regents of the University of California. # Copyright (c) 1994 Sun Microsystems, Inc. # Copyright (c) 1998-1999 by Scriptics Corporation. # -# See the file "license.terms" for information on usage and redistribution of -# this file, and for a DISCLAIMER OF ALL WARRANTIES. +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. if {[lsearch [namespace children] ::tcltest] == -1} { - package require tcltest 2 + package require tcltest namespace import -force ::tcltest::* } -::tcltest::loadTestedCommands -catch [list package require -exact Tcltest [info patchlevel]] - testConstraint testdel [llength [info commands testdel]] -# Must eliminate the "unknown" command while the test is running, especially -# if the test is being run in a program with its own special-purpose unknown -# command. +# Must eliminate the "unknown" command while the test is running, +# especially if the test is being run in a program with its +# own special-purpose unknown command. + catch {rename unknown unknown.old} - + catch {rename r2 {}} proc r1 {} {return "procedure r1"} rename r1 r2 - test rename-1.1 {simple renaming} { r2 } {procedure r1} @@ -41,9 +38,10 @@ test rename-1.3 {simple renaming} { list [catch r2 msg] $msg } {1 {invalid command name "r2"}} -# The test below is tricky because it renames a built-in command. It's -# possible that the test procedure uses this command, so must restore the -# command before calling test again. +# The test below is tricky because it renames a built-in command. +# It's possible that the test procedure uses this command, so must +# restore the command before calling test again. + rename list l.new set a [catch list msg1] set b [l.new a b c] @@ -56,27 +54,24 @@ test rename-2.1 {renaming built-in command} { test rename-3.1 {error conditions} { list [catch {rename r1} msg] $msg $errorCode -} {1 {wrong # args: should be "rename oldName newName"} {TCL WRONGARGS}} +} {1 {wrong # args: should be "rename oldName newName"} NONE} test rename-3.2 {error conditions} { list [catch {rename r1 r2 r3} msg] $msg $errorCode -} {1 {wrong # args: should be "rename oldName newName"} {TCL WRONGARGS}} -test rename-3.3 {error conditions} -setup { +} {1 {wrong # args: should be "rename oldName newName"} NONE} +test rename-3.3 {error conditions} { proc r1 {} {} proc r2 {} {} -} -returnCodes error -body { - rename r1 r2 -} -result {can't rename to "r2": command already exists} -test rename-3.4 {error conditions} -setup { + list [catch {rename r1 r2} msg] $msg +} {1 {can't rename to "r2": command already exists}} +test rename-3.4 {error conditions} { catch {rename r1 {}} catch {rename r2 {}} -} -returnCodes error -body { - rename r1 r2 -} -result {can't rename "r1": command doesn't exist} -test rename-3.5 {error conditions} -setup { + list [catch {rename r1 r2} msg] $msg +} {1 {can't rename "r1": command doesn't exist}} +test rename-3.5 {error conditions} { catch {rename _non_existent_command {}} -} -returnCodes error -body { - rename _non_existent_command {} -} -result {can't delete "_non_existent_command": command doesn't exist} + list [catch {rename _non_existent_command {}} msg] $msg +} {1 {can't delete "_non_existent_command": command doesn't exist}} catch {rename unknown {}} catch {rename unknown.old unknown} @@ -140,14 +135,23 @@ test rename-4.7 {reentrancy issues with command deletion and renaming} testdel { if {[info exists env(value)]} { unset env(value) } +test rename-4.8 {Bug a16752c252} testdel { + set x broken + testdel {} foo {set x ok} + proc foo args {} + rename foo {} + return -level 0 $x[unset x] +} ok # Save the unknown procedure which is modified by the following test. catch {rename unknown unknown.old} -set SAVED_UNKNOWN "proc unknown " -append SAVED_UNKNOWN [list [info args unknown.old] [info body unknown.old]] test rename-5.1 {repeated rename deletion and redefinition of same command} { + set SAVED_UNKNOWN "proc unknown " + append SAVED_UNKNOWN "\{[info args unknown.old]\} " + append SAVED_UNKNOWN "\{[info body unknown.old]\}" + for {set i 0} {$i < 10} {incr i} { eval $SAVED_UNKNOWN tcl_wordBreakBefore "" 0 @@ -159,27 +163,24 @@ test rename-5.1 {repeated rename deletion and redefinition of same command} { catch {rename unknown {}} catch {rename unknown.old unknown} -test rename-6.1 {old code invalidated (epoch incremented) when cmd with compile proc is renamed} -body { - proc x {} { + +test rename-6.1 {old code invalidated (epoch incremented) when cmd with compile proc is renamed } { + proc x {} { set a 123 set b [incr a] } x rename incr incr.old proc incr {} {puts "new incr called!"} - x -} -cleanup { + catch {x} msg rename incr {} rename incr.old incr -} -returnCodes error -result {wrong # args: should be "incr"} - + set msg +} {wrong # args: should be "incr"} + if {[info commands incr.old] != {}} { catch {rename incr {}} catch {rename incr.old incr} } ::tcltest::cleanupTests return - -# Local Variables: -# mode: tcl -# End: |
