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