1# common test setup script 2 3if {[info exists testsInited]} return 4 5package require Tcl 8.4 6 7if {[lsearch [namespace children] ::tcltest] == -1} { 8 package require tcltest 2.2 9 namespace import tcltest::* 10} 11 12singleProcess true ;# run without forking 13 14testsDirectory [file dirname [info script]] 15 16# if run from the tests directory, move one level up 17if {[pwd] eq [testsDirectory]} { 18 cd .. 19} 20 21temporaryDirectory [pwd] 22#workingDirectory [file dirname [testsDirectory]] 23 24# TextMate support on Mac OS X: run make before running any test from editor 25if {[info exists env(TM_FILENAME)]} { 26 if {[catch { exec make } msg]} { 27 puts stderr $msg 28 exit 1 29 } 30} 31 32proc readfile {filename} { 33 set fd [open $filename] 34 set data [read $fd] 35 close $fd 36 return $data 37} 38 39# extract version number from pkgIndex.tcl 40regexp {ifneeded Mk4tcl\s(\S+)\s} [readfile [workingDirectory]/pkgIndex.tcl] - version 41unset - 42 43# make sure the pkgIndex.tcl is found 44if {[lsearch $auto_path [workingDirectory]] < 0} { 45 set auto_path [linsert $auto_path 0 [workingDirectory]] 46} 47 48testConstraint 64bit [expr {$tcl_platform(wordSize) == 8}] 49testConstraint bigendian [expr {$tcl_platform(byteOrder) eq "bigEndian"}] 50testConstraint tcl$tcl_version 1 51 52proc assert {ok} { 53 if {!$ok} { 54 return -code error "assertion failed" 55 } 56} 57 58proc equal {expected result} { 59 if {$expected ne $result} { 60 return -code error [list expected $expected got $result] 61 } 62} 63 64proc match {pattern result} { 65 if {![string match $pattern $result]} { 66 return -code error [list pattern $pattern does not match $result] 67 } 68} 69 70set testsInited 1 71