source: trunk/tester/tester.tcl @ 2032

Last change on this file since 2032 was 2032, checked in by braffert, 13 years ago
  • Property svn:executable set to *
File size: 5.4 KB
Line 
1#! /bin/sh
2# ----------------------------------------------------------------------
3#  RAPPTURE REGRESSION TESTER
4#
5#  This program will read a set of test xml files typically located in
6#  a tool's "tests" subdirectory, and provide an interactive test suite.
7#  The test xml files should contain a complete set of inputs and
8#  outputs for one run of an application.  In each test xml, a label
9#  must be located at the path test.label.  Test labels may be organized
10#  hierarchically by using dots to separate components of the test label
11#  (example: roomtemp.1eV).  A description may optionally be located at
12#  the path test.description.  Input arguments are the path to the
13#  tool.xml of the version being tested, and the path the the directory
14#  containing a set of test xml files.  If the arguments are missing,
15#  the program will attempt to locate them automatically.
16#
17#  USAGE: tester.tcl ?-tool tool.xml? ?-testdir tests?
18# ======================================================================
19#  AUTHOR:  Ben Rafferty, Purdue University
20#  Copyright (c) 2010  Purdue Research Foundation
21#
22#  See the file "license.terms" for information on usage and
23#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
24# ======================================================================
25#\
26exec tclsh "$0" $*
27# ----------------------------------------------------------------------
28# wish executes everything from here on...
29
30# TODO: Won't need this once tied in with the rest of the package
31lappend auto_path [file dirname $argv0]
32
33package require Itk
34package require Rappture
35package require RapptureGUI
36
37Rappture::getopts argv params {
38    value -tool ""
39    value -testdir ""
40}
41
42# If tool.xml and test directory locations are not given, try to find them.
43if {$params(-tool) == ""} {
44    if {[file isfile tool.xml]} {
45        set params(-tool) tool.xml
46    } elseif {[file isfile [file join rappture tool.xml]]} {
47        set params(-tool) [file join rappture tool.xml]
48    } else {
49        puts "Cannot find tool.xml"
50        exit 1
51    }
52} elseif {![file isfile $params(-tool)]} {
53    puts "Tool \"$params(-tool)\" does not exist"
54    exit 1
55}
56
57if {$params(-testdir) == ""} {
58    set tooldir [file dirname $params(-tool)]
59    if {[file isdirectory [file join $tooldir tests]]} {
60        set params(-testdir) [file join $tooldir tests]
61    } elseif {[file isdirectory [file join [file dirname $tooldir] tests]]} {
62        set params(-testdir) [file join [file dirname $tooldir] tests]
63    } else {
64        puts "Cannot find test directory"
65        exit 1
66    }
67} elseif {![file isdirectory $params(-testdir)]} {
68    puts "Test directory \"$params(-testdir)\" does not exist"
69    exit 1
70}
71
72# ----------------------------------------------------------------------
73# INITIALIZE WINDOW
74# ----------------------------------------------------------------------
75wm title . "Rappture Regression Tester"
76panedwindow .pw
77
78.pw add [Rappture::Tester::TestTree .tree \
79    -testdir $params(-testdir) \
80    -toolxml $params(-tool) \
81    -selectcommand Rappture::Tester::selectionHandler]
82
83.pw add [frame .right]
84Rappture::Tester::TestView .right.view
85button .right.regoldenize -text "Regoldenize" -state disabled \
86    -command Rappture::Tester::regoldenize
87pack .right.regoldenize -side bottom -anchor e
88pack .right.view -side bottom -expand yes -fill both
89
90pack .pw -expand yes -fill both
91
92set lastsel ""
93
94# TODO: Handle resizing better
95# TODO: Fix error that occurs only when you click and hold on a test
96#       while the right hand side is empty.  Adding lastsel check
97#       removed the error, but tree selection still acts strange when
98#       holding down the mouse button.  selectionHandler actually gets
99#       invoked twice, somehow leading to an event dispatch error.
100#       If selectionHandler does NOT reconfigure the right side with the
101#       selected test, then no error occurs.
102
103# ----------------------------------------------------------------------
104# USAGE: selectionHandler ?-refresh?
105#
106# Used internally to communicate between the test tree and the right
107# hand side viewer.  Upon selecting a new tree node, pass the focused
108# node's data to the right hand side.  Use the -refresh option to force
109# the selected test to be re-displayed on the right side.
110# ----------------------------------------------------------------------
111proc Rappture::Tester::selectionHandler {args} {
112    puts sh
113    global lastsel
114    set test [.tree getTest]
115    if {$test != $lastsel || [lsearch $args "-refresh"] != -1} {
116#        .right.view configure -test $test
117        if {$test != "" && [$test hasRan] && [$test getResult] != "Error"} {
118            .right.regoldenize configure -state normal
119        } else {
120            .right.regoldenize configure -state disabled
121        }
122        set lastsel $test
123    }
124}
125
126# ----------------------------------------------------------------------
127# USAGE: regoldenize
128#
129# Regoldenizes the currently focused test case.  Displays a warning
130# message.  If confirmed, copy the test information from the existing
131# test xml into the new result, and write the new data into the test
132# xml.
133# ----------------------------------------------------------------------
134proc Rappture::Tester::regoldenize {} {
135    set test [.tree getTest]
136    set testxml [$test getTestxml]
137    if {[tk_messageBox -type yesno -icon warning -message "Are you sure you want to regoldenize?\n$testxml will be overwritten."]} {
138        $test regoldenize
139        .tree refresh
140        selectionHandler -refresh
141    }
142}
143
Note: See TracBrowser for help on using the repository browser.