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 automatic test suite. |
---|
7 | # Similar to main.tcl, but runs all tests automatically and exits with |
---|
8 | # status code zero if all tests pass. |
---|
9 | # |
---|
10 | # USAGE: auto.tcl ?-tool tool.xml? ?-testdir tests? |
---|
11 | # ====================================================================== |
---|
12 | # AUTHORS: Michael McLennan, Purdue University |
---|
13 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
14 | # |
---|
15 | # See the file "license.terms" for information on usage and |
---|
16 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
17 | # ====================================================================== |
---|
18 | #\ |
---|
19 | exec tclsh "$0" $* |
---|
20 | # ---------------------------------------------------------------------- |
---|
21 | # tclsh executes everything from here on... |
---|
22 | |
---|
23 | set testerdir [file dirname [file normalize [info script]]] |
---|
24 | lappend auto_path $testerdir |
---|
25 | |
---|
26 | # bring in the Rappture object system |
---|
27 | package require Rappture |
---|
28 | Rappture::objects::init |
---|
29 | Rappture::resources::load |
---|
30 | |
---|
31 | Rappture::getopts argv params { |
---|
32 | value -tool "" |
---|
33 | value -testdir "" |
---|
34 | } |
---|
35 | |
---|
36 | # If tool.xml and test directory locations are not given, try to find them. |
---|
37 | if {$params(-tool) == ""} { |
---|
38 | if {[file isfile tool.xml]} { |
---|
39 | set params(-tool) tool.xml |
---|
40 | } elseif {[file isfile [file join rappture tool.xml]]} { |
---|
41 | set params(-tool) [file join rappture tool.xml] |
---|
42 | } else { |
---|
43 | puts "Cannot find tool.xml" |
---|
44 | exit 1 |
---|
45 | } |
---|
46 | } elseif {![file isfile $params(-tool)]} { |
---|
47 | puts "Tool \"$params(-tool)\" does not exist" |
---|
48 | exit 1 |
---|
49 | } |
---|
50 | |
---|
51 | if {$params(-testdir) == ""} { |
---|
52 | set tooldir [file dirname $params(-tool)] |
---|
53 | if {[file isdirectory [file join $tooldir tests]]} { |
---|
54 | set params(-testdir) [file join $tooldir tests] |
---|
55 | } elseif {[file isdirectory [file join [file dirname $tooldir] tests]]} { |
---|
56 | set params(-testdir) [file join [file dirname $tooldir] tests] |
---|
57 | } else { |
---|
58 | puts "Cannot find test directory" |
---|
59 | exit 1 |
---|
60 | } |
---|
61 | } elseif {![file isdirectory $params(-testdir)]} { |
---|
62 | puts "Test directory \"$params(-testdir)\" does not exist" |
---|
63 | exit 1 |
---|
64 | } |
---|
65 | |
---|
66 | set installdir [file dirname [file normalize $params(-tool)]] |
---|
67 | set xmlobj [Rappture::library $params(-tool)] |
---|
68 | set TaskObj [Rappture::Task ::#auto $xmlobj $installdir] |
---|
69 | |
---|
70 | # tasks in the tester run quietly and discard results |
---|
71 | $TaskObj configure -jobstats "" -resultdir "" |
---|
72 | |
---|
73 | # Load all tests in the test directory |
---|
74 | # ---------------------------------------------------------------------- |
---|
75 | set testlist [glob -nocomplain -directory $params(-testdir) *.xml] |
---|
76 | if {[llength $testlist] == 0} { |
---|
77 | puts stderr "ERROR: no tests found in $params(-testdir)" |
---|
78 | exit 1 |
---|
79 | } |
---|
80 | |
---|
81 | set nerrors 0 |
---|
82 | foreach file [glob -nocomplain -directory $params(-testdir) *.xml] { |
---|
83 | set testobj [Rappture::Tester::Test ::#auto $TaskObj $file] |
---|
84 | if {[$testobj getTestInfo test.label] eq ""} { |
---|
85 | puts stderr "ERROR: Missing test label in $file" |
---|
86 | incr nerrors |
---|
87 | continue |
---|
88 | } |
---|
89 | |
---|
90 | set status [$testobj run] |
---|
91 | |
---|
92 | if {$status ne "finished"} { |
---|
93 | puts stderr "ERROR: test $file didn't finish -- $status" |
---|
94 | incr nerrors |
---|
95 | continue |
---|
96 | } |
---|
97 | if {[$testobj getResult] ne "Pass"} { |
---|
98 | set diffs [$testobj getDiffs] |
---|
99 | puts stderr "FAILED: $file ([llength $diffs] differences)" |
---|
100 | incr nerrors |
---|
101 | continue |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | if {$nerrors > 0} { |
---|
106 | set errs [expr {($nerrors == 1) ? "ERROR" : "ERRORS"}] |
---|
107 | puts stderr "\n$nerrors $errs TOTAL" |
---|
108 | } |
---|