source: trunk/tester/testview.tcl @ 2080

Last change on this file since 2080 was 2080, checked in by mmc, 13 years ago

Part 1 of a major reorganization of content. Moving "instant" to "builder"
and setting up "builder" more like the "gui" part as a package. Moving the
Rappture::object stuff from the builder into the main installation, so it
can be shared by the tester as well. Moving "driver" into gui/scripts
where it belongs. Creating a new "launcher.tcl" script that decides
which of the three parts to launch based on command line options. Still
need to sort out the Makefiles to get this all right...

File size: 10.1 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: testview - display the results of a test
3#
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.
7# ======================================================================
8#  AUTHOR:  Ben Rafferty, Purdue University
9#           Michael McLennan, Purdue University
10#  Copyright (c) 2010-2011  Purdue Research Foundation
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# ======================================================================
15package require Itk
16package require BLT
17
18namespace eval Rappture::Tester::TestView { #forward declaration }
19
20option add *TestView.font {Arial -12} widgetDefault
21option add *TestView.titleFont {Arial -18 bold} widgetDefault
22option add *TestView.statusFont {Arial -12 italic} widgetDefault
23option add *TestView.statusPassColor black widgetDefault
24option add *TestView.statusFailColor red widgetDefault
25option add *TestView*descScroller.width 3i widgetDefault
26option add *TestView*descScroller.height 1i widgetDefault
27
28itcl::class Rappture::Tester::TestView {
29    inherit itk::Widget
30
31    itk_option define -statuspasscolor statusPassColor StatusColor ""
32    itk_option define -statusfailcolor statusFailColor StatusColor ""
33    itk_option define -runcommand runCommand RunCommand ""
34
35    constructor {args} { #defined later }
36    public method show {args}
37
38    private method _doRun {}
39    private method _plural {n}
40
41    private variable _testobjs ""  ;# objects being displayed
42}
43
44# ----------------------------------------------------------------------
45# CONSTRUCTOR
46# ----------------------------------------------------------------------
47itcl::body Rappture::Tester::TestView::constructor {args} {
48
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]
53    }
54    pack $itk_component(run) -side right -anchor n
55
56    # shows the big icon for test: pass/fail
57    itk_component add statusicon {
58        label $itk_interior.sicon
59    }
60    pack $itk_component(statusicon) -side left -anchor n
61
62    # shows the name of the test
63    itk_component add title {
64        label $itk_interior.title -anchor w
65    } {
66        usual
67        rename -font -titlefont titleFont Font
68    }
69    pack $itk_component(title) -side top -anchor w
70
71    # shows the status of the test: pass/fail
72    itk_component add statusmesg {
73        label $itk_interior.smesg -anchor w
74    } {
75        usual
76        rename -font -statusfont statusFont Font
77        ignore -foreground
78    }
79    pack $itk_component(statusmesg) -side top -anchor w
80
81    # for the longer text describing the test
82    itk_component add descScroller {
83        Rappture::Scroller $itk_interior.descScroller \
84            -xscrollmode auto -yscrollmode auto
85    }
86    pack $itk_component(descScroller) -expand yes -fill both
87
88    itk_component add description {
89        text $itk_component(descScroller).desc -height 1 \
90            -wrap word -relief flat
91    }
92    $itk_component(descScroller) contents $itk_component(description)
93
94    eval itk_initialize $args
95}
96
97itk::usual TestView {
98    keep -background -foreground -cursor
99    keep -font -titlefont -statusfont
100}
101
102# ----------------------------------------------------------------------
103# USAGE: show <testObj> <testObj> ...
104#
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.
108# ----------------------------------------------------------------------
109itcl::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        }
114    }
115    set _testobjs $args
116
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                }
146                Running - Waiting {
147                    set smesg "Test waiting to run"
148                    set sicon [Rappture::icon wait64]
149                    set color $itk_option(-statuspasscolor)
150                }
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 {
168            array set states { ? 0  Pass 0  Fail 0  Running 0  Waiting 0  total 0 }
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            }
178
179            $itk_component(title) configure \
180                -text [string totitle [_plural $states(total)]]
181
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
235        }
236    }
237}
238
239# ----------------------------------------------------------------------
240# USAGE: _doRun
241#
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.
245# ----------------------------------------------------------------------
246itcl::body Rappture::Tester::TestView::_doRun {} {
247    if {[string length $itk_option(-runcommand)] > 0} {
248        uplevel #0 $itk_option(-runcommand) $_testobjs
249    }
250}
251
252# ----------------------------------------------------------------------
253# USAGE: _plural <num>
254#
255# Handy way of generating a plural string.  If <num> is 1, it returns
256# "1 test".  Otherwise it returns "<num> tests".
257# ----------------------------------------------------------------------
258itcl::body Rappture::Tester::TestView::_plural {num} {
259    if {$num == 1} {
260        return "1 test"
261    } else {
262        return "$num tests"
263    }
264}
Note: See TracBrowser for help on using the repository browser.