Debian Codegraph @

tests/defs

raw
1 # -*- tcl -*-
2 # This file contains support code for the MEMCHAN test suite. It is
3 # normally sourced by the individual files in the test suite before
4 # they run their tests. This improved approach to testing was designed
5 # and initially implemented by Mary Ann May-Pumphrey of Sun Microsystems.
6 #
7 # Copyright (c) 1990-1994 The Regents of the University of California.
8 # Copyright (c) 1994 Sun Microsystems, Inc.
9 #
10 # Modified 1995 Andreas Kupries ([email protected])
11 # Modified 1997 Andreas Kupries ([email protected])
12 #
13 # See the file "license.terms" for information on usage and redistribution
14 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 #
16 # CVS: $Id: defs,v 1.1 1999/05/11 18:08:07 aku Exp $
17
18
19 if {![info exists VERBOSE]} {
20 set VERBOSE 0
21 }
22 if {![info exists TESTS]} {
23 set TESTS {}
24 }
25
26 if ![info exists DLP] {
27 set DLP 0
28 }
29
30
31
32
33 # If tests are being run as root, issue a warning message and set a
34 # variable to prevent some tests from running at all.
35
36 set user {}
37 catch {set user [exec whoami]}
38 if {$user == "root"} {
39 puts stdout "Warning: you're executing as root. I'll have to"
40 puts stdout "skip some of the tests, since they'll fail as root."
41 }
42
43 # Some of the tests don't work on some system configurations due to
44 # differences in word length, file system configuration, etc. In order
45 # to prevent false alarms, these tests are generally only run in the
46 # master development directory for Tcl. The presence of a file
47 # "doAllTests" in this directory is used to indicate that the non-portable
48 # tests should be run.
49
50 set doNonPortableTests [file exists doAllTests]
51
52 proc print_verbose {test_name test_description contents_of_test code answer} {
53 puts stdout "\n"
54 puts stdout "==== $test_name $test_description"
55 puts stdout "==== Contents of test case:"
56 puts stdout "$contents_of_test"
57 if {$code != 0} {
58 if {$code == 1} {
59 puts stdout "==== Test generated error:"
60 puts stdout $answer
61 } elseif {$code == 2} {
62 puts stdout "==== Test generated return exception; result was:"
63 puts stdout $answer
64 } elseif {$code == 3} {
65 puts stdout "==== Test generated break exception"
66 } elseif {$code == 4} {
67 puts stdout "==== Test generated continue exception"
68 } else {
69 puts stdout "==== Test generated exception $code; message was:"
70 puts stdout $answer
71 }
72 } else {
73 puts stdout "==== Result was:"
74 puts stdout "$answer"
75 }
76 }
77
78 proc test {test_name test_description contents_of_test passing_results} {
79
80 #error "REREAD failure"
81
82 global VERBOSE
83 global TESTS
84 global DLP
85
86 if {[string compare $TESTS ""] != 0} then {
87 set ok 0
88 foreach test $TESTS {
89 if [string match $test $test_name] then {
90 set ok 1
91 break
92 }
93 }
94 if !$ok then return
95 }
96
97 if {$DLP} {
98 dlp session log "$test_name $test_description"
99 }
100
101 set code [catch {uplevel $contents_of_test} answer]
102 #
103 # memory active $test_name
104 #
105 if {$code != 0} {
106 print_verbose $test_name $test_description $contents_of_test \
107 $code $answer
108
109 if {$DLP} {
110 dlp session log " ERROR\n"
111 }
112 } elseif {[string compare $answer $passing_results] == 0} then {
113 if $VERBOSE then {
114 print_verbose $test_name $test_description $contents_of_test \
115 $code $answer
116 puts stdout "++++ $test_name PASSED"
117 }
118
119 if {$DLP} {
120 dlp session log "\n"
121 }
122 } else {
123 print_verbose $test_name $test_description $contents_of_test $code \
124 $answer
125 puts stdout "---- Result should have been:"
126 puts stdout "$passing_results"
127 puts stdout "---- $test_name FAILED"
128
129 if {$DLP} {
130 dlp session log " FAILED\n"
131 }
132 }
133 }
134
135 proc dotests {file args} {
136 global TESTS
137 set savedTests $TESTS
138 set TESTS $args
139 source $file
140 set TESTS $savedTests
141 }