/tcl6.7/tests/error.test

https://bitbucket.org/tickling/tcl67-ecos · Unknown · 174 lines · 146 code · 28 blank · 0 comment · 0 complexity · 4925d3f8cc6358811154159b7cc81630 MD5 · raw file

  1. # Commands covered: error, catch
  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 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies. The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose. It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /sprite/src/lib/tcl/tests/RCS/error.test,v 1.11 91/08/20 14:18:52 ouster Exp $ (Berkeley)
  17. if {[string compare test [info procs test]] == 1} then {source defs}
  18. proc foo {} {
  19. global errorInfo
  20. set a [catch {format [error glorp2]} b]
  21. error {Human-generated}
  22. }
  23. proc foo2 {} {
  24. global errorInfo
  25. set a [catch {format [error glorp2]} b]
  26. error {Human-generated} $errorInfo
  27. }
  28. # Catch errors occurring in commands and errors from "error" command
  29. test error-1.1 {simple errors from commands} {
  30. catch {format [string compare]} b
  31. } 1
  32. test error-1.2 {simple errors from commands} {
  33. catch {format [string compare]} b
  34. set b
  35. } {wrong # args: should be "string compare string1 string2"}
  36. test error-1.3 {simple errors from commands} {
  37. catch {format [string compare]} b
  38. set errorInfo
  39. } {wrong # args: should be "string compare string1 string2"
  40. while executing
  41. "string compare"
  42. invoked from within
  43. "format [string compare]..."}
  44. test error-1.4 {simple errors from commands} {
  45. catch {error glorp} b
  46. } 1
  47. test error-1.5 {simple errors from commands} {
  48. catch {error glorp} b
  49. set b
  50. } glorp
  51. test error-1.6 {simple errors from commands} {
  52. catch {catch a b c} b
  53. } 1
  54. test error-1.7 {simple errors from commands} {
  55. catch {catch a b c} b
  56. set b
  57. } {wrong # args: should be "catch command ?varName?"}
  58. test error-2.1 {simple errors from commands} {
  59. catch catch
  60. } 1
  61. # Check errors nested in procedures. Also check the optional argument
  62. # to "error" to generate a new error trace.
  63. test error-2.1 {errors in nested procedures} {
  64. catch foo b
  65. } 1
  66. test error-2.2 {errors in nested procedures} {
  67. catch foo b
  68. set b
  69. } {Human-generated}
  70. test error-2.3 {errors in nested procedures} {
  71. catch foo b
  72. set errorInfo
  73. } {Human-generated
  74. while executing
  75. "error {Human-generated}"
  76. (procedure "foo" line 4)
  77. invoked from within
  78. "foo"}
  79. test error-2.4 {errors in nested procedures} {
  80. catch foo2 b
  81. } 1
  82. test error-2.5 {errors in nested procedures} {
  83. catch foo2 b
  84. set b
  85. } {Human-generated}
  86. test error-2.6 {errors in nested procedures} {
  87. catch foo2 b
  88. set errorInfo
  89. } {glorp2
  90. while executing
  91. "error glorp2"
  92. invoked from within
  93. "format [error glorp2]..."
  94. (procedure "foo2" line 1)
  95. invoked from within
  96. "foo2"}
  97. # Error conditions related to "catch".
  98. test error-3.1 {errors in catch command} {
  99. list [catch {catch} msg] $msg
  100. } {1 {wrong # args: should be "catch command ?varName?"}}
  101. test error-3.2 {errors in catch command} {
  102. list [catch {catch a b c} msg] $msg
  103. } {1 {wrong # args: should be "catch command ?varName?"}}
  104. test error-3.3 {errors in catch command} {
  105. catch {unset a}
  106. set a(0) 22
  107. list [catch {catch {format 44} a} msg] $msg
  108. } {1 {couldn't save command result in variable}}
  109. catch {unset a}
  110. # More tests related to errorInfo and errorCode
  111. test error-4.1 {errorInfo and errorCode variables} {
  112. list [catch {error msg1 msg2 msg3} msg] $msg $errorInfo $errorCode
  113. } {1 msg1 msg2 msg3}
  114. test error-4.2 {errorInfo and errorCode variables} {
  115. list [catch {error msg1 {} msg3} msg] $msg $errorInfo $errorCode
  116. } {1 msg1 {msg1
  117. while executing
  118. "error msg1 {} msg3"} msg3}
  119. test error-4.3 {errorInfo and errorCode variables} {
  120. list [catch {error msg1 {}} msg] $msg $errorInfo $errorCode
  121. } {1 msg1 {msg1
  122. while executing
  123. "error msg1 {}"} NONE}
  124. test error-4.4 {errorInfo and errorCode variables} {
  125. set errorCode bogus
  126. list [catch {error msg1} msg] $msg $errorInfo $errorCode
  127. } {1 msg1 {msg1
  128. while executing
  129. "error msg1"} NONE}
  130. test error-4.5 {errorInfo and errorCode variables} {
  131. set errorCode bogus
  132. list [catch {error msg1 msg2 {}} msg] $msg $errorInfo $errorCode
  133. } {1 msg1 msg2 {}}
  134. # Errors in error command itself
  135. test error-5.1 {errors in error command} {
  136. list [catch {error} msg] $msg
  137. } {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
  138. test error-5.2 {errors in error command} {
  139. list [catch {error a b c d} msg] $msg
  140. } {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
  141. # Make sure that catch resets error information
  142. test error-6.1 {catch must reset error state} {
  143. catch {error outer [catch {error inner inner.errorInfo inner.errorCode}]}
  144. list $errorCode $errorInfo
  145. } {NONE 1}
  146. return ""