home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tcl7.4 / tests / rename.test < prev    next >
Encoding:
Text File  |  1994-12-18  |  2.5 KB  |  75 lines

  1. # Commands covered:  rename
  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. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # @(#) rename.test 1.8 94/12/17 16:20:21
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. # Must eliminate the "unknown" command while the test is running,
  18. # especially if the test is being run in a program with its
  19. # own special-purpose unknown command.
  20.  
  21. catch {rename unknown unknown.old}
  22.  
  23. catch {rename r2 {}}
  24. proc r1 {} {return "procedure r1"}
  25. rename r1 r2
  26. test rename-1.1 {simple renaming} {
  27.     r2
  28. } {procedure r1}
  29. test rename-1.2 {simple renaming} {
  30.     list [catch r1 msg] $msg
  31. } {1 {invalid command name "r1"}}
  32. rename r2 {}
  33. test rename-1.3 {simple renaming} {
  34.     list [catch r2 msg] $msg
  35. } {1 {invalid command name "r2"}}
  36.  
  37. # The test below is tricky because it renames a built-in command.
  38. # It's possible that the test procedure uses this command, so must
  39. # restore the command before calling test again.
  40.  
  41. rename list l.new
  42. set a [catch list msg1]
  43. set b [l.new a b c]
  44. rename l.new list
  45. set c [catch l.new msg2]
  46. set d [list 111 222]
  47. test 2.1 {renaming built-in command} {
  48.     list $a $msg1 $b $c $msg2 $d
  49. } {1 {invalid command name "list"} {a b c} 1 {invalid command name "l.new"} {111 222}}
  50.  
  51. test rename-3.1 {error conditions} {
  52.     list [catch {rename r1} msg] $msg $errorCode
  53. } {1 {wrong # args: should be "rename oldName newName"} NONE}
  54. test rename-3.2 {error conditions} {
  55.     list [catch {rename r1 r2 r3} msg] $msg $errorCode
  56. } {1 {wrong # args: should be "rename oldName newName"} NONE}
  57. test rename-3.3 {error conditions} {
  58.     proc r1 {} {}
  59.     proc r2 {} {}
  60.     list [catch {rename r1 r2} msg] $msg
  61. } {1 {can't rename to "r2": command already exists}}
  62. test rename-3.4 {error conditions} {
  63.     catch {rename r1 {}}
  64.     catch {rename r2 {}}
  65.     list [catch {rename r1 r2} msg] $msg
  66. } {1 {can't rename "r1":  command doesn't exist}}
  67. test rename-3.5 {error conditions} {
  68.     catch {rename _non_existent_command {}}
  69.     list [catch {rename _non_existent_command {}} msg] $msg
  70. } {1 {can't delete "_non_existent_command": command doesn't exist}}
  71.  
  72. catch {rename unknown {}}
  73. catch {rename unknown.old unknown}
  74. concat
  75.