source: branches/blt4/tester/scripts/runview.tcl @ 4965

Last change on this file since 4965 was 3959, checked in by gah, 11 years ago

sync with trunk

File size: 7.9 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: runview - show details of a run with status/stdout
3#
4#  This component is used when examining a diff of type "status".
5#  It shows an overview of the run, including the exit status and
6#  the stdout/stderr.  This helps to visualize unexpected failures,
7#  and is also useful for negative testing, where tests are expected
8#  to fail but should show consistent error messages.
9# ======================================================================
10#  AUTHOR:  Michael McLennan, Purdue University
11#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
12#
13#  See the file "license.terms" for information on usage and
14#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15# ======================================================================
16package require Itk
17package require RapptureGUI
18
19namespace eval Rappture::Tester { # forward declaration }
20
21option add *RunView.headingFont {Arial -12 bold} widgetDefault
22option add *RunView.infoFont {Arial -12} widgetDefault
23option add *RunView.codeFont {Courier -12} widgetDefault
24option add *RunView.addedBackground #ccffcc widgetDefault
25option add *RunView.deletedBackground #ffcccc widgetDefault
26
27itcl::class Rappture::Tester::RunView {
28    inherit itk::Widget
29
30    itk_option define -testobj testObj TestObj ""
31    itk_option define -showdiffs showDiffs ShowDiffs "off"
32
33    itk_option define -addedbackground addedBackground Background ""
34    itk_option define -deletedbackground deletedBackground Background ""
35    itk_option define -infofont infoFont Font ""
36    itk_option define -codefont codeFont Font ""
37
38    constructor {args} { # defined later }
39
40    protected method _reload {}
41
42    private variable _dispatcher ""  ;# dispatcher for !events
43}
44
45# ----------------------------------------------------------------------
46# CONSTRUCTOR
47# ----------------------------------------------------------------------
48itcl::body Rappture::Tester::RunView::constructor {args} {
49    Rappture::dispatcher _dispatcher
50    $_dispatcher register !reload
51    $_dispatcher dispatch $this !reload "[itcl::code $this _reload]; list"
52
53    itk_component add overview {
54        frame $itk_interior.overview
55    }
56    pack $itk_component(overview) -fill x
57
58    # run failure icon on the left-hand side
59    itk_component add icon {
60        label $itk_component(overview).icon -image [Rappture::icon fail64]
61    }
62    grid $itk_component(icon) -row 0 -rowspan 6 -column 0 \
63        -sticky ne -padx {0 20}
64
65    # create label/value for "status" parameter
66    itk_component add lstatus {
67        label $itk_component(overview).lstatus -text "Status:"
68    } {
69        usual
70        rename -font -headingfont headingFont Font
71    }
72    grid $itk_component(lstatus) -row 0 -column 1 -sticky e
73
74    itk_component add vstatus {
75        label $itk_component(overview).vstatus -justify left -anchor w
76    } {
77        usual
78        rename -font -codefont codeFont Font
79    }
80    grid $itk_component(vstatus) -row 0 -column 2 -sticky w
81
82    itk_component add lstatus2 {
83        label $itk_component(overview).lstatus2 -text "Got status:"
84    } {
85        usual
86        rename -font -headingfont headingFont Font
87    }
88    grid $itk_component(lstatus2) -row 0 -column 1 -sticky e
89
90    itk_component add vstatus2 {
91        label $itk_component(overview).vstatus2 -justify left -anchor w
92    } {
93        usual
94        rename -font -codefont codeFont Font
95        rename -background -deletedbackground deletedBackground Background
96    }
97
98    # set up the layout to resize properly
99    grid columnconfigure $itk_component(overview) 2 -weight 1
100
101    # create an area to show the program output -- either as text or diffs
102    itk_component add body {
103        frame $itk_interior.body
104    }
105    pack $itk_component(body) -expand yes -fill both
106
107    # use this to show output text (-showdiffs no)
108    itk_component add output {
109        Rappture::Scroller $itk_component(body).scrl \
110            -xscrollmode auto -yscrollmode auto
111    }
112    itk_component add text {
113        text $itk_component(output).text -wrap none
114    }
115    $itk_component(output) contents $itk_component(text)
116
117    # use this to show output diffs (-showdiffs yes)
118    itk_component add diffs {
119        Rappture::Tester::StringDiffs $itk_component(body).diffs \
120            -title "Test output:" -title1 "Expected this:" -title2 "Got this:"
121    }
122
123    eval itk_initialize $args
124}
125
126itk::usual RunView {
127    keep -background -foreground -cursor
128    keep -headingfont -infofont -codefont
129}
130
131# ----------------------------------------------------------------------
132# USAGE: _reload
133#
134# Called internally to load run information from the -testobj XML
135# definition.
136# ----------------------------------------------------------------------
137itcl::body Rappture::Tester::RunView::_reload {} {
138    set testobj $itk_option(-testobj)
139
140    # find the test output to show, or blank
141    if {$testobj ne ""} {
142        if {$itk_option(-showdiffs)} {
143            set st1 [$testobj getTestInfo output.status]
144            set st2 [$testobj getRunInfo output.status]
145            if {$st1 ne $st2} {
146                # show the difference in status
147                $itk_component(lstatus) configure -text "Expected status:"
148                $itk_component(vstatus) configure -text $st1
149                $itk_component(vstatus2) configure -text $st2
150
151                grid $itk_component(lstatus2) -row 1 -column 1 -sticky e
152                grid $itk_component(vstatus2) -row 1 -column 2 -sticky w
153            } else {
154                # show the status as an ordinary label
155                $itk_component(lstatus) configure -text "Status:"
156                $itk_component(vstatus) configure -text $st1
157                grid forget $itk_component(lstatus2) $itk_component(vstatus2)
158            }
159
160            set log1 [$testobj getTestInfo output.log]
161            set log2 [$testobj getRunInfo output.log]
162            if {$log1 ne $log2} {
163                # show the output as a diff
164                $itk_component(diffs) show $log1 $log2
165                pack forget $itk_component(output)
166                pack $itk_component(diffs) -expand yes -fill both
167            } else {
168                # show the output as ordinary text
169                $itk_component(text) configure -state normal
170                $itk_component(text) delete 1.0 end
171                $itk_component(text) insert end $log1
172                $itk_component(text) configure -state disabled
173                pack forget $itk_component(diffs)
174                pack $itk_component(output) -expand yes -fill both
175            }
176
177            return
178        }
179        # not showing diffs -- show the original test
180        set st1 [$testobj getTestInfo output.status]
181        $itk_component(lstatus) configure -text "Status:"
182        $itk_component(vstatus) configure -text $st1
183        grid forget $itk_component(lstatus2) $itk_component(vstatus2)
184
185        $itk_component(text) configure -state normal
186        $itk_component(text) delete 1.0 end
187        $itk_component(text) insert end [$testobj getTestInfo output.log]
188        $itk_component(text) configure -state disabled
189        pack forget $itk_component(diffs)
190        pack $itk_component(output) -expand yes -fill both
191        return
192    }
193
194    # if all else fails, blank everything out
195    $itk_component(lstatus) configure -text "Status:"
196    $itk_component(vstatus) configure -text ""
197    grid forget $itk_component(lstatus2) $itk_component(vstatus2)
198    pack forget $itk_component(output) $itk_component(diffs)
199}
200
201# ----------------------------------------------------------------------
202# CONFIGURATION OPTIONS
203# ----------------------------------------------------------------------
204itcl::configbody Rappture::Tester::RunView::testobj {
205    $_dispatcher event -idle !reload
206}
207itcl::configbody Rappture::Tester::RunView::showdiffs {
208    if {![string is boolean -strict $itk_option(-showdiffs)]} {
209        error "bad value \"$itk_option(-showdiffs)\": should be boolean"
210    }
211    $_dispatcher event -idle !reload
212}
Note: See TracBrowser for help on using the repository browser.