[1963] | 1 | # ---------------------------------------------------------------------- |
---|
[2019] | 2 | # COMPONENT: testview - display the results of a test |
---|
[1963] | 3 | # |
---|
[2077] | 4 | # Top part of right hand side of the regression tester. Displays an |
---|
| 5 | # overview of selected test cases, and offers a button for running |
---|
| 6 | # them. |
---|
[1963] | 7 | # ====================================================================== |
---|
| 8 | # AUTHOR: Ben Rafferty, Purdue University |
---|
[2077] | 9 | # Michael McLennan, Purdue University |
---|
| 10 | # Copyright (c) 2010-2011 Purdue Research Foundation |
---|
[1963] | 11 | # |
---|
| 12 | # See the file "license.terms" for information on usage and |
---|
| 13 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 14 | # ====================================================================== |
---|
| 15 | package require Itk |
---|
[2012] | 16 | package require BLT |
---|
[1963] | 17 | |
---|
[1968] | 18 | namespace eval Rappture::Tester::TestView { #forward declaration } |
---|
[1963] | 19 | |
---|
[2077] | 20 | option add *TestView.font {Arial -12} widgetDefault |
---|
| 21 | option add *TestView.titleFont {Arial -18 bold} widgetDefault |
---|
| 22 | option add *TestView.statusFont {Arial -12 italic} widgetDefault |
---|
| 23 | option add *TestView.statusPassColor black widgetDefault |
---|
| 24 | option add *TestView.statusFailColor red widgetDefault |
---|
| 25 | option add *TestView*descScroller.width 3i widgetDefault |
---|
| 26 | option add *TestView*descScroller.height 1i widgetDefault |
---|
[1963] | 27 | |
---|
[1968] | 28 | itcl::class Rappture::Tester::TestView { |
---|
| 29 | inherit itk::Widget |
---|
| 30 | |
---|
[2077] | 31 | itk_option define -statuspasscolor statusPassColor StatusColor "" |
---|
| 32 | itk_option define -statusfailcolor statusFailColor StatusColor "" |
---|
| 33 | itk_option define -runcommand runCommand RunCommand "" |
---|
[2019] | 34 | |
---|
[2027] | 35 | constructor {args} { #defined later } |
---|
[2077] | 36 | public method show {args} |
---|
[2019] | 37 | |
---|
[2077] | 38 | private method _doRun {} |
---|
| 39 | private method _plural {n} |
---|
[2053] | 40 | |
---|
[2077] | 41 | private variable _testobjs "" ;# objects being displayed |
---|
[1963] | 42 | } |
---|
| 43 | |
---|
[1965] | 44 | # ---------------------------------------------------------------------- |
---|
| 45 | # CONSTRUCTOR |
---|
| 46 | # ---------------------------------------------------------------------- |
---|
[2019] | 47 | itcl::body Rappture::Tester::TestView::constructor {args} { |
---|
| 48 | |
---|
[2077] | 49 | # run button to run selected tests |
---|
| 50 | itk_component add run { |
---|
| 51 | button $itk_interior.run -text "Run" -padx 12 -pady 12 \ |
---|
| 52 | -command [itcl::code $this _doRun] |
---|
[1963] | 53 | } |
---|
[2077] | 54 | pack $itk_component(run) -side right -anchor n |
---|
[1964] | 55 | |
---|
[2077] | 56 | # shows the big icon for test: pass/fail |
---|
| 57 | itk_component add statusicon { |
---|
| 58 | label $itk_interior.sicon |
---|
[2009] | 59 | } |
---|
[2077] | 60 | pack $itk_component(statusicon) -side left -anchor n |
---|
[2009] | 61 | |
---|
[2077] | 62 | # shows the name of the test |
---|
| 63 | itk_component add title { |
---|
| 64 | label $itk_interior.title -anchor w |
---|
[2010] | 65 | } { |
---|
[2077] | 66 | usual |
---|
| 67 | rename -font -titlefont titleFont Font |
---|
[2010] | 68 | } |
---|
[2077] | 69 | pack $itk_component(title) -side top -anchor w |
---|
[2010] | 70 | |
---|
[2077] | 71 | # shows the status of the test: pass/fail |
---|
| 72 | itk_component add statusmesg { |
---|
| 73 | label $itk_interior.smesg -anchor w |
---|
[2031] | 74 | } { |
---|
[2077] | 75 | usual |
---|
| 76 | rename -font -statusfont statusFont Font |
---|
| 77 | ignore -foreground |
---|
[2031] | 78 | } |
---|
[2077] | 79 | pack $itk_component(statusmesg) -side top -anchor w |
---|
[2031] | 80 | |
---|
[2077] | 81 | # for the longer text describing the test |
---|
| 82 | itk_component add descScroller { |
---|
| 83 | Rappture::Scroller $itk_interior.descScroller \ |
---|
[2053] | 84 | -xscrollmode auto -yscrollmode auto |
---|
| 85 | } |
---|
[2077] | 86 | pack $itk_component(descScroller) -expand yes -fill both |
---|
[2053] | 87 | |
---|
[2077] | 88 | itk_component add description { |
---|
| 89 | text $itk_component(descScroller).desc -height 1 \ |
---|
| 90 | -wrap word -relief flat |
---|
[2053] | 91 | } |
---|
[2077] | 92 | $itk_component(descScroller) contents $itk_component(description) |
---|
[2053] | 93 | |
---|
[1964] | 94 | eval itk_initialize $args |
---|
[1963] | 95 | } |
---|
| 96 | |
---|
[1966] | 97 | itk::usual TestView { |
---|
[2077] | 98 | keep -background -foreground -cursor |
---|
| 99 | keep -font -titlefont -statusfont |
---|
[1966] | 100 | } |
---|
| 101 | |
---|
[2008] | 102 | # ---------------------------------------------------------------------- |
---|
[2077] | 103 | # USAGE: show <testObj> <testObj> ... |
---|
[2008] | 104 | # |
---|
[2077] | 105 | # Loads one or more Test objects into the display. When a single |
---|
| 106 | # object is shown, we can display more detail. When several objects |
---|
| 107 | # are shown, we provide overview info. |
---|
[2008] | 108 | # ---------------------------------------------------------------------- |
---|
[2077] | 109 | itcl::body Rappture::Tester::TestView::show {args} { |
---|
| 110 | foreach obj $args { |
---|
| 111 | if {[catch {$obj isa Test} valid] || !$valid} { |
---|
| 112 | error "bad value \"$obj\": should be Test object" |
---|
| 113 | } |
---|
[2019] | 114 | } |
---|
[2077] | 115 | set _testobjs $args |
---|
[2019] | 116 | |
---|
[2077] | 117 | switch -- [llength $_testobjs] { |
---|
| 118 | 0 { |
---|
| 119 | # If an empty string is passed in then clear everything |
---|
| 120 | $itk_component(title) configure -text "" |
---|
| 121 | $itk_component(statusicon) configure -image "" |
---|
| 122 | $itk_component(statusmesg) configure -text "" |
---|
| 123 | $itk_component(description) configure -state normal |
---|
| 124 | $itk_component(description) delete 1.0 end |
---|
| 125 | $itk_component(description) configure -state disabled |
---|
| 126 | $itk_component(run) configure -state disabled |
---|
| 127 | } |
---|
| 128 | 1 { |
---|
| 129 | set obj [lindex $_testobjs 0] |
---|
| 130 | switch [$obj getResult] { |
---|
| 131 | ? { |
---|
| 132 | set smesg "Ready to run" |
---|
| 133 | set sicon [Rappture::icon test64] |
---|
| 134 | set color $itk_option(-statuspasscolor) |
---|
| 135 | } |
---|
| 136 | Pass { |
---|
| 137 | set smesg "Test passed" |
---|
| 138 | set sicon [Rappture::icon pass64] |
---|
| 139 | set color $itk_option(-statuspasscolor) |
---|
| 140 | } |
---|
| 141 | Fail { |
---|
| 142 | set smesg "Test failed" |
---|
| 143 | set sicon [Rappture::icon fail64] |
---|
| 144 | set color $itk_option(-statusfailcolor) |
---|
| 145 | } |
---|
[2080] | 146 | Running - Waiting { |
---|
| 147 | set smesg "Test waiting to run" |
---|
| 148 | set sicon [Rappture::icon wait64] |
---|
| 149 | set color $itk_option(-statuspasscolor) |
---|
| 150 | } |
---|
[2077] | 151 | default { error "unknown test state \"[$obj getResult]\"" } |
---|
| 152 | } |
---|
| 153 | set name [lindex [split [$obj getTestInfo test.label] |] end] |
---|
| 154 | $itk_component(title) configure -text "Test: $name" |
---|
| 155 | $itk_component(statusicon) configure -image $sicon |
---|
| 156 | $itk_component(statusmesg) configure -text $smesg -foreground $color |
---|
| 157 | $itk_component(description) configure -state normal |
---|
| 158 | $itk_component(description) delete 1.0 end |
---|
| 159 | set desc [string trim [$obj getTestInfo test.description]] |
---|
| 160 | if {$desc eq ""} { |
---|
| 161 | set desc "--" |
---|
| 162 | } |
---|
| 163 | $itk_component(description) insert 1.0 $desc |
---|
| 164 | $itk_component(description) configure -state disabled |
---|
| 165 | $itk_component(run) configure -state normal |
---|
| 166 | } |
---|
| 167 | default { |
---|
[2080] | 168 | array set states { ? 0 Pass 0 Fail 0 Running 0 Waiting 0 total 0 } |
---|
[2077] | 169 | foreach obj $_testobjs { |
---|
| 170 | incr states(total) |
---|
| 171 | incr states([$obj getResult]) |
---|
| 172 | } |
---|
| 173 | if {$states(total) == 1} { |
---|
| 174 | set thistest "This test" |
---|
| 175 | } else { |
---|
| 176 | set thistest "These tests" |
---|
| 177 | } |
---|
[2019] | 178 | |
---|
[2077] | 179 | $itk_component(title) configure \ |
---|
| 180 | -text [string totitle [_plural $states(total)]] |
---|
[2055] | 181 | |
---|
[2077] | 182 | switch -glob -- $states(Pass)/$states(Fail)/$states(?) { |
---|
| 183 | 0/0/* { |
---|
| 184 | set smesg "Ready to run" |
---|
| 185 | set sicon [Rappture::icon test64] |
---|
| 186 | set color $itk_option(-statuspasscolor) |
---|
| 187 | set desc "" |
---|
| 188 | } |
---|
| 189 | */0/0 { |
---|
| 190 | set smesg "$thistest passed" |
---|
| 191 | set sicon [Rappture::icon pass64] |
---|
| 192 | set color $itk_option(-statuspasscolor) |
---|
| 193 | set desc "" |
---|
| 194 | } |
---|
| 195 | 0/*/0 { |
---|
| 196 | set smesg "$thistest failed" |
---|
| 197 | set sicon [Rappture::icon fail64] |
---|
| 198 | set color $itk_option(-statusfailcolor) |
---|
| 199 | set desc "" |
---|
| 200 | } |
---|
| 201 | 0/*/* { |
---|
| 202 | if {$states(Fail) == 1} { |
---|
| 203 | set smesg "One of these tests failed" |
---|
| 204 | } else { |
---|
| 205 | set smesg "Some of these tests failed" |
---|
| 206 | } |
---|
| 207 | set sicon [Rappture::icon fail64] |
---|
| 208 | set color $itk_option(-statusfailcolor) |
---|
| 209 | set desc "[_plural $states(Fail)] failed\n[_plural $states(?)] need to run" |
---|
| 210 | } |
---|
| 211 | */*/0 { |
---|
| 212 | if {$states(Pass) == 1} { |
---|
| 213 | set smesg "One of these tests passed" |
---|
| 214 | } else { |
---|
| 215 | set smesg "Some of these tests passed" |
---|
| 216 | } |
---|
| 217 | set sicon [Rappture::icon test64] |
---|
| 218 | set color $itk_option(-statuspasscolor) |
---|
| 219 | set desc "[_plural $states(Fail)] failed\n[_plural $states(Pass)] passed" |
---|
| 220 | } |
---|
| 221 | default { |
---|
| 222 | set smesg "Some tests passed, some failed" |
---|
| 223 | set sicon [Rappture::icon fail64] |
---|
| 224 | set color $itk_option(-statusfailcolor) |
---|
| 225 | set desc "[_plural $states(Fail)] failed\n[_plural $states(Pass)] passed\n[_plural $states(?)] need to run" |
---|
| 226 | } |
---|
| 227 | } |
---|
| 228 | $itk_component(statusicon) configure -image $sicon |
---|
| 229 | $itk_component(statusmesg) configure -text $smesg -foreground $color |
---|
| 230 | $itk_component(description) configure -state normal |
---|
| 231 | $itk_component(description) delete 1.0 end |
---|
| 232 | $itk_component(description) insert end $desc |
---|
| 233 | $itk_component(description) configure -state disabled |
---|
| 234 | $itk_component(run) configure -state normal |
---|
[2031] | 235 | } |
---|
[2011] | 236 | } |
---|
[1968] | 237 | } |
---|
| 238 | |
---|
[2055] | 239 | # ---------------------------------------------------------------------- |
---|
[2077] | 240 | # USAGE: _doRun |
---|
[2055] | 241 | # |
---|
[2077] | 242 | # Invoked when the user presses the "Run" button to invoke the |
---|
| 243 | # -runcommand script for this widget. Invokes the command with |
---|
| 244 | # the current test objects appended as arguments. |
---|
[2055] | 245 | # ---------------------------------------------------------------------- |
---|
[2077] | 246 | itcl::body Rappture::Tester::TestView::_doRun {} { |
---|
| 247 | if {[string length $itk_option(-runcommand)] > 0} { |
---|
| 248 | uplevel #0 $itk_option(-runcommand) $_testobjs |
---|
[2012] | 249 | } |
---|
[1977] | 250 | } |
---|
| 251 | |
---|
[2055] | 252 | # ---------------------------------------------------------------------- |
---|
[2077] | 253 | # USAGE: _plural <num> |
---|
[2055] | 254 | # |
---|
[2077] | 255 | # Handy way of generating a plural string. If <num> is 1, it returns |
---|
| 256 | # "1 test". Otherwise it returns "<num> tests". |
---|
[2055] | 257 | # ---------------------------------------------------------------------- |
---|
[2077] | 258 | itcl::body Rappture::Tester::TestView::_plural {num} { |
---|
| 259 | if {$num == 1} { |
---|
| 260 | return "1 test" |
---|
[2034] | 261 | } else { |
---|
[2077] | 262 | return "$num tests" |
---|
| 263 | } |
---|
[2031] | 264 | } |
---|