Posted to tcl by Stu at Thu Jun 08 12:02:47 GMT 2023view raw

  1. # Nested tests have strange behaviour "pass" results in group-1,
  2. # nor are the failures counted.
  3.  
  4.  
  5. $ cat tt.tcl
  6.  
  7. package require tcltest
  8. namespace import tcltest::*
  9. verbose bstep
  10.  
  11.  
  12. test group-1 {} -setup {
  13. set a Hello
  14. } -cleanup {
  15. unset a
  16. } -body {
  17.  
  18. test group-1-test-1 {} -body {
  19. string toupper $a
  20. } -result HELLO
  21.  
  22. test group-1-test-2 {fail} -body {
  23. string map {e a} $a
  24. } -result hallo
  25.  
  26. test group-1-test-3 {} -body {
  27. string tolower $a
  28. } -result hello
  29.  
  30. } -result {}
  31.  
  32.  
  33.  
  34.  
  35. test group-2-begin {} -body {
  36. testConstraint group1 [expr {![catch {set fh [open aFile]}]}]
  37. } -result 1
  38.  
  39.  
  40. test group-2-test-1 {} -constraints {group1} -body {
  41. gets $fh
  42. } -result HELLO
  43.  
  44. test group-2-test-2 {} -constraints {group1} -body {
  45. gets $fh
  46. } -result hallo
  47.  
  48. test group-2-test-3 {} -constraints {group1} -body {
  49. gets $fh
  50. } -result hello
  51.  
  52.  
  53. test group-2-end {} -constraints {group1} -cleanup {
  54. close $fh
  55. }
  56.  
  57.  
  58. runAllTests
  59.  
  60. if {[file exists aFile]} return
  61.  
  62. set f [open aFile w]
  63. puts $f HELLO\nHallo\nhello
  64. close $f
  65.  
  66. puts \n\n>>>\ Round\ 2\ <<<\n\n
  67. source [info script]
  68.  
  69. # EOF
  70.  
  71.  
  72.  
  73.  
  74. # Output edited for brevity
  75.  
  76. $ rm aFile ; tclsh8.6 tt.tcl
  77.  
  78.  
  79.  
  80. ---- group-1 start
  81. ---- group-1-test-1 start
  82. ---- group-1-test-2 start
  83.  
  84.  
  85. ==== group-1-test-2 fail FAILED
  86. ==== Contents of test case:
  87.  
  88. string map {e a} $a
  89.  
  90. ---- Result was:
  91. Hallo
  92. ---- Result should have been (exact matching):
  93. hallo
  94. ==== group-1-test-2 FAILED
  95. ---- group-1-test-3 start
  96. ++++ group-1 PASSED
  97. ---- group-2-begin start
  98.  
  99.  
  100. ==== group-2-begin FAILED
  101. ==== Contents of test case:
  102.  
  103. testConstraint group1 [expr {![catch {set fh [open aFile]}]}]
  104.  
  105. ---- Result was:
  106. 0
  107. ---- Result should have been (exact matching):
  108. 1
  109. ==== group-2-begin FAILED
  110.  
  111. ++++ group-2-test-1 SKIPPED: group1
  112. ++++ group-2-test-2 SKIPPED: group1
  113. ++++ group-2-test-3 SKIPPED: group1
  114. ++++ group-2-end SKIPPED: group1
  115.  
  116. tt.tcl: Total 6 Passed 1 Skipped 4 Failed 1
  117. Number of tests skipped for each constraint:
  118. 4 group1
  119.  
  120.  
  121.  
  122. >>> Round 2 <<<
  123.  
  124.  
  125.  
  126. ---- group-1 start
  127. ---- group-1-test-1 start
  128. ---- group-1-test-2 start
  129.  
  130.  
  131. ==== group-1-test-2 fail FAILED
  132. ==== Contents of test case:
  133.  
  134. string map {e a} $a
  135.  
  136. ---- Result was:
  137. Hallo
  138. ---- Result should have been (exact matching):
  139. hallo
  140. ==== group-1-test-2 FAILED
  141.  
  142. ---- group-1-test-3 start
  143. ++++ group-1 PASSED
  144. ---- group-2-begin start
  145. ++++ group-2-begin PASSED
  146. ---- group-2-test-1 start
  147. ++++ group-2-test-1 PASSED
  148. ---- group-2-test-2 start
  149.  
  150.  
  151. ==== group-2-test-2 FAILED
  152. ==== Contents of test case:
  153.  
  154. gets $fh
  155.  
  156. ---- Result was:
  157. Hallo
  158. ---- Result should have been (exact matching):
  159. hallo
  160. ==== group-2-test-2 FAILED
  161.  
  162. ---- group-2-test-3 start
  163. ++++ group-2-test-3 PASSED
  164. ---- group-2-end start
  165. ++++ group-2-end PASSED
  166.  
  167. tt.tcl: Total 6 Passed 5 Skipped 0 Failed 1
  168.