Index: library/lib/nx-test.tcl =================================================================== diff -u -rb4e6c8da93f250a75e634cf9ecd317432cbd2199 -r4bc60e16c10fdbbb640b3019d4bdebdc469fdf55 --- library/lib/nx-test.tcl (.../nx-test.tcl) (revision b4e6c8da93f250a75e634cf9ecd317432cbd2199) +++ library/lib/nx-test.tcl (.../nx-test.tcl) (revision 4bc60e16c10fdbbb640b3019d4bdebdc469fdf55) @@ -5,7 +5,7 @@ # @file Simple regression test support for XOTcl / NX - nx::Class create nx::Test { + nx::Class create nx::test { # # Class Test is used to configure test instances, which can # be configured by the following parameters: @@ -22,46 +22,47 @@ :property {name ""} :property cmd :property {namespace ::} - :property {verbose 0} + :property {verbose:boolean 0} :property -accessor public {expected 1} - :property {count 1} + :property {count:integer 1} :property msg :property setResult :property errorReport :property pre :property post - :class variable success 0 - :class variable failure 0 - :class variable testfile "" - :class variable count 0 - :class variable ms 0 + :object property {count:integer 1} + :object variable success 0 + :object variable failure 0 + :object variable testfile "" + :object variable ms 0 + :object variable case "test" - :public class method success {} { + :public object method success {} { incr :success } - :public class method failure {} { + :public object method failure {} { incr :failure } - :public class method ms {ms:double} { + :public object method ms {ms:double} { set :ms [expr {${:ms} + $ms}] } - :public class method destroy {} { + :public object method destroy {} { lappend msg \ - file [file rootname [file tail ${:testfile}]] \ + Test-set [file rootname [file tail ${:testfile}]] \ tests [expr {${:success} + ${:failure}}] \ success ${:success} \ failure ${:failure} \ ms ${:ms} - puts "Summary: $msg" + puts "Summary: $msg\n" array set "" $::argv if {[info exists (-testlog)]} { set f [open $(-testlog) a]; puts $f $msg; close $f } next } - :public class method case {name arg:optional} { + :public object method case {name arg:optional} { # # Experimental version of Test case, which (1) accepts test case as argument # and (2) destroys all created objects on exit (auto cleanup) @@ -87,28 +88,15 @@ } } - :public class method parameter {name value:optional} { - if {[info exists value]} { - [self]::slot::$name default $value - [self]::slot::$name reconfigure - } else { - return [[self]::slot::$name $name default] - } - } - - :public class method new args { + :public object method new args { set testfile [file rootname [file tail [info script]]] set :testfile $testfile - if {[info exists :case]} { - if {![info exists :ccount(${:case})]} {set :ccount(${:case}) 0} - set :name $testfile/${:case}.[format %.3d [incr :ccount(${:case})]] - } else { - set :name $testfile/t.[format %.3d [incr :count]] - } - :create ${:name} -name ${:name} {*}$args + if {![info exists :ccount(${:case})]} {set :ccount(${:case}) 0} + set :name $testfile/${:case}.[format %.3d [incr :ccount(${:case})]] + :create ${:name} -name ${:name} -count ${:count} {*}$args } - :public class method run {} { + :public object method run {} { set startTime [clock clicks -milliseconds] foreach example [lsort [:info instances -closure]] { $example run @@ -139,26 +127,33 @@ #puts stderr "running test $c times" if {${:verbose}} {puts stderr "running test $c times"} if {$c > 1} { - set r0 [time {time {::namespace eval ${:namespace} ";"} $c}] - regexp {^(-?[0-9]+) +} $r0 _ mS0 + # + # The following line was used to calculate calling-overhead. + # deactivated for now, since sometimes the reported calling + # overhead was larger than the call. + # + #set r0 [time {time {::namespace eval ${:namespace} ";"} $c}] + #regexp {^(-?[0-9]+) +} $r0 _ mS0 set r1 [time {time {::namespace eval ${:namespace} ${:cmd}} $c}] #puts stderr "running {time {::namespace eval ${:namespace} ${:cmd}} $c} => $r1" regexp {^(-?[0-9]+) +} $r1 _ mS1 - set ms [expr {($mS1 - $mS0) * 1.0 / $c}] + #set ms [expr {($mS1 - $mS0) * 1.0 / $c}] + set ms [expr {$mS1 * 1.0 / $c}] # if for some reason the run of the test is faster than the # body-less eval, don't report negative values. - if {$ms < 0} {set ms 0.0} - puts stderr "[set :name]:\t[format %6.2f $ms]\tmms, ${:msg} (overhead [format %.2f [expr {$mS0*1.0/$c}]])" + #if {$ms < 0} {set ms 0.0} + #puts stderr "[set :name]:\t[format %6.2f $ms]\tmms, ${:msg} (overhead [format %.2f [expr {$mS0*1.0/$c}]])" + puts stderr "[set :name]:\t[format %6.2f $ms]\tmms, ${:msg}" } else { puts stderr "[set :name]: ${:msg} ok" } - ::nx::Test success + ::nx::test success } else { puts stderr "[set :name]:\tincorrect result for '${:msg}', expected:" - puts stderr "'${:expected}', got\n'$r'" + puts stderr "'${:expected}', got\n\"$r\"" puts stderr "\tin test file [info script]" if {[info exists :errorReport]} {eval [set :errorReport]} - ::nx::Test failure + ::nx::test failure # # Make sure that the script exits with an error code, but # unwind the callstack via return with an error code. Using @@ -168,7 +163,7 @@ :exit -1 } if {[info exists :post]} {:call "post" ${:post}} - ::nx::Test ms [expr {[clock clicks -milliseconds]-$startTime}] + ::nx::test ms [expr {[clock clicks -milliseconds]-$startTime}] :exitOff } @@ -199,14 +194,15 @@ set namespace [uplevel {::namespace current}] #puts stderr "eval in namespace $namespace" if {$msg ne ""} { - set t [nx::Test new -cmd $cmd -msg $msg -namespace $namespace] + set t [nx::test new -cmd $cmd -msg $msg -namespace $namespace] } else { - set t [nx::Test new -cmd $cmd -namespace $namespace] + set t [nx::test new -cmd $cmd -namespace $namespace] } $t expected $expected $t run nsf::__db_run_assertions } +nsf::log notice "Running test cases: [info script]"