# tcltest compatibilty/wrapper/extension # Common code set testinfo(verbose) 0 set testinfo(numpass) 0 set testinfo(stoponerror) 0 set testinfo(template) 0 set testinfo(numfail) 0 set testinfo(numskip) 0 set testinfo(numtests) 0 set testinfo(reported) 0 set testinfo(failed) {} set testinfo(source) [file tail $::argv0] # -verbose or $testverbose show OK/ERR of individual tests if {[lsearch $argv "-verbose"] >= 0 || [info exists env(testverbose)]} { incr testinfo(verbose) } # -template causes failed tests to output a template test that would succeed if {[lsearch $argv "-template"] >= 0} { incr testinfo(template) } # -stoponerror or $stoponerror stops on the first failed test if {[lsearch $argv "-stoponerror"] >= 0 || [info exists env(stoponerror)]} { incr testinfo(stoponerror) } proc needscmdcheck {what {packages {}}} { # Does it exist already? if {[info commands $what] ne ""} { return 1 } if {$packages eq ""} { # e.g. exec command is in exec package set packages $what } foreach p $packages { catch {package require $p} } if {[info commands $what] ne ""} { return 1 } return 0 } # Verifies the constraint/need # Returns 1 if the check passes or 0 if not proc needcheck {type what args} { # Returns 1 if the check passed or 0 if not if {$type eq "constraint"} { if {[info exists ::tcltest::testConstraints($what)] && $::tcltest::testConstraints($what)} { return 1 } return 0 } if {$type eq "cmd"} { lassign $what cmd subcmd if {![needscmdcheck $cmd $args]} { return 0 } if {$subcmd ne ""} { if {[testConstraint jim]} { if {$subcmd ni [$cmd -commands]} { return 0 } } else { if {[catch {$cmd $subcmd}]} { return 0 } } } return 1 } if {$type eq "package"} { if {[catch {package require $what}]} { return 0 } return 1 } if {$type eq "expr"} { return [uplevel #0 [list expr [lindex $args 0]]] } if {$type eq "eval"} { try { uplevel #0 [lindex $args 0] return 1 } on error msg { return 0 } } error "Unknown needs type: $type" } # needs skips all tests in the file if the requirement isn't met # constrains sets a constraint to 1 or 0 based on if the requirement is met. # # needs|constraint cmd {cmd ?subcmd?} ?packages? # # Checks that the command 'cmd' (and possibly 'cmd subcmd') exists # If necessary, loads the given packages # If used as a constraint, the constraint name is $cmd or $cmd-$subcmd # # needs constraint name # # Checks that the given constraint is set and is met (true) # If the constraint hasn't been set, this check fails (returns false) # # needs|constraint expr name # # Checks that the expression evaluates to true. # If used as a constraint, the constraint name is $name # # needs|constraint eval name