Changeset 2139 for trunk/tester/scripts/test.tcl
- Timestamp:
- Mar 18, 2011, 8:45:29 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tester/scripts/test.tcl
r2136 r2139 24 24 public method getResult {} 25 25 public method getTestInfo {args} 26 public method getRunInfo {args} 26 27 public method getDiffs {args} 27 28 28 public method getRunobj {}29 29 public method getTestobj {} 30 30 public method getTestxml {} 31 31 32 32 public method run {args} 33 public method abort {} 33 34 public method regoldenize {} 34 35 … … 44 45 private method _setResult {name} 45 46 private method _computeDiffs {obj1 obj2 args} 47 private method _buildFailure {str} 46 48 47 49 # use this to add tests to the "run" queue … … 60 62 itcl::body Rappture::Tester::Test::constructor {toolobj testxml args} { 61 63 set _toolobj $toolobj 62 63 64 set _testxml $testxml 64 65 set _testobj [Rappture::library $testxml] 65 66 # HACK: Add a new input to differentiate between results67 $_testobj put input.TestRun.current "Golden"68 66 69 67 eval configure $args … … 113 111 114 112 # ---------------------------------------------------------------------- 113 # USAGE: getRunInfo <path> 114 # USAGE: getRunInfo children <path> 115 # USAGE: getRunInfo element ?-as type? <path> 116 # 117 # Returns info about the most recent run at the specified <path> in 118 # the XML. If the <path> is missing or misspelled, this method returns 119 # "" instead of an error. 120 # ---------------------------------------------------------------------- 121 itcl::body Rappture::Tester::Test::getRunInfo {args} { 122 if {[llength $args] == 1} { 123 set path [lindex $args 0] 124 return [$_runobj get $path] 125 } 126 return [eval $_runobj $args] 127 } 128 129 # ---------------------------------------------------------------------- 115 130 # USAGE: run ?-output callback path value path value ...? 116 131 # … … 132 147 foreach path [Rappture::entities -as path $_testobj input] { 133 148 if {[$_testobj element -as type $path.current] ne ""} { 134 puts " override: $path = [$_testobj get $path.current]"135 149 lappend args $path [$_testobj get $path.current] 136 150 } … … 147 161 } elseif {[Rappture::library isvalid $result]} { 148 162 set _runobj $result 149 set idiffs [_computeDiffs [$_toolobj xml] $_testobj -in input] 150 set odiffs [_computeDiffs $_testobj $_runobj -in output] 151 set _diffs [concat $idiffs $odiffs] 152 puts "DIFFS:" 153 foreach rec $_diffs { 154 puts ">> $rec" 155 } 156 157 # HACK: Add a new input to differentiate between results 158 $_runobj put input.TestRun.current "Test result" 159 160 # any differences from expected result mean test failed 161 if {[llength $_diffs] == 0} { 163 164 if {[$_testobj get output.status] ne "ok"} { 165 # expected test to fail, but it didn't 166 set idiffs [_computeDiffs [$_toolobj xml] $_runobj -in input] 167 set odiffs [_computeDiffs $_testobj $_runobj -what run] 168 set _diffs [concat $idiffs $odiffs] 169 _setResult "Fail" 170 } else { 171 set idiffs [_computeDiffs [$_toolobj xml] $_testobj -in input] 172 set odiffs [_computeDiffs $_testobj $_runobj -in output] 173 set _diffs [concat $idiffs $odiffs] 174 175 # any differences from expected result mean test failed 176 if {[llength $_diffs] == 0} { 177 _setResult "Pass" 178 } else { 179 _setResult "Fail" 180 } 181 } 182 return "finished" 183 } else { 184 set _runobj [_buildFailure $result] 185 if {[$_testobj get output.status] eq "failed" 186 && [$_testobj get output.log] eq $result} { 162 187 _setResult "Pass" 163 188 } else { 189 set idiffs [_computeDiffs [$_toolobj xml] $_runobj -in input] 190 set odiffs [_computeDiffs $_testobj $_runobj -what run] 191 set _diffs [concat $idiffs $odiffs] 164 192 _setResult "Fail" 165 193 } 166 194 return "finished" 195 } 196 } else { 197 set _runobj [_buildFailure $result] 198 if {[$_testobj get output.status] eq "failed" 199 && [$_testobj get output.log] eq $result} { 200 _setResult "Pass" 167 201 } else { 202 set idiffs [_computeDiffs [$_toolobj xml] $_runobj -in input] 203 set odiffs [_computeDiffs $_testobj $_runobj -what run] 204 set _diffs [concat $idiffs $odiffs] 168 205 _setResult "Fail" 169 return "failed: $result" 170 } 171 } else { 172 _setResult "Fail" 173 tk_messageBox -icon error -message "Tool failed: $result" 206 } 174 207 return "finished" 175 208 } 209 } 210 211 # ---------------------------------------------------------------------- 212 # USAGE: abort 213 # 214 # Causes the current test kicked off by the "run" method to be aborted. 215 # ---------------------------------------------------------------------- 216 itcl::body Rappture::Tester::Test::abort {} { 217 $_toolobj abort 176 218 } 177 219 … … 234 276 # otherwise, compare the golden test vs. the test result 235 277 return [_computeDiffs $_testobj $_runobj -in $path -detail max] 236 }237 238 # -----------------------------------------------------------------------239 # USAGE: getRunobj240 #241 # Returns the library object generated by the previous run of the test.242 # Throws an error if the test has not been run.243 # -----------------------------------------------------------------------244 itcl::body Rappture::Tester::Test::getRunobj {} {245 if {$_runobj eq ""} {246 error "Test has not yet been run."247 }248 return $_runobj249 278 } 250 279 … … 300 329 # ---------------------------------------------------------------------- 301 330 # USAGE: _computeDiffs <xmlObj1> <xmlObj2> ?-in xxx? \ 302 # ?-what value|attrs| all? ?-detail min|max?331 # ?-what value|attrs|run|all? ?-detail min|max? 303 332 # 304 333 # Used internally to compute differences between two different XML … … 324 353 Rappture::getopts args params { 325 354 value -in output 326 value -what all355 value -what "attrs value" 327 356 value -detail min 328 357 } 329 358 if {$params(-what) == "all"} { 330 set params(-what) "attrs value" 359 set params(-what) "attrs value run" 360 } 361 362 # handle any run output diffs first, so they appear at the top 363 # report this as one incident -- not separate reports for status/log 364 set rlist "" 365 if {[lsearch $params(-what) "run"] >= 0} { 366 set st1 [$obj1 get output.status] 367 set st2 [$obj2 get output.status] 368 if {$st1 ne $st2} { 369 # status changes are most serious 370 lappend rlist [list -what status -path output.status \ 371 -obj1 $obj1 -obj2 $obj2] 372 } else { 373 set log1 [$obj1 get output.log] 374 set log2 [$obj2 get output.log] 375 if {$log1 ne $log2} { 376 # flag log changes instead if status agrees 377 lappend rlist [list -what status -path output.log \ 378 -obj1 $obj1 -obj2 $obj2] 379 } 380 } 331 381 } 332 382 333 383 # scan through the specified sections or paths 334 set rlist ""335 384 foreach elem $params(-in) { 336 385 if {[string first . $elem] >= 0} { … … 359 408 lappend details -val1 $val1 -val2 $val2 360 409 361 puts "COMPARE: $path $obj1 =?= $obj2"362 puts " $val1 =?= $val2"363 410 if {$val1 eq "" || $val2 eq ""} { 364 411 lappend rlist [linsert $details 0 -what "value c"] … … 422 469 } 423 470 } 471 run { 472 # do nothing -- already handled above 473 474 # handled this comparison 475 set v2paths [lreplace $v2paths $i $i] 476 } 424 477 default { 425 error "bad part \"$part\": should be attrs, value "478 error "bad part \"$part\": should be attrs, value, run" 426 479 } 427 480 } … … 437 490 } 438 491 return $rlist 492 } 493 494 # ---------------------------------------------------------------------- 495 # USAGE: _buildFailure <output> 496 # 497 # Returns a new Rappture::library object that contains a copy of the 498 # original test with the given <output> and a failing status. This 499 # is used to represent the result of a test that aborts without 500 # producing a valid run.xml file. 501 # ---------------------------------------------------------------------- 502 itcl::body Rappture::Tester::Test::_buildFailure {output} { 503 set info "<?xml version=\"1.0\"?>\n[$_testobj xml]" 504 set obj [Rappture::LibraryObj ::#auto $info] 505 $obj remove test 506 507 $obj put output.time [clock format [clock seconds]] 508 $obj put output.status failed 509 $obj put output.user $::tcl_platform(user) 510 $obj put output.log $output 511 512 return $obj 439 513 } 440 514
Note: See TracChangeset
for help on using the changeset viewer.