PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/uClinux-dist/user/tcl/tests/error.test

https://bitbucket.org/__wp__/mb-linux-msli
Unknown | 181 lines | 152 code | 29 blank | 0 comment | 0 complexity | daf9062d149ed5a6cdce0f06fbb45a4b MD5 | raw file
Possible License(s): AGPL-3.0, GPL-2.0, LGPL-2.0, MPL-2.0, ISC, BSD-3-Clause, LGPL-2.1, MPL-2.0-no-copyleft-exception, 0BSD, CC-BY-SA-3.0, GPL-3.0, LGPL-3.0, AGPL-1.0, Unlicense
  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. # Copyright (c) 1998-1999 by Scriptics Corporation.
  10. #
  11. # See the file "license.terms" for information on usage and redistribution
  12. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  13. #
  14. # RCS: @(#) $Id: error.test,v 1.7 2000/04/10 17:18:58 ericm Exp $
  15. if {[lsearch [namespace children] ::tcltest] == -1} {
  16. package require tcltest
  17. namespace import -force ::tcltest::*
  18. }
  19. proc foo {} {
  20. global errorInfo
  21. set a [catch {format [error glorp2]} b]
  22. error {Human-generated}
  23. }
  24. proc foo2 {} {
  25. global errorInfo
  26. set a [catch {format [error glorp2]} b]
  27. error {Human-generated} $errorInfo
  28. }
  29. # Catch errors occurring in commands and errors from "error" command
  30. test error-1.1 {simple errors from commands} {
  31. catch {format [string index]} b
  32. } 1
  33. test error-1.2 {simple errors from commands} {
  34. catch {format [string index]} b
  35. set b
  36. } {wrong # args: should be "string index string charIndex"}
  37. test error-1.3 {simple errors from commands} {
  38. catch {format [string index]} b
  39. set errorInfo
  40. } {wrong # args: should be "string index string charIndex"
  41. while executing
  42. "string index"}
  43. test error-1.4 {simple errors from commands} {
  44. catch {error glorp} b
  45. } 1
  46. test error-1.5 {simple errors from commands} {
  47. catch {error glorp} b
  48. set b
  49. } glorp
  50. test error-1.6 {simple errors from commands} {
  51. catch {catch a b c} b
  52. } 1
  53. test error-1.7 {simple errors from commands} {
  54. catch {catch a b c} b
  55. set b
  56. } {wrong # args: should be "catch command ?varName?"}
  57. test error-1.8 {simple errors from commands} {nonPortable} {
  58. # This test is non-portable: it generates a memory fault on
  59. # machines like DEC Alphas (infinite recursion overflows
  60. # stack?)
  61. proc p {} {
  62. uplevel 1 catch p error
  63. }
  64. p
  65. } 0
  66. # Check errors nested in procedures. Also check the optional argument
  67. # to "error" to generate a new error trace.
  68. test error-2.1 {errors in nested procedures} {
  69. catch foo b
  70. } 1
  71. test error-2.2 {errors in nested procedures} {
  72. catch foo b
  73. set b
  74. } {Human-generated}
  75. test error-2.3 {errors in nested procedures} {
  76. catch foo b
  77. set errorInfo
  78. } {Human-generated
  79. while executing
  80. "error {Human-generated}"
  81. (procedure "foo" line 4)
  82. invoked from within
  83. "foo"}
  84. test error-2.4 {errors in nested procedures} {
  85. catch foo2 b
  86. } 1
  87. test error-2.5 {errors in nested procedures} {
  88. catch foo2 b
  89. set b
  90. } {Human-generated}
  91. test error-2.6 {errors in nested procedures} {
  92. catch foo2 b
  93. set errorInfo
  94. } {glorp2
  95. while executing
  96. "error glorp2"
  97. (procedure "foo2" line 3)
  98. invoked from within
  99. "foo2"}
  100. # Error conditions related to "catch".
  101. test error-3.1 {errors in catch command} {
  102. list [catch {catch} msg] $msg
  103. } {1 {wrong # args: should be "catch command ?varName?"}}
  104. test error-3.2 {errors in catch command} {
  105. list [catch {catch a b c} msg] $msg
  106. } {1 {wrong # args: should be "catch command ?varName?"}}
  107. test error-3.3 {errors in catch command} {
  108. catch {unset a}
  109. set a(0) 22
  110. list [catch {catch {format 44} a} msg] $msg
  111. } {1 {couldn't save command result in variable}}
  112. catch {unset a}
  113. # More tests related to errorInfo and errorCode
  114. test error-4.1 {errorInfo and errorCode variables} {
  115. list [catch {error msg1 msg2 msg3} msg] $msg $errorInfo $errorCode
  116. } {1 msg1 msg2 msg3}
  117. test error-4.2 {errorInfo and errorCode variables} {
  118. list [catch {error msg1 {} msg3} msg] $msg $errorInfo $errorCode
  119. } {1 msg1 {msg1
  120. while executing
  121. "error msg1 {} msg3"} msg3}
  122. test error-4.3 {errorInfo and errorCode variables} {
  123. list [catch {error msg1 {}} msg] $msg $errorInfo $errorCode
  124. } {1 msg1 {msg1
  125. while executing
  126. "error msg1 {}"} NONE}
  127. test error-4.4 {errorInfo and errorCode variables} {
  128. set errorCode bogus
  129. list [catch {error msg1} msg] $msg $errorInfo $errorCode
  130. } {1 msg1 {msg1
  131. while executing
  132. "error msg1"} NONE}
  133. test error-4.5 {errorInfo and errorCode variables} {
  134. set errorCode bogus
  135. list [catch {error msg1 msg2 {}} msg] $msg $errorInfo $errorCode
  136. } {1 msg1 msg2 {}}
  137. # Errors in error command itself
  138. test error-5.1 {errors in error command} {
  139. list [catch {error} msg] $msg
  140. } {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
  141. test error-5.2 {errors in error command} {
  142. list [catch {error a b c d} msg] $msg
  143. } {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
  144. # Make sure that catch resets error information
  145. test error-6.1 {catch must reset error state} {
  146. catch {error outer [catch {error inner inner.errorInfo inner.errorCode}]}
  147. list $errorCode $errorInfo
  148. } {NONE 1}
  149. # cleanup
  150. catch {rename p ""}
  151. ::tcltest::cleanupTests
  152. return