source: trunk/tester/mainwin.tcl @ 1968

Last change on this file since 1968 was 1968, checked in by braffert, 14 years ago

Developing regression tester

File size: 6.2 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: mainwin - main application window for regression tester
3#
4#  This widget acts as the main window for the Rappture regression
5#  tester.  Constructor accepts the location of the tool.xml of the new
6#  version to be tested, and the location of a directory containg test
7#  xml files.
8# ======================================================================
9#  AUTHOR:  Ben Rafferty, Purdue University
10#  Copyright (c) 2010  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 Rappture
17package require RapptureGUI
18
19namespace eval Rappture::Tester::MainWin { #forward declaration }
20
21itcl::class Rappture::Tester::MainWin {
22    inherit itk::Toplevel
23
24    constructor {toolxml testdir args} { #defined later }
25    public method runAll {args}
26    public method runSelected {args}
27
28    private method selectionHandler {}
29    private method runTest {id args}
30
31    private variable _testdir
32    private variable _toolxml
33    private variable _toolobj
34
35}
36
37# ----------------------------------------------------------------------
38# CONSTRUCTOR
39# ----------------------------------------------------------------------
40itcl::body Rappture::Tester::MainWin::constructor {toolxml testdir args} {
41    if {[file exists $toolxml]} {
42        set _toolxml $toolxml
43        set _toolobj [Rappture::library $_toolxml]
44    } else {
45        error "File \"$toolxml\" does not exist."
46    }
47
48    if {[file isdirectory $testdir]} {
49        set _testdir $testdir
50    } else {
51        error "Directory \"$testdir\" does not exist."
52    }
53
54    itk_component add pw {
55        panedwindow $itk_interior.pw
56    } {
57    }
58    pack $itk_component(pw) -expand yes -fill both
59
60    itk_component add tree {
61        Rappture::Tester::TestTree $itk_component(pw).tree \
62            -command "[itcl::code $itk_interior runSelected]" \
63            -testdir $_testdir \
64            -selectcommand "[itcl::code $itk_interior selectionHandler]"
65    }
66    $itk_component(pw) add $itk_component(tree)
67
68    itk_component add view {
69        Rappture::Tester::TestView $itk_component(pw).view \
70            [Rappture::Tool ::#auto $_toolobj [file dirname $_toolxml]]
71    }
72    $itk_component(pw) add $itk_component(view)
73
74    eval itk_initialize $args
75}
76
77# ----------------------------------------------------------------------
78# USAGE: runAll ?-force?
79#
80# When this method is invoked, all tests contained in the TestTree will
81# be ran sequentially.
82# ----------------------------------------------------------------------
83itcl::body Rappture::Tester::MainWin::runAll {args} {
84    set tests [$itk_component(tree) getTests]
85    foreach id $tests {
86        runTest $id $args
87    }
88}
89
90# ----------------------------------------------------------------------
91# USAGE: runSelected ?-force?
92#
93# When this method is invoked, all tests that are currently selected
94# will be ran.  If a branch node (folder) is selected, all of its
95# descendant tests will be ran as well.
96# ----------------------------------------------------------------------
97itcl::body Rappture::Tester::MainWin::runSelected {args} {
98    set selected [$itk_component(tree) getSelected]
99    foreach id $selected {
100        runTest $id $args
101    }
102}
103
104# ----------------------------------------------------------------------
105# USAGE: runTest id ?-force?
106#
107# Called by runAll and runSelected to run a single test at tree node
108# specified by the given id.  In most cases, this method should not be
109# called directly.  A driver object is generated by the makeDriver
110# procedure in compare.tcl, and the results given by the new version are
111# compared to the test xml by the compare procedure in compare.tcl
112# ----------------------------------------------------------------------
113itcl::body Rappture::Tester::MainWin::runTest {id args} {
114    array set data [$itk_component(tree) getData $id]
115    if {$data(ran) && [lsearch -exact $args "-force"]==-1} {
116        # Already ran.  Skip.
117        return
118    }
119    set data(result) "Running"
120    $itk_component(tree) setData $id [array get data]
121
122    set driver [Rappture::Tester::makeDriver $_toolxml $data(testxml)]
123    set tool [Rappture::Tool ::#auto $driver [file dirname $_toolxml]]
124    foreach {status result} [eval $tool run] break
125    set data(ran) yes
126    if {$status == 0 && [Rappture::library isvalid $result]} {
127        set golden [Rappture::library $data(testxml)]
128        set diffs [Rappture::Tester::compare $golden $result "output"]
129        if {$diffs != ""} {
130            set data(result) Fail
131            set data(diffs) $diffs
132        } else {
133            set data(result) Pass
134        }
135        set data(runfile) [$tool getRunFile]
136    } else {
137        set data(result) Error
138        set data(runfile) ""
139    }
140    $itk_component(tree) setData $id [array get data]
141
142    # Call selectionHandler to refresh right hand side view
143    selectionHandler
144
145}
146
147# ----------------------------------------------------------------------
148# USAGE: selectionHandler
149#
150# Used internally to communicate between the test tree and the right
151# hand side whenever the tree's selection has changed.
152# ----------------------------------------------------------------------
153itcl::body Rappture::Tester::MainWin::selectionHandler {} {
154    array set data [$itk_component(tree) getData focus]
155    # Data array is empty for branch nodes
156    if {[array names data] != ""} {
157        if {$data(ran)} {
158            switch $data(result) {
159                Pass {$itk_component(view) showText "Test passed."}
160                Fail {$itk_component(view) showText "Diffs: $data(diffs)"}
161                Error {$itk_component(view) showText "Error while running test"}
162            }
163            if {$data(runfile) != ""} {
164                $itk_component(view) display $data(runfile) $data(testxml)
165            } else {
166                $itk_component(view) clear
167            }
168        } else {
169            $itk_component(view) showText "Test has not ben ran."
170            $itk_component(view) clear
171        }
172    } else {
173        $itk_component(view) showDefault
174    }
175}
176
Note: See TracBrowser for help on using the repository browser.