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

# Nested tests have strange behaviour "pass" results in group-1,
# nor are the failures counted.


$ cat tt.tcl

package require tcltest
namespace import tcltest::*
verbose bstep


test group-1 {} -setup {
        set a Hello
} -cleanup {
        unset a
} -body {

        test group-1-test-1 {} -body {
                string toupper $a
        } -result HELLO

        test group-1-test-2 {fail} -body {
                string map {e a} $a
        } -result hallo

        test group-1-test-3 {} -body {
                string tolower $a
        } -result hello

} -result {}



        
test group-2-begin {} -body {
        testConstraint group1 [expr {![catch {set fh [open aFile]}]}]
} -result 1

        
test group-2-test-1 {} -constraints {group1} -body {
        gets $fh
} -result HELLO
        
test group-2-test-2 {} -constraints {group1} -body {
        gets $fh
} -result hallo
        
test group-2-test-3 {} -constraints {group1} -body {
        gets $fh
} -result hello


test group-2-end {} -constraints {group1} -cleanup {
        close $fh
}

        
runAllTests

if {[file exists aFile]} return

set f [open aFile w]
puts $f HELLO\nHallo\nhello
close $f

puts \n\n>>>\ Round\ 2\ <<<\n\n
source [info script]

# EOF




# Output edited for brevity

$ rm aFile ; tclsh8.6 tt.tcl



---- group-1 start
---- group-1-test-1 start
---- group-1-test-2 start


==== group-1-test-2 fail FAILED
==== Contents of test case:

                string map {e a} $a

---- Result was:
Hallo
---- Result should have been (exact matching):
hallo
==== group-1-test-2 FAILED
---- group-1-test-3 start
++++ group-1 PASSED
---- group-2-begin start


==== group-2-begin  FAILED
==== Contents of test case:

        testConstraint group1 [expr {![catch {set fh [open aFile]}]}]

---- Result was:
0
---- Result should have been (exact matching):
1
==== group-2-begin FAILED

++++ group-2-test-1 SKIPPED: group1
++++ group-2-test-2 SKIPPED: group1
++++ group-2-test-3 SKIPPED: group1
++++ group-2-end SKIPPED: group1

tt.tcl: Total   6       Passed  1       Skipped 4       Failed  1
Number of tests skipped for each constraint:
        4       group1



>>> Round 2 <<<



---- group-1 start
---- group-1-test-1 start
---- group-1-test-2 start


==== group-1-test-2 fail FAILED
==== Contents of test case:

                string map {e a} $a

---- Result was:
Hallo
---- Result should have been (exact matching):
hallo
==== group-1-test-2 FAILED

---- group-1-test-3 start
++++ group-1 PASSED
---- group-2-begin start
++++ group-2-begin PASSED
---- group-2-test-1 start
++++ group-2-test-1 PASSED
---- group-2-test-2 start


==== group-2-test-2  FAILED
==== Contents of test case:

        gets $fh

---- Result was:
Hallo
---- Result should have been (exact matching):
hallo
==== group-2-test-2 FAILED

---- group-2-test-3 start
++++ group-2-test-3 PASSED
---- group-2-end start  
++++ group-2-end PASSED  

tt.tcl: Total   6       Passed  5       Skipped 0       Failed  1