[25] | 1 | '\" |
---|
| 2 | '\" Copyright (c) 1990-1994 The Regents of the University of California |
---|
| 3 | '\" Copyright (c) 1994-1997 Sun Microsystems, Inc. |
---|
| 4 | '\" Copyright (c) 1998-1999 Scriptics Corporation |
---|
| 5 | '\" Copyright (c) 2000 Ajuba Solutions |
---|
| 6 | '\" Contributions from Don Porter, NIST, 2002. (not subject to US copyright) |
---|
| 7 | '\" |
---|
| 8 | '\" See the file "license.terms" for information on usage and redistribution |
---|
| 9 | '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 10 | '\" |
---|
| 11 | '\" RCS: @(#) $Id: tcltest.n,v 1.55 2007/12/13 15:22:33 dgp Exp $ |
---|
| 12 | '\" |
---|
| 13 | .so man.macros |
---|
| 14 | .TH "tcltest" n 2.3 tcltest "Tcl Bundled Packages" |
---|
| 15 | .BS |
---|
| 16 | '\" Note: do not modify the .SH NAME line immediately below! |
---|
| 17 | .SH NAME |
---|
| 18 | tcltest \- Test harness support code and utilities |
---|
| 19 | .SH SYNOPSIS |
---|
| 20 | .nf |
---|
| 21 | \fBpackage require tcltest ?2.3?\fR |
---|
| 22 | .sp |
---|
| 23 | \fBtcltest::test \fIname description ?option value ...?\fR |
---|
| 24 | \fBtcltest::test \fIname description ?constraints? body result\fR |
---|
| 25 | .sp |
---|
| 26 | \fBtcltest::loadTestedCommands\fR |
---|
| 27 | \fBtcltest::makeDirectory \fIname ?directory?\fR |
---|
| 28 | \fBtcltest::removeDirectory \fIname ?directory?\fR |
---|
| 29 | \fBtcltest::makeFile \fIcontents name ?directory?\fR |
---|
| 30 | \fBtcltest::removeFile \fIname ?directory?\fR |
---|
| 31 | \fBtcltest::viewFile \fIname ?directory?\fR |
---|
| 32 | \fBtcltest::cleanupTests \fI?runningMultipleTests?\fR |
---|
| 33 | \fBtcltest::runAllTests\fR |
---|
| 34 | .sp |
---|
| 35 | \fBtcltest::configure\fR |
---|
| 36 | \fBtcltest::configure \fIoption\fR |
---|
| 37 | \fBtcltest::configure \fIoption value ?option value ...?\fR |
---|
| 38 | \fBtcltest::customMatch \fImode command\fR |
---|
| 39 | \fBtcltest::testConstraint \fIconstraint ?value?\fR |
---|
| 40 | \fBtcltest::outputChannel \fI?channelID?\fR |
---|
| 41 | \fBtcltest::errorChannel \fI?channelID?\fR |
---|
| 42 | \fBtcltest::interpreter \fI?interp?\fR |
---|
| 43 | .sp |
---|
| 44 | \fBtcltest::debug \fI?level?\fR |
---|
| 45 | \fBtcltest::errorFile \fI?filename?\fR |
---|
| 46 | \fBtcltest::limitConstraints \fI?boolean?\fR |
---|
| 47 | \fBtcltest::loadFile \fI?filename?\fR |
---|
| 48 | \fBtcltest::loadScript \fI?script?\fR |
---|
| 49 | \fBtcltest::match \fI?patternList?\fR |
---|
| 50 | \fBtcltest::matchDirectories \fI?patternList?\fR |
---|
| 51 | \fBtcltest::matchFiles \fI?patternList?\fR |
---|
| 52 | \fBtcltest::outputFile \fI?filename?\fR |
---|
| 53 | \fBtcltest::preserveCore \fI?level?\fR |
---|
| 54 | \fBtcltest::singleProcess \fI?boolean?\fR |
---|
| 55 | \fBtcltest::skip \fI?patternList?\fR |
---|
| 56 | \fBtcltest::skipDirectories \fI?patternList?\fR |
---|
| 57 | \fBtcltest::skipFiles \fI?patternList?\fR |
---|
| 58 | \fBtcltest::temporaryDirectory \fI?directory?\fR |
---|
| 59 | \fBtcltest::testsDirectory \fI?directory?\fR |
---|
| 60 | \fBtcltest::verbose \fI?level?\fR |
---|
| 61 | .sp |
---|
| 62 | \fBtcltest::test \fIname description optionList\fR |
---|
| 63 | \fBtcltest::bytestring \fIstring\fR |
---|
| 64 | \fBtcltest::normalizeMsg \fImsg\fR |
---|
| 65 | \fBtcltest::normalizePath \fIpathVar\fR |
---|
| 66 | \fBtcltest::workingDirectory \fI?dir?\fR |
---|
| 67 | .fi |
---|
| 68 | .BE |
---|
| 69 | .SH DESCRIPTION |
---|
| 70 | .PP |
---|
| 71 | The \fBtcltest\fR package provides several utility commands useful |
---|
| 72 | in the construction of test suites for code instrumented to be |
---|
| 73 | run by evaluation of Tcl commands. Notably the built-in commands |
---|
| 74 | of the Tcl library itself are tested by a test suite using the |
---|
| 75 | tcltest package. |
---|
| 76 | .PP |
---|
| 77 | All the commands provided by the \fBtcltest\fR package are defined |
---|
| 78 | in and exported from the \fB::tcltest\fR namespace, as indicated in |
---|
| 79 | the \fBSYNOPSIS\fR above. In the following sections, all commands |
---|
| 80 | will be described by their simple names, in the interest of brevity. |
---|
| 81 | .PP |
---|
| 82 | The central command of \fBtcltest\fR is \fBtest\fR that defines |
---|
| 83 | and runs a test. Testing with \fBtest\fR involves evaluation |
---|
| 84 | of a Tcl script and comparing the result to an expected result, as |
---|
| 85 | configured and controlled by a number of options. Several other |
---|
| 86 | commands provided by \fBtcltest\fR govern the configuration of |
---|
| 87 | \fBtest\fR and the collection of many \fBtest\fR commands into |
---|
| 88 | test suites. |
---|
| 89 | .PP |
---|
| 90 | See \fBCREATING TEST SUITES WITH TCLTEST\fR below for an extended example |
---|
| 91 | of how to use the commands of \fBtcltest\fR to produce test suites |
---|
| 92 | for your Tcl-enabled code. |
---|
| 93 | .SH COMMANDS |
---|
| 94 | .TP |
---|
| 95 | \fBtest\fR \fIname description ?option value ...?\fR |
---|
| 96 | Defines and possibly runs a test with the name \fIname\fR and |
---|
| 97 | description \fIdescription\fR. The name and description of a test |
---|
| 98 | are used in messages reported by \fBtest\fR during the |
---|
| 99 | test, as configured by the options of \fBtcltest\fR. The |
---|
| 100 | remaining \fIoption value\fR arguments to \fBtest\fR |
---|
| 101 | define the test, including the scripts to run, the conditions |
---|
| 102 | under which to run them, the expected result, and the means |
---|
| 103 | by which the expected and actual results should be compared. |
---|
| 104 | See \fBTESTS\fR below for a complete description of the valid |
---|
| 105 | options and how they define a test. The \fBtest\fR command |
---|
| 106 | returns an empty string. |
---|
| 107 | .TP |
---|
| 108 | \fBtest\fR \fIname description ?constraints? body result\fR |
---|
| 109 | This form of \fBtest\fR is provided to support test suites written |
---|
| 110 | for version 1 of the \fBtcltest\fR package, and also a simpler |
---|
| 111 | interface for a common usage. It is the same as |
---|
| 112 | .QW "\fBtest\fR \fIname description\fB \-constraints \fIconstraints\fB \-body \fIbody\fB \-result \fIresult\fR" . |
---|
| 113 | All other options to \fBtest\fR |
---|
| 114 | take their default values. When \fIconstraints\fR is omitted, this |
---|
| 115 | form of \fBtest\fR can be distinguished from the first because |
---|
| 116 | all \fIoption\fRs begin with |
---|
| 117 | .QW \- . |
---|
| 118 | .TP |
---|
| 119 | \fBloadTestedCommands\fR |
---|
| 120 | Evaluates in the caller's context the script specified by |
---|
| 121 | \fBconfigure \-load\fR or \fBconfigure \-loadfile\fR. |
---|
| 122 | Returns the result of that script evaluation, including any error |
---|
| 123 | raised by the script. Use this command and the related |
---|
| 124 | configuration options to provide the commands to be tested to |
---|
| 125 | the interpreter running the test suite. |
---|
| 126 | .TP |
---|
| 127 | \fBmakeFile\fR \fIcontents name ?directory?\fR |
---|
| 128 | Creates a file named \fIname\fR relative to |
---|
| 129 | directory \fIdirectory\fR and write \fIcontents\fR |
---|
| 130 | to that file using the encoding \fBencoding system\fR. |
---|
| 131 | If \fIcontents\fR does not end with a newline, a newline |
---|
| 132 | will be appended so that the file named \fIname\fR |
---|
| 133 | does end with a newline. Because the system encoding is used, |
---|
| 134 | this command is only suitable for making text files. |
---|
| 135 | The file will be removed by the next evaluation |
---|
| 136 | of \fBcleanupTests\fR, unless it is removed by |
---|
| 137 | \fBremoveFile\fR first. The default value of |
---|
| 138 | \fIdirectory\fR is the directory \fBconfigure \-tmpdir\fR. |
---|
| 139 | Returns the full path of the file created. Use this command |
---|
| 140 | to create any text file required by a test with contents as needed. |
---|
| 141 | .TP |
---|
| 142 | \fBremoveFile\fR \fIname ?directory?\fR |
---|
| 143 | Forces the file referenced by \fIname\fR to be removed. This file name |
---|
| 144 | should be relative to \fIdirectory\fR. The default value of |
---|
| 145 | \fIdirectory\fR is the directory \fBconfigure \-tmpdir\fR. |
---|
| 146 | Returns an empty string. Use this command to delete files |
---|
| 147 | created by \fBmakeFile\fR. |
---|
| 148 | .TP |
---|
| 149 | \fBmakeDirectory\fR \fIname ?directory?\fR |
---|
| 150 | Creates a directory named \fIname\fR relative to directory \fIdirectory\fR. |
---|
| 151 | The directory will be removed by the next evaluation of \fBcleanupTests\fR, |
---|
| 152 | unless it is removed by \fBremoveDirectory\fR first. |
---|
| 153 | The default value of \fIdirectory\fR is the directory |
---|
| 154 | \fBconfigure \-tmpdir\fR. |
---|
| 155 | Returns the full path of the directory created. Use this command |
---|
| 156 | to create any directories that are required to exist by a test. |
---|
| 157 | .TP |
---|
| 158 | \fBremoveDirectory\fR \fIname ?directory?\fR |
---|
| 159 | Forces the directory referenced by \fIname\fR to be removed. This |
---|
| 160 | directory should be relative to \fIdirectory\fR. |
---|
| 161 | The default value of \fIdirectory\fR is the directory |
---|
| 162 | \fBconfigure \-tmpdir\fR. |
---|
| 163 | Returns an empty string. Use this command to delete any directories |
---|
| 164 | created by \fBmakeDirectory\fR. |
---|
| 165 | .TP |
---|
| 166 | \fBviewFile\fR \fIfile ?directory?\fR |
---|
| 167 | Returns the contents of \fIfile\fR, except for any |
---|
| 168 | final newline, just as \fBread \-nonewline\fR would return. |
---|
| 169 | This file name should be relative to \fIdirectory\fR. |
---|
| 170 | The default value of \fIdirectory\fR is the directory |
---|
| 171 | \fBconfigure \-tmpdir\fR. Use this command |
---|
| 172 | as a convenient way to turn the contents of a file generated |
---|
| 173 | by a test into the result of that test for matching against |
---|
| 174 | an expected result. The contents of the file are read using |
---|
| 175 | the system encoding, so its usefulness is limited to text |
---|
| 176 | files. |
---|
| 177 | .TP |
---|
| 178 | \fBcleanupTests\fR |
---|
| 179 | Intended to clean up and summarize after several tests have been |
---|
| 180 | run. Typically called once per test file, at the end of the file |
---|
| 181 | after all tests have been completed. For best effectiveness, be |
---|
| 182 | sure that the \fBcleanupTests\fR is evaluated even if an error |
---|
| 183 | occurs earlier in the test file evaluation. |
---|
| 184 | .RS |
---|
| 185 | .PP |
---|
| 186 | Prints statistics about the tests run and removes files that were |
---|
| 187 | created by \fBmakeDirectory\fR and \fBmakeFile\fR since the |
---|
| 188 | last \fBcleanupTests\fR. Names of files and directories |
---|
| 189 | in the directory \fBconfigure \-tmpdir\fR created since |
---|
| 190 | the last \fBcleanupTests\fR, but not created by |
---|
| 191 | \fBmakeFile\fR or \fBmakeDirectory\fR are printed |
---|
| 192 | to \fBoutputChannel\fR. This command also restores the original |
---|
| 193 | shell environment, as described by the \fB::env\fR |
---|
| 194 | array. Returns an empty string. |
---|
| 195 | .RE |
---|
| 196 | .TP |
---|
| 197 | \fBrunAllTests\fR |
---|
| 198 | This is a master command meant to run an entire suite of tests, |
---|
| 199 | spanning multiple files and/or directories, as governed by |
---|
| 200 | the configurable options of \fBtcltest\fR. See \fBRUNNING ALL TESTS\fR |
---|
| 201 | below for a complete description of the many variations possible |
---|
| 202 | with \fBrunAllTests\fR. |
---|
| 203 | .SH "CONFIGURATION COMMANDS" |
---|
| 204 | .TP |
---|
| 205 | \fBconfigure\fR |
---|
| 206 | Returns the list of configurable options supported by \fBtcltest\fR. |
---|
| 207 | See \fBCONFIGURABLE OPTIONS\fR below for the full list of options, |
---|
| 208 | their valid values, and their effect on \fBtcltest\fR operations. |
---|
| 209 | .TP |
---|
| 210 | \fBconfigure \fIoption\fR |
---|
| 211 | Returns the current value of the supported configurable option \fIoption\fR. |
---|
| 212 | Raises an error if \fIoption\fR is not a supported configurable option. |
---|
| 213 | .TP |
---|
| 214 | \fBconfigure \fIoption value ?option value ...?\fR |
---|
| 215 | Sets the value of each configurable option \fIoption\fR to the |
---|
| 216 | corresponding value \fIvalue\fR, in order. Raises an error if |
---|
| 217 | an \fIoption\fR is not a supported configurable option, or if |
---|
| 218 | \fIvalue\fR is not a valid value for the corresponding \fIoption\fR, |
---|
| 219 | or if a \fIvalue\fR is not provided. When an error is raised, the |
---|
| 220 | operation of \fBconfigure\fR is halted, and subsequent \fIoption value\fR |
---|
| 221 | arguments are not processed. |
---|
| 222 | .RS |
---|
| 223 | .PP |
---|
| 224 | If the environment variable \fB::env(TCLTEST_OPTIONS)\fR exists when |
---|
| 225 | the \fBtcltest\fR package is loaded (by \fBpackage require tcltest\fR) |
---|
| 226 | then its value is taken as a list of arguments to pass to \fBconfigure\fR. |
---|
| 227 | This allows the default values of the configuration options to be |
---|
| 228 | set by the environment. |
---|
| 229 | .RE |
---|
| 230 | .TP |
---|
| 231 | \fBcustomMatch \fImode script\fR |
---|
| 232 | Registers \fImode\fR as a new legal value of the \fB\-match\fR option |
---|
| 233 | to \fBtest\fR. When the \fB\-match \fImode\fR option is |
---|
| 234 | passed to \fBtest\fR, the script \fIscript\fR will be evaluated |
---|
| 235 | to compare the actual result of evaluating the body of the test |
---|
| 236 | to the expected result. |
---|
| 237 | To perform the match, the \fIscript\fR is completed with two additional |
---|
| 238 | words, the expected result, and the actual result, and the completed script |
---|
| 239 | is evaluated in the global namespace. |
---|
| 240 | The completed script is expected to return a boolean value indicating |
---|
| 241 | whether or not the results match. The built-in matching modes of |
---|
| 242 | \fBtest\fR are \fBexact\fR, \fBglob\fR, and \fBregexp\fR. |
---|
| 243 | .TP |
---|
| 244 | \fBtestConstraint \fIconstraint ?boolean?\fR |
---|
| 245 | Sets or returns the boolean value associated with the named \fIconstraint\fR. |
---|
| 246 | See \fBTEST CONSTRAINTS\fR below for more information. |
---|
| 247 | .TP |
---|
| 248 | \fBinterpreter\fR \fI?executableName?\fR |
---|
| 249 | Sets or returns the name of the executable to be \fBexec\fRed by |
---|
| 250 | \fBrunAllTests\fR to run each test file when |
---|
| 251 | \fBconfigure \-singleproc\fR is false. |
---|
| 252 | The default value for \fBinterpreter\fR is the name of the |
---|
| 253 | currently running program as returned by \fBinfo nameofexecutable\fR. |
---|
| 254 | .TP |
---|
| 255 | \fBoutputChannel\fR \fI?channelID?\fR |
---|
| 256 | Sets or returns the output channel ID. This defaults to stdout. |
---|
| 257 | Any test that prints test related output should send |
---|
| 258 | that output to \fBoutputChannel\fR rather than letting |
---|
| 259 | that output default to stdout. |
---|
| 260 | .TP |
---|
| 261 | \fBerrorChannel\fR \fI?channelID?\fR |
---|
| 262 | Sets or returns the error channel ID. This defaults to stderr. |
---|
| 263 | Any test that prints error messages should send |
---|
| 264 | that output to \fBerrorChannel\fR rather than printing |
---|
| 265 | directly to stderr. |
---|
| 266 | .SH "SHORTCUT COMMANDS" |
---|
| 267 | .TP |
---|
| 268 | \fBdebug \fI?level?\fR |
---|
| 269 | Same as \fBconfigure \-debug \fI?level?\fR. |
---|
| 270 | .TP |
---|
| 271 | \fBerrorFile \fI?filename?\fR |
---|
| 272 | Same as \fBconfigure \-errfile \fI?filename?\fR. |
---|
| 273 | .TP |
---|
| 274 | \fBlimitConstraints \fI?boolean?\fR |
---|
| 275 | Same as \fBconfigure \-limitconstraints \fI?boolean?\fR. |
---|
| 276 | .TP |
---|
| 277 | \fBloadFile \fI?filename?\fR |
---|
| 278 | Same as \fBconfigure \-loadfile \fI?filename?\fR. |
---|
| 279 | .TP |
---|
| 280 | \fBloadScript \fI?script?\fR |
---|
| 281 | Same as \fBconfigure \-load \fI?script?\fR. |
---|
| 282 | .TP |
---|
| 283 | \fBmatch \fI?patternList?\fR |
---|
| 284 | Same as \fBconfigure \-match \fI?patternList?\fR. |
---|
| 285 | .TP |
---|
| 286 | \fBmatchDirectories \fI?patternList?\fR |
---|
| 287 | Same as \fBconfigure \-relateddir \fI?patternList?\fR. |
---|
| 288 | .TP |
---|
| 289 | \fBmatchFiles \fI?patternList?\fR |
---|
| 290 | Same as \fBconfigure \-file \fI?patternList?\fR. |
---|
| 291 | .TP |
---|
| 292 | \fBoutputFile \fI?filename?\fR |
---|
| 293 | Same as \fBconfigure \-outfile \fI?filename?\fR. |
---|
| 294 | .TP |
---|
| 295 | \fBpreserveCore \fI?level?\fR |
---|
| 296 | Same as \fBconfigure \-preservecore \fI?level?\fR. |
---|
| 297 | .TP |
---|
| 298 | \fBsingleProcess \fI?boolean?\fR |
---|
| 299 | Same as \fBconfigure \-singleproc \fI?boolean?\fR. |
---|
| 300 | .TP |
---|
| 301 | \fBskip \fI?patternList?\fR |
---|
| 302 | Same as \fBconfigure \-skip \fI?patternList?\fR. |
---|
| 303 | .TP |
---|
| 304 | \fBskipDirectories \fI?patternList?\fR |
---|
| 305 | Same as \fBconfigure \-asidefromdir \fI?patternList?\fR. |
---|
| 306 | .TP |
---|
| 307 | \fBskipFiles \fI?patternList?\fR |
---|
| 308 | Same as \fBconfigure \-notfile \fI?patternList?\fR. |
---|
| 309 | .TP |
---|
| 310 | \fBtemporaryDirectory \fI?directory?\fR |
---|
| 311 | Same as \fBconfigure \-tmpdir \fI?directory?\fR. |
---|
| 312 | .TP |
---|
| 313 | \fBtestsDirectory \fI?directory?\fR |
---|
| 314 | Same as \fBconfigure \-testdir \fI?directory?\fR. |
---|
| 315 | .TP |
---|
| 316 | \fBverbose \fI?level?\fR |
---|
| 317 | Same as \fBconfigure \-verbose \fI?level?\fR. |
---|
| 318 | .SH "OTHER COMMANDS" |
---|
| 319 | .PP |
---|
| 320 | The remaining commands provided by \fBtcltest\fR have better |
---|
| 321 | alternatives provided by \fBtcltest\fR or \fBTcl\fR itself. They |
---|
| 322 | are retained to support existing test suites, but should be avoided |
---|
| 323 | in new code. |
---|
| 324 | .TP |
---|
| 325 | \fBtest\fR \fIname description optionList\fR |
---|
| 326 | This form of \fBtest\fR was provided to enable passing many |
---|
| 327 | options spanning several lines to \fBtest\fR as a single |
---|
| 328 | argument quoted by braces, rather than needing to backslash quote |
---|
| 329 | the newlines between arguments to \fBtest\fR. The \fIoptionList\fR |
---|
| 330 | argument is expected to be a list with an even number of elements |
---|
| 331 | representing \fIoption\fR and \fIvalue\fR arguments to pass |
---|
| 332 | to \fBtest\fR. However, these values are not passed directly, as |
---|
| 333 | in the alternate forms of \fBswitch\fR. Instead, this form makes |
---|
| 334 | an unfortunate attempt to overthrow Tcl's substitution rules by |
---|
| 335 | performing substitutions on some of the list elements as an attempt to |
---|
| 336 | implement a |
---|
| 337 | .QW "do what I mean" |
---|
| 338 | interpretation of a brace-enclosed |
---|
| 339 | .QW block . |
---|
| 340 | The result is nearly impossible to document clearly, and |
---|
| 341 | for that reason this form is not recommended. See the examples in |
---|
| 342 | \fBCREATING TEST SUITES WITH TCLTEST\fR below to see that this |
---|
| 343 | form is really not necessary to avoid backslash-quoted newlines. |
---|
| 344 | If you insist on using this form, examine |
---|
| 345 | the source code of \fBtcltest\fR if you want to know the substitution |
---|
| 346 | details, or just enclose the third through last argument |
---|
| 347 | to \fBtest\fR in braces and hope for the best. |
---|
| 348 | .TP |
---|
| 349 | \fBworkingDirectory\fR \fI?directoryName?\fR |
---|
| 350 | Sets or returns the current working directory when the test suite is |
---|
| 351 | running. The default value for workingDirectory is the directory in |
---|
| 352 | which the test suite was launched. The Tcl commands \fBcd\fR and |
---|
| 353 | \fBpwd\fR are sufficient replacements. |
---|
| 354 | .TP |
---|
| 355 | \fBnormalizeMsg\fR \fImsg\fR |
---|
| 356 | Returns the result of removing the |
---|
| 357 | .QW extra |
---|
| 358 | newlines from \fImsg\fR, where |
---|
| 359 | .QW extra |
---|
| 360 | is rather imprecise. Tcl offers plenty of string |
---|
| 361 | processing commands to modify strings as you wish, and |
---|
| 362 | \fBcustomMatch\fR allows flexible matching of actual and expected |
---|
| 363 | results. |
---|
| 364 | .TP |
---|
| 365 | \fBnormalizePath\fR \fIpathVar\fR |
---|
| 366 | Resolves symlinks in a path, thus creating a path without internal |
---|
| 367 | redirection. It is assumed that \fIpathVar\fR is absolute. |
---|
| 368 | \fIpathVar\fR is modified in place. The Tcl command \fBfile normalize\fR |
---|
| 369 | is a sufficient replacement. |
---|
| 370 | .TP |
---|
| 371 | \fBbytestring\fR \fIstring\fR |
---|
| 372 | Construct a string that consists of the requested sequence of bytes, |
---|
| 373 | as opposed to a string of properly formed UTF-8 characters using the |
---|
| 374 | value supplied in \fIstring\fR. This allows the tester to create |
---|
| 375 | denormalized or improperly formed strings to pass to C procedures that |
---|
| 376 | are supposed to accept strings with embedded NULL types and confirm |
---|
| 377 | that a string result has a certain pattern of bytes. This is |
---|
| 378 | exactly equivalent to the Tcl command \fBencoding convertfrom identity\fR. |
---|
| 379 | .SH TESTS |
---|
| 380 | .PP |
---|
| 381 | The \fBtest\fR command is the heart of the \fBtcltest\fR package. |
---|
| 382 | Its essential function is to evaluate a Tcl script and compare |
---|
| 383 | the result with an expected result. The options of \fBtest\fR |
---|
| 384 | define the test script, the environment in which to evaluate it, |
---|
| 385 | the expected result, and how the compare the actual result to |
---|
| 386 | the expected result. Some configuration options of \fBtcltest\fR |
---|
| 387 | also influence how \fBtest\fR operates. |
---|
| 388 | .PP |
---|
| 389 | The valid options for \fBtest\fR are summarized: |
---|
| 390 | .PP |
---|
| 391 | .CS |
---|
| 392 | \fBtest\fR \fIname\fR \fIdescription\fR |
---|
| 393 | ?-constraints \fIkeywordList|expression\fR? |
---|
| 394 | ?-setup \fIsetupScript\fR? |
---|
| 395 | ?-body \fItestScript\fR? |
---|
| 396 | ?-cleanup \fIcleanupScript\fR? |
---|
| 397 | ?-result \fIexpectedAnswer\fR? |
---|
| 398 | ?-output \fIexpectedOutput\fR? |
---|
| 399 | ?-errorOutput \fIexpectedError\fR? |
---|
| 400 | ?-returnCodes \fIcodeList\fR? |
---|
| 401 | ?-match \fImode\fR? |
---|
| 402 | .CE |
---|
| 403 | .PP |
---|
| 404 | The \fIname\fR may be any string. It is conventional to choose |
---|
| 405 | a \fIname\fR according to the pattern: |
---|
| 406 | .PP |
---|
| 407 | .CS |
---|
| 408 | \fItarget\fR-\fImajorNum\fR.\fIminorNum\fR |
---|
| 409 | .CE |
---|
| 410 | .PP |
---|
| 411 | For white-box (regression) tests, the target should be the name of the |
---|
| 412 | C function or Tcl procedure being tested. For black-box tests, the |
---|
| 413 | target should be the name of the feature being tested. Some conventions |
---|
| 414 | call for the names of black-box tests to have the suffix \fB_bb\fR. |
---|
| 415 | Related tests should share a major number. As a test suite evolves, |
---|
| 416 | it is best to have the same test name continue to correspond to the |
---|
| 417 | same test, so that it remains meaningful to say things like |
---|
| 418 | .QW "Test foo-1.3 passed in all releases up to 3.4, but began failing in release 3.5." |
---|
| 419 | .PP |
---|
| 420 | During evaluation of \fBtest\fR, the \fIname\fR will be compared |
---|
| 421 | to the lists of string matching patterns returned by |
---|
| 422 | \fBconfigure \-match\fR, and \fBconfigure \-skip\fR. The test |
---|
| 423 | will be run only if \fIname\fR matches any of the patterns from |
---|
| 424 | \fBconfigure \-match\fR and matches none of the patterns |
---|
| 425 | from \fBconfigure \-skip\fR. |
---|
| 426 | .PP |
---|
| 427 | The \fIdescription\fR should be a short textual description of the |
---|
| 428 | test. The \fIdescription\fR is included in output produced by the |
---|
| 429 | test, typically test failure messages. Good \fIdescription\fR values |
---|
| 430 | should briefly explain the purpose of the test to users of a test suite. |
---|
| 431 | The name of a Tcl or C function being tested should be included in the |
---|
| 432 | description for regression tests. If the test case exists to reproduce |
---|
| 433 | a bug, include the bug ID in the description. |
---|
| 434 | .PP |
---|
| 435 | Valid attributes and associated values are: |
---|
| 436 | .TP |
---|
| 437 | \fB\-constraints \fIkeywordList|expression\fR |
---|
| 438 | The optional \fB\-constraints\fR attribute can be list of one or more |
---|
| 439 | keywords or an expression. If the \fB\-constraints\fR value is a list of |
---|
| 440 | keywords, each of these keywords should be the name of a constraint |
---|
| 441 | defined by a call to \fBtestConstraint\fR. If any of the listed |
---|
| 442 | constraints is false or does not exist, the test is skipped. If the |
---|
| 443 | \fB\-constraints\fR value is an expression, that expression |
---|
| 444 | is evaluated. If the expression evaluates to true, then the test is run. |
---|
| 445 | Note that the expression form of \fB\-constraints\fR may interfere with the |
---|
| 446 | operation of \fBconfigure \-constraints\fR and |
---|
| 447 | \fBconfigure \-limitconstraints\fR, and is not recommended. |
---|
| 448 | Appropriate constraints should be added to any tests that should |
---|
| 449 | not always be run. That is, conditional evaluation of a test |
---|
| 450 | should be accomplished by the \fB\-constraints\fR option, not by |
---|
| 451 | conditional evaluation of \fBtest\fR. In that way, the same |
---|
| 452 | number of tests are always reported by the test suite, though |
---|
| 453 | the number skipped may change based on the testing environment. |
---|
| 454 | The default value is an empty list. |
---|
| 455 | See \fBTEST CONSTRAINTS\fR below for a list of built-in constraints |
---|
| 456 | and information on how to add your own constraints. |
---|
| 457 | .TP |
---|
| 458 | \fB\-setup \fIscript\fR |
---|
| 459 | The optional \fB\-setup\fR attribute indicates a \fIscript\fR that will be run |
---|
| 460 | before the script indicated by the \fB\-body\fR attribute. If evaluation |
---|
| 461 | of \fIscript\fR raises an error, the test will fail. The default value |
---|
| 462 | is an empty script. |
---|
| 463 | .TP |
---|
| 464 | \fB\-body \fIscript\fR |
---|
| 465 | The \fB\-body\fR attribute indicates the \fIscript\fR to run to carry out the |
---|
| 466 | test. It must return a result that can be checked for correctness. |
---|
| 467 | If evaluation of \fIscript\fR raises an error, the test will fail. |
---|
| 468 | The default value is an empty script. |
---|
| 469 | .TP |
---|
| 470 | \fB\-cleanup \fIscript\fR |
---|
| 471 | The optional \fB\-cleanup\fR attribute indicates a \fIscript\fR that will be |
---|
| 472 | run after the script indicated by the \fB\-body\fR attribute. |
---|
| 473 | If evaluation of \fIscript\fR raises an error, the test will fail. |
---|
| 474 | The default value is an empty script. |
---|
| 475 | .TP |
---|
| 476 | \fB\-match \fImode\fR |
---|
| 477 | The \fB\-match\fR attribute determines how expected answers supplied by |
---|
| 478 | \fB\-result\fR, \fB\-output\fR, and \fB\-errorOutput\fR are compared. Valid |
---|
| 479 | values for \fImode\fR are \fBregexp\fR, \fBglob\fR, \fBexact\fR, and |
---|
| 480 | any value registered by a prior call to \fBcustomMatch\fR. The default |
---|
| 481 | value is \fBexact\fR. |
---|
| 482 | .TP |
---|
| 483 | \fB\-result \fIexpectedValue\fR |
---|
| 484 | The \fB\-result\fR attribute supplies the \fIexpectedValue\fR against which |
---|
| 485 | the return value from script will be compared. The default value is |
---|
| 486 | an empty string. |
---|
| 487 | .TP |
---|
| 488 | \fB\-output \fIexpectedValue\fR |
---|
| 489 | The \fB\-output\fR attribute supplies the \fIexpectedValue\fR against which |
---|
| 490 | any output sent to \fBstdout\fR or \fBoutputChannel\fR during evaluation |
---|
| 491 | of the script(s) will be compared. Note that only output printed using |
---|
| 492 | \fB::puts\fR is used for comparison. If \fB\-output\fR is not specified, |
---|
| 493 | output sent to \fBstdout\fR and \fBoutputChannel\fR is not processed for |
---|
| 494 | comparison. |
---|
| 495 | .TP |
---|
| 496 | \fB\-errorOutput \fIexpectedValue\fR |
---|
| 497 | The \fB\-errorOutput\fR attribute supplies the \fIexpectedValue\fR against |
---|
| 498 | which any output sent to \fBstderr\fR or \fBerrorChannel\fR during |
---|
| 499 | evaluation of the script(s) will be compared. Note that only output |
---|
| 500 | printed using \fB::puts\fR is used for comparison. If \fB\-errorOutput\fR |
---|
| 501 | is not specified, output sent to \fBstderr\fR and \fBerrorChannel\fR is |
---|
| 502 | not processed for comparison. |
---|
| 503 | .TP |
---|
| 504 | \fB\-returnCodes \fIexpectedCodeList\fR |
---|
| 505 | The optional \fB\-returnCodes\fR attribute supplies \fIexpectedCodeList\fR, |
---|
| 506 | a list of return codes that may be accepted from evaluation of the |
---|
| 507 | \fB\-body\fR script. If evaluation of the \fB\-body\fR script returns |
---|
| 508 | a code not in the \fIexpectedCodeList\fR, the test fails. All |
---|
| 509 | return codes known to \fBreturn\fR, in both numeric and symbolic |
---|
| 510 | form, including extended return codes, are acceptable elements in |
---|
| 511 | the \fIexpectedCodeList\fR. Default value is |
---|
| 512 | .QW \fBok return\fR. |
---|
| 513 | .PP |
---|
| 514 | To pass, a test must successfully evaluate its \fB\-setup\fR, \fB\-body\fR, |
---|
| 515 | and \fB\-cleanup\fR scripts. The return code of the \fB\-body\fR script and |
---|
| 516 | its result must match expected values, and if specified, output and error |
---|
| 517 | data from the test must match expected \fB\-output\fR and \fB\-errorOutput\fR |
---|
| 518 | values. If any of these conditions are not met, then the test fails. |
---|
| 519 | Note that all scripts are evaluated in the context of the caller |
---|
| 520 | of \fBtest\fR. |
---|
| 521 | .PP |
---|
| 522 | As long as \fBtest\fR is called with valid syntax and legal |
---|
| 523 | values for all attributes, it will not raise an error. Test |
---|
| 524 | failures are instead reported as output written to \fBoutputChannel\fR. |
---|
| 525 | In default operation, a successful test produces no output. The output |
---|
| 526 | messages produced by \fBtest\fR are controlled by the |
---|
| 527 | \fBconfigure \-verbose\fR option as described in \fBCONFIGURABLE OPTIONS\fR |
---|
| 528 | below. Any output produced by the test scripts themselves should be |
---|
| 529 | produced using \fB::puts\fR to \fBoutputChannel\fR or |
---|
| 530 | \fBerrorChannel\fR, so that users of the test suite may |
---|
| 531 | easily capture output with the \fBconfigure \-outfile\fR and |
---|
| 532 | \fBconfigure \-errfile\fR options, and so that the \fB\-output\fR |
---|
| 533 | and \fB\-errorOutput\fR attributes work properly. |
---|
| 534 | .SH "TEST CONSTRAINTS" |
---|
| 535 | .PP |
---|
| 536 | Constraints are used to determine whether or not a test should be skipped. |
---|
| 537 | Each constraint has a name, which may be any string, and a boolean |
---|
| 538 | value. Each \fBtest\fR has a \fB\-constraints\fR value which is a |
---|
| 539 | list of constraint names. There are two modes of constraint control. |
---|
| 540 | Most frequently, the default mode is used, indicated by a setting |
---|
| 541 | of \fBconfigure \-limitconstraints\fR to false. The test will run |
---|
| 542 | only if all constraints in the list are true-valued. Thus, |
---|
| 543 | the \fB\-constraints\fR option of \fBtest\fR is a convenient, symbolic |
---|
| 544 | way to define any conditions required for the test to be possible or |
---|
| 545 | meaningful. For example, a \fBtest\fR with \fB\-constraints unix\fR |
---|
| 546 | will only be run if the constraint \fBunix\fR is true, which indicates |
---|
| 547 | the test suite is being run on a Unix platform. |
---|
| 548 | .PP |
---|
| 549 | Each \fBtest\fR should include whatever \fB\-constraints\fR are |
---|
| 550 | required to constrain it to run only where appropriate. Several |
---|
| 551 | constraints are pre-defined in the \fBtcltest\fR package, listed |
---|
| 552 | below. The registration of user-defined constraints is performed |
---|
| 553 | by the \fBtestConstraint\fR command. User-defined constraints |
---|
| 554 | may appear within a test file, or within the script specified |
---|
| 555 | by the \fBconfigure \-load\fR or \fBconfigure \-loadfile\fR |
---|
| 556 | options. |
---|
| 557 | .PP |
---|
| 558 | The following is a list of constraints pre-defined by the |
---|
| 559 | \fBtcltest\fR package itself: |
---|
| 560 | .TP |
---|
| 561 | \fIsingleTestInterp\fR |
---|
| 562 | test can only be run if all test files are sourced into a single interpreter |
---|
| 563 | .TP |
---|
| 564 | \fIunix\fR |
---|
| 565 | test can only be run on any Unix platform |
---|
| 566 | .TP |
---|
| 567 | \fIwin\fR |
---|
| 568 | test can only be run on any Windows platform |
---|
| 569 | .TP |
---|
| 570 | \fInt\fR |
---|
| 571 | test can only be run on any Windows NT platform |
---|
| 572 | .TP |
---|
| 573 | \fI95\fR |
---|
| 574 | test can only be run on any Windows 95 platform |
---|
| 575 | .TP |
---|
| 576 | \fI98\fR |
---|
| 577 | test can only be run on any Windows 98 platform |
---|
| 578 | .TP |
---|
| 579 | \fImac\fR |
---|
| 580 | test can only be run on any Mac platform |
---|
| 581 | .TP |
---|
| 582 | \fIunixOrWin\fR |
---|
| 583 | test can only be run on a Unix or Windows platform |
---|
| 584 | .TP |
---|
| 585 | \fImacOrWin\fR |
---|
| 586 | test can only be run on a Mac or Windows platform |
---|
| 587 | .TP |
---|
| 588 | \fImacOrUnix\fR |
---|
| 589 | test can only be run on a Mac or Unix platform |
---|
| 590 | .TP |
---|
| 591 | \fItempNotWin\fR |
---|
| 592 | test can not be run on Windows. This flag is used to temporarily |
---|
| 593 | disable a test. |
---|
| 594 | .TP |
---|
| 595 | \fItempNotMac\fR |
---|
| 596 | test can not be run on a Mac. This flag is used |
---|
| 597 | to temporarily disable a test. |
---|
| 598 | .TP |
---|
| 599 | \fIunixCrash\fR |
---|
| 600 | test crashes if it is run on Unix. This flag is used to temporarily |
---|
| 601 | disable a test. |
---|
| 602 | .TP |
---|
| 603 | \fIwinCrash\fR |
---|
| 604 | test crashes if it is run on Windows. This flag is used to temporarily |
---|
| 605 | disable a test. |
---|
| 606 | .TP |
---|
| 607 | \fImacCrash\fR |
---|
| 608 | test crashes if it is run on a Mac. This flag is used to temporarily |
---|
| 609 | disable a test. |
---|
| 610 | .TP |
---|
| 611 | \fIemptyTest\fR |
---|
| 612 | test is empty, and so not worth running, but it remains as a |
---|
| 613 | place-holder for a test to be written in the future. This constraint |
---|
| 614 | has value false to cause tests to be skipped unless the user specifies |
---|
| 615 | otherwise. |
---|
| 616 | .TP |
---|
| 617 | \fIknownBug\fR |
---|
| 618 | test is known to fail and the bug is not yet fixed. This constraint |
---|
| 619 | has value false to cause tests to be skipped unless the user specifies |
---|
| 620 | otherwise. |
---|
| 621 | .TP |
---|
| 622 | \fInonPortable\fR |
---|
| 623 | test can only be run in some known development environment. |
---|
| 624 | Some tests are inherently non-portable because they depend on things |
---|
| 625 | like word length, file system configuration, window manager, etc. |
---|
| 626 | This constraint has value false to cause tests to be skipped unless |
---|
| 627 | the user specifies otherwise. |
---|
| 628 | .TP |
---|
| 629 | \fIuserInteraction\fR |
---|
| 630 | test requires interaction from the user. This constraint has |
---|
| 631 | value false to causes tests to be skipped unless the user specifies |
---|
| 632 | otherwise. |
---|
| 633 | .TP |
---|
| 634 | \fIinteractive\fR |
---|
| 635 | test can only be run in if the interpreter is in interactive mode |
---|
| 636 | (when the global tcl_interactive variable is set to 1). |
---|
| 637 | .TP |
---|
| 638 | \fInonBlockFiles\fR |
---|
| 639 | test can only be run if platform supports setting files into |
---|
| 640 | nonblocking mode |
---|
| 641 | .TP |
---|
| 642 | \fIasyncPipeClose\fR |
---|
| 643 | test can only be run if platform supports async flush and async close |
---|
| 644 | on a pipe |
---|
| 645 | .TP |
---|
| 646 | \fIunixExecs\fR |
---|
| 647 | test can only be run if this machine has Unix-style commands |
---|
| 648 | \fBcat\fR, \fBecho\fR, \fBsh\fR, \fBwc\fR, \fBrm\fR, \fBsleep\fR, |
---|
| 649 | \fBfgrep\fR, \fBps\fR, \fBchmod\fR, and \fBmkdir\fR available |
---|
| 650 | .TP |
---|
| 651 | \fIhasIsoLocale\fR |
---|
| 652 | test can only be run if can switch to an ISO locale |
---|
| 653 | .TP |
---|
| 654 | \fIroot\fR |
---|
| 655 | test can only run if Unix user is root |
---|
| 656 | .TP |
---|
| 657 | \fInotRoot\fR |
---|
| 658 | test can only run if Unix user is not root |
---|
| 659 | .TP |
---|
| 660 | \fIeformat\fR |
---|
| 661 | test can only run if app has a working version of sprintf with respect |
---|
| 662 | to the |
---|
| 663 | .QW e |
---|
| 664 | format of floating-point numbers. |
---|
| 665 | .TP |
---|
| 666 | \fIstdio\fR |
---|
| 667 | test can only be run if \fBinterpreter\fR can be \fBopen\fRed |
---|
| 668 | as a pipe. |
---|
| 669 | .PP |
---|
| 670 | The alternative mode of constraint control is enabled by setting |
---|
| 671 | \fBconfigure \-limitconstraints\fR to true. With that configuration |
---|
| 672 | setting, all existing constraints other than those in the constraint |
---|
| 673 | list returned by \fBconfigure \-constraints\fR are set to false. |
---|
| 674 | When the value of \fBconfigure \-constraints\fR |
---|
| 675 | is set, all those constraints are set to true. The effect is that |
---|
| 676 | when both options \fBconfigure \-constraints\fR and |
---|
| 677 | \fBconfigure \-limitconstraints\fR are in use, only those tests including |
---|
| 678 | only constraints from the \fBconfigure \-constraints\fR list |
---|
| 679 | are run; all others are skipped. For example, one might set |
---|
| 680 | up a configuration with |
---|
| 681 | .PP |
---|
| 682 | .CS |
---|
| 683 | \fBconfigure\fR -constraints knownBug \e |
---|
| 684 | -limitconstraints true \e |
---|
| 685 | -verbose pass |
---|
| 686 | .CE |
---|
| 687 | .PP |
---|
| 688 | to run exactly those tests that exercise known bugs, and discover |
---|
| 689 | whether any of them pass, indicating the bug had been fixed. |
---|
| 690 | .SH "RUNNING ALL TESTS" |
---|
| 691 | .PP |
---|
| 692 | The single command \fBrunAllTests\fR is evaluated to run an entire |
---|
| 693 | test suite, spanning many files and directories. The configuration |
---|
| 694 | options of \fBtcltest\fR control the precise operations. The |
---|
| 695 | \fBrunAllTests\fR command begins by printing a summary of its |
---|
| 696 | configuration to \fBoutputChannel\fR. |
---|
| 697 | .PP |
---|
| 698 | Test files to be evaluated are sought in the directory |
---|
| 699 | \fBconfigure \-testdir\fR. The list of files in that directory |
---|
| 700 | that match any of the patterns in \fBconfigure \-file\fR and |
---|
| 701 | match none of the patterns in \fBconfigure \-notfile\fR is generated |
---|
| 702 | and sorted. Then each file will be evaluated in turn. If |
---|
| 703 | \fBconfigure \-singleproc\fR is true, then each file will |
---|
| 704 | be \fBsource\fRd in the caller's context. If it is false, |
---|
| 705 | then a copy of \fBinterpreter\fR will be \fBexec\fR'd to |
---|
| 706 | evaluate each file. The multi-process operation is useful |
---|
| 707 | when testing can cause errors so severe that a process |
---|
| 708 | terminates. Although such an error may terminate a child |
---|
| 709 | process evaluating one file, the master process can continue |
---|
| 710 | with the rest of the test suite. In multi-process operation, |
---|
| 711 | the configuration of \fBtcltest\fR in the master process is |
---|
| 712 | passed to the child processes as command line arguments, |
---|
| 713 | with the exception of \fBconfigure \-outfile\fR. The |
---|
| 714 | \fBrunAllTests\fR command in the |
---|
| 715 | master process collects all output from the child processes |
---|
| 716 | and collates their results into one master report. Any |
---|
| 717 | reports of individual test failures, or messages requested |
---|
| 718 | by a \fBconfigure \-verbose\fR setting are passed directly |
---|
| 719 | on to \fBoutputChannel\fR by the master process. |
---|
| 720 | .PP |
---|
| 721 | After evaluating all selected test files, a summary of the |
---|
| 722 | results is printed to \fBoutputChannel\fR. The summary |
---|
| 723 | includes the total number of \fBtest\fRs evaluated, broken |
---|
| 724 | down into those skipped, those passed, and those failed. |
---|
| 725 | The summary also notes the number of files evaluated, and the names |
---|
| 726 | of any files with failing tests or errors. A list of |
---|
| 727 | the constraints that caused tests to be skipped, and the |
---|
| 728 | number of tests skipped for each is also printed. Also, |
---|
| 729 | messages are printed if it appears that evaluation of |
---|
| 730 | a test file has caused any temporary files to be left |
---|
| 731 | behind in \fBconfigure \-tmpdir\fR. |
---|
| 732 | .PP |
---|
| 733 | Having completed and summarized all selected test files, |
---|
| 734 | \fBrunAllTests\fR then recursively acts on subdirectories |
---|
| 735 | of \fBconfigure \-testdir\fR. All subdirectories that |
---|
| 736 | match any of the patterns in \fBconfigure \-relateddir\fR |
---|
| 737 | and do not match any of the patterns in |
---|
| 738 | \fBconfigure \-asidefromdir\fR are examined. If |
---|
| 739 | a file named \fBall.tcl\fR is found in such a directory, |
---|
| 740 | it will be \fBsource\fRd in the caller's context. |
---|
| 741 | Whether or not an examined directory contains an |
---|
| 742 | \fBall.tcl\fR file, its subdirectories are also scanned |
---|
| 743 | against the \fBconfigure \-relateddir\fR and |
---|
| 744 | \fBconfigure \-asidefromdir\fR patterns. In this way, |
---|
| 745 | many directories in a directory tree can have all their |
---|
| 746 | test files evaluated by a single \fBrunAllTests\fR |
---|
| 747 | command. |
---|
| 748 | .SH "CONFIGURABLE OPTIONS" |
---|
| 749 | The \fBconfigure\fR command is used to set and query the configurable |
---|
| 750 | options of \fBtcltest\fR. The valid options are: |
---|
| 751 | .TP |
---|
| 752 | \fB\-singleproc \fIboolean\fR |
---|
| 753 | Controls whether or not \fBrunAllTests\fR spawns a child process for |
---|
| 754 | each test file. No spawning when \fIboolean\fR is true. Default |
---|
| 755 | value is false. |
---|
| 756 | .TP |
---|
| 757 | \fB\-debug \fIlevel\fR |
---|
| 758 | Sets the debug level to \fIlevel\fR, an integer value indicating how |
---|
| 759 | much debugging information should be printed to stdout. Note that |
---|
| 760 | debug messages always go to stdout, independent of the value of |
---|
| 761 | \fBconfigure \-outfile\fR. Default value is 0. Levels are defined as: |
---|
| 762 | .RS |
---|
| 763 | .IP 0 |
---|
| 764 | Do not display any debug information. |
---|
| 765 | .IP 1 |
---|
| 766 | Display information regarding whether a test is skipped because it |
---|
| 767 | does not match any of the tests that were specified using by |
---|
| 768 | \fBconfigure \-match\fR (userSpecifiedNonMatch) or matches any of |
---|
| 769 | the tests specified by \fBconfigure \-skip\fR (userSpecifiedSkip). Also |
---|
| 770 | print warnings about possible lack of cleanup or balance in test files. |
---|
| 771 | Also print warnings about any re-use of test names. |
---|
| 772 | .IP 2 |
---|
| 773 | Display the flag array parsed by the command line processor, the |
---|
| 774 | contents of the ::env array, and all user-defined variables that exist |
---|
| 775 | in the current namespace as they are used. |
---|
| 776 | .IP 3 |
---|
| 777 | Display information regarding what individual procs in the test |
---|
| 778 | harness are doing. |
---|
| 779 | .RE |
---|
| 780 | .TP |
---|
| 781 | \fB\-verbose \fIlevel\fR |
---|
| 782 | Sets the type of output verbosity desired to \fIlevel\fR, |
---|
| 783 | a list of zero or more of the elements \fBbody\fR, \fBpass\fR, |
---|
| 784 | \fBskip\fR, \fBstart\fR, \fBerror\fR and \fBline\fR. Default value |
---|
| 785 | is \fB{body error}\fR. |
---|
| 786 | Levels are defined as: |
---|
| 787 | .RS |
---|
| 788 | .IP "body (b)" |
---|
| 789 | Display the body of failed tests |
---|
| 790 | .IP "pass (p)" |
---|
| 791 | Print output when a test passes |
---|
| 792 | .IP "skip (s)" |
---|
| 793 | Print output when a test is skipped |
---|
| 794 | .IP "start (t)" |
---|
| 795 | Print output whenever a test starts |
---|
| 796 | .IP "error (e)" |
---|
| 797 | Print errorInfo and errorCode, if they exist, when a test return code |
---|
| 798 | does not match its expected return code |
---|
| 799 | .IP "line (l)" |
---|
| 800 | Print source file line information of failed tests |
---|
| 801 | .RE |
---|
| 802 | The single letter abbreviations noted above are also recognized |
---|
| 803 | so that |
---|
| 804 | .QW "\fBconfigure \-verbose pt\fR" |
---|
| 805 | is the same as |
---|
| 806 | .QW "\fBconfigure \-verbose {pass start}\fR" . |
---|
| 807 | .TP |
---|
| 808 | \fB\-preservecore \fIlevel\fR |
---|
| 809 | Sets the core preservation level to \fIlevel\fR. This level |
---|
| 810 | determines how stringent checks for core files are. Default |
---|
| 811 | value is 0. Levels are defined as: |
---|
| 812 | .RS |
---|
| 813 | .IP 0 |
---|
| 814 | No checking \(em do not check for core files at the end of each test |
---|
| 815 | command, but do check for them in \fBrunAllTests\fR after all |
---|
| 816 | test files have been evaluated. |
---|
| 817 | .IP 1 |
---|
| 818 | Also check for core files at the end of each \fBtest\fR command. |
---|
| 819 | .IP 2 |
---|
| 820 | Check for core files at all times described above, and save a |
---|
| 821 | copy of each core file produced in \fBconfigure \-tmpdir\fR. |
---|
| 822 | .RE |
---|
| 823 | .TP |
---|
| 824 | \fB\-limitconstraints \fIboolean\fR |
---|
| 825 | Sets the mode by which \fBtest\fR honors constraints as described |
---|
| 826 | in \fBTESTS\fR above. Default value is false. |
---|
| 827 | .TP |
---|
| 828 | \fB\-constraints \fIlist\fR |
---|
| 829 | Sets all the constraints in \fIlist\fR to true. Also used in |
---|
| 830 | combination with \fBconfigure \-limitconstraints true\fR to control an |
---|
| 831 | alternative constraint mode as described in \fBTESTS\fR above. |
---|
| 832 | Default value is an empty list. |
---|
| 833 | .TP |
---|
| 834 | \fB\-tmpdir \fIdirectory\fR |
---|
| 835 | Sets the temporary directory to be used by \fBmakeFile\fR, |
---|
| 836 | \fBmakeDirectory\fR, \fBviewFile\fR, \fBremoveFile\fR, |
---|
| 837 | and \fBremoveDirectory\fR as the default directory where |
---|
| 838 | temporary files and directories created by test files should |
---|
| 839 | be created. Default value is \fBworkingDirectory\fR. |
---|
| 840 | .TP |
---|
| 841 | \fB\-testdir \fIdirectory\fR |
---|
| 842 | Sets the directory searched by \fBrunAllTests\fR for test files |
---|
| 843 | and subdirectories. Default value is \fBworkingDirectory\fR. |
---|
| 844 | .TP |
---|
| 845 | \fB\-file \fIpatternList\fR |
---|
| 846 | Sets the list of patterns used by \fBrunAllTests\fR to determine |
---|
| 847 | what test files to evaluate. Default value is |
---|
| 848 | .QW \fB*.test\fR . |
---|
| 849 | .TP |
---|
| 850 | \fB\-notfile \fIpatternList\fR |
---|
| 851 | Sets the list of patterns used by \fBrunAllTests\fR to determine |
---|
| 852 | what test files to skip. Default value is |
---|
| 853 | .QW \fBl.*.test\fR , |
---|
| 854 | so that any SCCS lock files are skipped. |
---|
| 855 | .TP |
---|
| 856 | \fB\-relateddir \fIpatternList\fR |
---|
| 857 | Sets the list of patterns used by \fBrunAllTests\fR to determine |
---|
| 858 | what subdirectories to search for an \fBall.tcl\fR file. Default |
---|
| 859 | value is |
---|
| 860 | .QW \fB*\fR . |
---|
| 861 | .TP |
---|
| 862 | \fB\-asidefromdir \fIpatternList\fR |
---|
| 863 | Sets the list of patterns used by \fBrunAllTests\fR to determine |
---|
| 864 | what subdirectories to skip when searching for an \fBall.tcl\fR file. |
---|
| 865 | Default value is an empty list. |
---|
| 866 | .TP |
---|
| 867 | \fB\-match \fIpatternList\fR |
---|
| 868 | Set the list of patterns used by \fBtest\fR to determine whether |
---|
| 869 | a test should be run. Default value is |
---|
| 870 | .QW \fB*\fR . |
---|
| 871 | .TP |
---|
| 872 | \fB\-skip \fIpatternList\fR |
---|
| 873 | Set the list of patterns used by \fBtest\fR to determine whether |
---|
| 874 | a test should be skipped. Default value is an empty list. |
---|
| 875 | .TP |
---|
| 876 | \fB\-load \fIscript\fR |
---|
| 877 | Sets a script to be evaluated by \fBloadTestedCommands\fR. |
---|
| 878 | Default value is an empty script. |
---|
| 879 | .TP |
---|
| 880 | \fB\-loadfile \fIfilename\fR |
---|
| 881 | Sets the filename from which to read a script to be evaluated |
---|
| 882 | by \fBloadTestedCommands\fR. This is an alternative to |
---|
| 883 | \fB\-load\fR. They cannot be used together. |
---|
| 884 | .TP |
---|
| 885 | \fB\-outfile \fIfilename\fR |
---|
| 886 | Sets the file to which all output produced by tcltest should be |
---|
| 887 | written. A file named \fIfilename\fR will be \fBopen\fRed for writing, |
---|
| 888 | and the resulting channel will be set as the value of \fBoutputChannel\fR. |
---|
| 889 | .TP |
---|
| 890 | \fB\-errfile \fIfilename\fR |
---|
| 891 | Sets the file to which all error output produced by tcltest |
---|
| 892 | should be written. A file named \fIfilename\fR will be \fBopen\fRed |
---|
| 893 | for writing, and the resulting channel will be set as the value |
---|
| 894 | of \fBerrorChannel\fR. |
---|
| 895 | .SH "CREATING TEST SUITES WITH TCLTEST" |
---|
| 896 | .PP |
---|
| 897 | The fundamental element of a test suite is the individual \fBtest\fR |
---|
| 898 | command. We begin with several examples. |
---|
| 899 | .IP [1] |
---|
| 900 | Test of a script that returns normally. |
---|
| 901 | .RS |
---|
| 902 | .PP |
---|
| 903 | .CS |
---|
| 904 | \fBtest\fR example-1.0 {normal return} { |
---|
| 905 | format %s value |
---|
| 906 | } value |
---|
| 907 | .CE |
---|
| 908 | .RE |
---|
| 909 | .IP [2] |
---|
| 910 | Test of a script that requires context setup and cleanup. Note the |
---|
| 911 | bracing and indenting style that avoids any need for line continuation. |
---|
| 912 | .RS |
---|
| 913 | .PP |
---|
| 914 | .CS |
---|
| 915 | \fBtest\fR example-1.1 {test file existence} -setup { |
---|
| 916 | set file [makeFile {} test] |
---|
| 917 | } -body { |
---|
| 918 | file exists $file |
---|
| 919 | } -cleanup { |
---|
| 920 | removeFile test |
---|
| 921 | } -result 1 |
---|
| 922 | .CE |
---|
| 923 | .RE |
---|
| 924 | .IP [3] |
---|
| 925 | Test of a script that raises an error. |
---|
| 926 | .RS |
---|
| 927 | .PP |
---|
| 928 | .CS |
---|
| 929 | \fBtest\fR example-1.2 {error return} -body { |
---|
| 930 | error message |
---|
| 931 | } -returnCodes error -result message |
---|
| 932 | .CE |
---|
| 933 | .RE |
---|
| 934 | .IP [4] |
---|
| 935 | Test with a constraint. |
---|
| 936 | .RS |
---|
| 937 | .PP |
---|
| 938 | .CS |
---|
| 939 | \fBtest\fR example-1.3 {user owns created files} -constraints { |
---|
| 940 | unix |
---|
| 941 | } -setup { |
---|
| 942 | set file [makeFile {} test] |
---|
| 943 | } -body { |
---|
| 944 | file attributes $file -owner |
---|
| 945 | } -cleanup { |
---|
| 946 | removeFile test |
---|
| 947 | } -result $::tcl_platform(user) |
---|
| 948 | .CE |
---|
| 949 | .RE |
---|
| 950 | .PP |
---|
| 951 | At the next higher layer of organization, several \fBtest\fR commands |
---|
| 952 | are gathered together into a single test file. Test files should have |
---|
| 953 | names with the \fB.test\fR extension, because that is the default pattern |
---|
| 954 | used by \fBrunAllTests\fR to find test files. It is a good rule of |
---|
| 955 | thumb to have one test file for each source code file of your project. |
---|
| 956 | It is good practice to edit the test file and the source code file |
---|
| 957 | together, keeping tests synchronized with code changes. |
---|
| 958 | .PP |
---|
| 959 | Most of the code in the test file should be the \fBtest\fR commands. |
---|
| 960 | Use constraints to skip tests, rather than conditional evaluation |
---|
| 961 | of \fBtest\fR. |
---|
| 962 | .IP [5] |
---|
| 963 | Recommended system for writing conditional tests, using constraints to |
---|
| 964 | guard: |
---|
| 965 | .RS |
---|
| 966 | .PP |
---|
| 967 | .CS |
---|
| 968 | \fBtestConstraint\fR X [expr $myRequirement] |
---|
| 969 | \fBtest\fR goodConditionalTest {} X { |
---|
| 970 | # body |
---|
| 971 | } result |
---|
| 972 | .CE |
---|
| 973 | .RE |
---|
| 974 | .IP [6] |
---|
| 975 | Discouraged system for writing conditional tests, using \fBif\fR to |
---|
| 976 | guard: |
---|
| 977 | .RS |
---|
| 978 | .PP |
---|
| 979 | .CS |
---|
| 980 | if $myRequirement { |
---|
| 981 | test badConditionalTest {} { |
---|
| 982 | #body |
---|
| 983 | } result |
---|
| 984 | } |
---|
| 985 | .CE |
---|
| 986 | .RE |
---|
| 987 | .PP |
---|
| 988 | Use the \fB\-setup\fR and \fB\-cleanup\fR options to establish and release |
---|
| 989 | all context requirements of the test body. Do not make tests depend on |
---|
| 990 | prior tests in the file. Those prior tests might be skipped. If several |
---|
| 991 | consecutive tests require the same context, the appropriate setup |
---|
| 992 | and cleanup scripts may be stored in variable for passing to each tests |
---|
| 993 | \fB\-setup\fR and \fB\-cleanup\fR options. This is a better solution than |
---|
| 994 | performing setup outside of \fBtest\fR commands, because the setup will |
---|
| 995 | only be done if necessary, and any errors during setup will be reported, |
---|
| 996 | and not cause the test file to abort. |
---|
| 997 | .PP |
---|
| 998 | A test file should be able to be combined with other test files and not |
---|
| 999 | interfere with them, even when \fBconfigure \-singleproc 1\fR causes |
---|
| 1000 | all files to be evaluated in a common interpreter. A simple way to |
---|
| 1001 | achieve this is to have your tests define all their commands and variables |
---|
| 1002 | in a namespace that is deleted when the test file evaluation is complete. |
---|
| 1003 | A good namespace to use is a child namespace \fBtest\fR of the namespace |
---|
| 1004 | of the module you are testing. |
---|
| 1005 | .PP |
---|
| 1006 | A test file should also be able to be evaluated directly as a script, |
---|
| 1007 | not depending on being called by a master \fBrunAllTests\fR. This |
---|
| 1008 | means that each test file should process command line arguments to give |
---|
| 1009 | the tester all the configuration control that \fBtcltest\fR provides. |
---|
| 1010 | .PP |
---|
| 1011 | After all \fBtest\fRs in a test file, the command \fBcleanupTests\fR |
---|
| 1012 | should be called. |
---|
| 1013 | .IP [7] |
---|
| 1014 | Here is a sketch of a sample test file illustrating those points: |
---|
| 1015 | .RS |
---|
| 1016 | .PP |
---|
| 1017 | .CS |
---|
| 1018 | package require tcltest 2.2 |
---|
| 1019 | eval \fB::tcltest::configure\fR $argv |
---|
| 1020 | package require example |
---|
| 1021 | namespace eval ::example::test { |
---|
| 1022 | namespace import ::tcltest::* |
---|
| 1023 | \fBtestConstraint\fR X [expr {...}] |
---|
| 1024 | variable SETUP {#common setup code} |
---|
| 1025 | variable CLEANUP {#common cleanup code} |
---|
| 1026 | \fBtest\fR example-1 {} -setup $SETUP -body { |
---|
| 1027 | # First test |
---|
| 1028 | } -cleanup $CLEANUP -result {...} |
---|
| 1029 | \fBtest\fR example-2 {} -constraints X -setup $SETUP -body { |
---|
| 1030 | # Second test; constrained |
---|
| 1031 | } -cleanup $CLEANUP -result {...} |
---|
| 1032 | \fBtest\fR example-3 {} { |
---|
| 1033 | # Third test; no context required |
---|
| 1034 | } {...} |
---|
| 1035 | \fBcleanupTests\fR |
---|
| 1036 | } |
---|
| 1037 | namespace delete ::example::test |
---|
| 1038 | .CE |
---|
| 1039 | .RE |
---|
| 1040 | .PP |
---|
| 1041 | The next level of organization is a full test suite, made up of several |
---|
| 1042 | test files. One script is used to control the entire suite. The |
---|
| 1043 | basic function of this script is to call \fBrunAllTests\fR after |
---|
| 1044 | doing any necessary setup. This script is usually named \fBall.tcl\fR |
---|
| 1045 | because that is the default name used by \fBrunAllTests\fR when combining |
---|
| 1046 | multiple test suites into one testing run. |
---|
| 1047 | .IP [8] |
---|
| 1048 | Here is a sketch of a sample test suite master script: |
---|
| 1049 | .RS |
---|
| 1050 | .PP |
---|
| 1051 | .CS |
---|
| 1052 | package require Tcl 8.4 |
---|
| 1053 | package require tcltest 2.2 |
---|
| 1054 | package require example |
---|
| 1055 | \fB::tcltest::configure\fR -testdir \e |
---|
| 1056 | [file dirname [file normalize [info script]]] |
---|
| 1057 | eval \fB::tcltest::configure\fR $argv |
---|
| 1058 | \fB::tcltest::runAllTests\fR |
---|
| 1059 | .CE |
---|
| 1060 | .RE |
---|
| 1061 | .SH COMPATIBILITY |
---|
| 1062 | .PP |
---|
| 1063 | A number of commands and variables in the \fB::tcltest\fR namespace |
---|
| 1064 | provided by earlier releases of \fBtcltest\fR have not been documented |
---|
| 1065 | here. They are no longer part of the supported public interface of |
---|
| 1066 | \fBtcltest\fR and should not be used in new test suites. However, |
---|
| 1067 | to continue to support existing test suites written to the older |
---|
| 1068 | interface specifications, many of those deprecated commands and |
---|
| 1069 | variables still work as before. For example, in many circumstances, |
---|
| 1070 | \fBconfigure\fR will be automatically called shortly after |
---|
| 1071 | \fBpackage require tcltest 2.1\fR succeeds with arguments |
---|
| 1072 | from the variable \fB::argv\fR. This is to support test suites |
---|
| 1073 | that depend on the old behavior that \fBtcltest\fR was automatically |
---|
| 1074 | configured from command line arguments. New test files should not |
---|
| 1075 | depend on this, but should explicitly include |
---|
| 1076 | .PP |
---|
| 1077 | .CS |
---|
| 1078 | eval \fB::tcltest::configure\fR $::argv |
---|
| 1079 | .CE |
---|
| 1080 | .PP |
---|
| 1081 | to establish a configuration from command line arguments. |
---|
| 1082 | .SH "KNOWN ISSUES" |
---|
| 1083 | There are two known issues related to nested evaluations of \fBtest\fR. |
---|
| 1084 | The first issue relates to the stack level in which test scripts are |
---|
| 1085 | executed. Tests nested within other tests may be executed at the same |
---|
| 1086 | stack level as the outermost test. For example, in the following code: |
---|
| 1087 | .PP |
---|
| 1088 | .CS |
---|
| 1089 | \fBtest\fR level-1.1 {level 1} { |
---|
| 1090 | -body { |
---|
| 1091 | \fBtest\fR level-2.1 {level 2} { |
---|
| 1092 | } |
---|
| 1093 | } |
---|
| 1094 | } |
---|
| 1095 | .CE |
---|
| 1096 | .PP |
---|
| 1097 | any script executed in level-2.1 may be executed at the same stack |
---|
| 1098 | level as the script defined for level-1.1. |
---|
| 1099 | .PP |
---|
| 1100 | In addition, while two \fBtest\fRs have been run, results will only |
---|
| 1101 | be reported by \fBcleanupTests\fR for tests at the same level as |
---|
| 1102 | test level-1.1. However, test results for all tests run prior to |
---|
| 1103 | level-1.1 will be available when test level-2.1 runs. What this |
---|
| 1104 | means is that if you try to access the test results for test level-2.1, |
---|
| 1105 | it will may say that |
---|
| 1106 | .QW m |
---|
| 1107 | tests have run, |
---|
| 1108 | .QW n |
---|
| 1109 | tests have been skipped, |
---|
| 1110 | .QW o |
---|
| 1111 | tests have passed and |
---|
| 1112 | .QW p |
---|
| 1113 | tests have failed, where |
---|
| 1114 | .QW m , |
---|
| 1115 | .QW n , |
---|
| 1116 | .QW o , |
---|
| 1117 | and |
---|
| 1118 | .QW p |
---|
| 1119 | refer to tests that were run at the same test level as test level-1.1. |
---|
| 1120 | .PP |
---|
| 1121 | Implementation of output and error comparison in the test command |
---|
| 1122 | depends on usage of ::puts in your application code. Output is |
---|
| 1123 | intercepted by redefining the ::puts command while the defined test |
---|
| 1124 | script is being run. Errors thrown by C procedures or printed |
---|
| 1125 | directly from C applications will not be caught by the test command. |
---|
| 1126 | Therefore, usage of the \fB\-output\fR and \fB\-errorOutput\fR |
---|
| 1127 | options to \fBtest\fR is useful only for pure Tcl applications |
---|
| 1128 | that use \fB::puts\fR to produce output. |
---|
| 1129 | .SH KEYWORDS |
---|
| 1130 | test, test harness, test suite |
---|