PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/Src/gnu/tcl/tests/error.test

https://bitbucket.org/staceyoi/bb101repo
Unknown | 175 lines | 146 code | 29 blank | 0 comment | 0 complexity | c1876d315a6f43ad0d364cc952354389 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, LGPL-2.1, AGPL-3.0
  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 (c) 1991-1993 The Regents of the University of California.
  8. # Copyright (c) 1994-1996 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. # RCS: @(#) $Id: error.test,v 1.2 1998/09/14 18:40:08 stanton Exp $
  14. if {[string compare test [info procs test]] == 1} then {source defs}
  15. proc foo {} {
  16. global errorInfo
  17. set a [catch {format [error glorp2]} b]
  18. error {Human-generated}
  19. }
  20. proc foo2 {} {
  21. global errorInfo
  22. set a [catch {format [error glorp2]} b]
  23. error {Human-generated} $errorInfo
  24. }
  25. # Catch errors occurring in commands and errors from "error" command
  26. test error-1.1 {simple errors from commands} {
  27. catch {format [string compare]} b
  28. } 1
  29. test error-1.2 {simple errors from commands} {
  30. catch {format [string compare]} b
  31. set b
  32. } {wrong # args: should be "string compare string1 string2"}
  33. test error-1.3 {simple errors from commands} {
  34. catch {format [string compare]} b
  35. set errorInfo
  36. } {wrong # args: should be "string compare string1 string2"
  37. while executing
  38. "string compare"}
  39. test error-1.4 {simple errors from commands} {
  40. catch {error glorp} b
  41. } 1
  42. test error-1.5 {simple errors from commands} {
  43. catch {error glorp} b
  44. set b
  45. } glorp
  46. test error-1.6 {simple errors from commands} {
  47. catch {catch a b c} b
  48. } 1
  49. test error-1.7 {simple errors from commands} {
  50. catch {catch a b c} b
  51. set b
  52. } {wrong # args: should be "catch command ?varName?"}
  53. test error-1.8 {simple errors from commands} {nonPortable} {
  54. # This test is non-portable: it generates a memory fault on
  55. # machines like DEC Alphas (infinite recursion overflows
  56. # stack?)
  57. proc p {} {
  58. uplevel 1 catch p error
  59. }
  60. p
  61. } 0
  62. # Check errors nested in procedures. Also check the optional argument
  63. # to "error" to generate a new error trace.
  64. test error-2.1 {errors in nested procedures} {
  65. catch foo b
  66. } 1
  67. test error-2.2 {errors in nested procedures} {
  68. catch foo b
  69. set b
  70. } {Human-generated}
  71. test error-2.3 {errors in nested procedures} {
  72. catch foo b
  73. set errorInfo
  74. } {Human-generated
  75. while executing
  76. "error {Human-generated}"
  77. (procedure "foo" line 4)
  78. invoked from within
  79. "foo"}
  80. test error-2.4 {errors in nested procedures} {
  81. catch foo2 b
  82. } 1
  83. test error-2.5 {errors in nested procedures} {
  84. catch foo2 b
  85. set b
  86. } {Human-generated}
  87. test error-2.6 {errors in nested procedures} {
  88. catch foo2 b
  89. set errorInfo
  90. } {glorp2
  91. while executing
  92. "error glorp2"
  93. (procedure "foo2" line 3)
  94. invoked from within
  95. "foo2"}
  96. # Error conditions related to "catch".
  97. test error-3.1 {errors in catch command} {
  98. list [catch {catch} msg] $msg
  99. } {1 {wrong # args: should be "catch command ?varName?"}}
  100. test error-3.2 {errors in catch command} {
  101. list [catch {catch a b c} msg] $msg
  102. } {1 {wrong # args: should be "catch command ?varName?"}}
  103. test error-3.3 {errors in catch command} {
  104. catch {unset a}
  105. set a(0) 22
  106. list [catch {catch {format 44} a} msg] $msg
  107. } {1 {couldn't save command result in variable}}
  108. catch {unset a}
  109. # More tests related to errorInfo and errorCode
  110. test error-4.1 {errorInfo and errorCode variables} {
  111. list [catch {error msg1 msg2 msg3} msg] $msg $errorInfo $errorCode
  112. } {1 msg1 msg2 msg3}
  113. test error-4.2 {errorInfo and errorCode variables} {
  114. list [catch {error msg1 {} msg3} msg] $msg $errorInfo $errorCode
  115. } {1 msg1 {msg1
  116. while executing
  117. "error msg1 {} msg3"} msg3}
  118. test error-4.3 {errorInfo and errorCode variables} {
  119. list [catch {error msg1 {}} msg] $msg $errorInfo $errorCode
  120. } {1 msg1 {msg1
  121. while executing
  122. "error msg1 {}"} NONE}
  123. test error-4.4 {errorInfo and errorCode variables} {
  124. set errorCode bogus
  125. list [catch {error msg1} msg] $msg $errorInfo $errorCode
  126. } {1 msg1 {msg1
  127. while executing
  128. "error msg1"} NONE}
  129. test error-4.5 {errorInfo and errorCode variables} {
  130. set errorCode bogus
  131. list [catch {error msg1 msg2 {}} msg] $msg $errorInfo $errorCode
  132. } {1 msg1 msg2 {}}
  133. # Errors in error command itself
  134. test error-5.1 {errors in error command} {
  135. list [catch {error} msg] $msg
  136. } {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
  137. test error-5.2 {errors in error command} {
  138. list [catch {error a b c d} msg] $msg
  139. } {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
  140. # Make sure that catch resets error information
  141. test error-6.1 {catch must reset error state} {
  142. catch {error outer [catch {error inner inner.errorInfo inner.errorCode}]}
  143. list $errorCode $errorInfo
  144. } {NONE 1}
  145. catch {rename p ""}
  146. return ""