tcltest.n

来自「tcl是工具命令语言」· N 代码 · 共 1,066 行 · 第 1/3 页

N
1,066
字号
'\"'\" Copyright (c) 1990-1994 The Regents of the University of California'\" Copyright (c) 1994-1997 Sun Microsystems, Inc.'\" Copyright (c) 1998-1999 Scriptics Corporation'\" Copyright (c) 2000 Ajuba Solutions'\" Contributions from Don Porter, NIST, 2002. (not subject to US copyright)'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" RCS: @(#) $Id: tcltest.n,v 1.38 2003/01/24 16:33:35 dgp Exp $'\" .so man.macros.TH "tcltest" n 2.2 tcltest "Tcl Bundled Packages".BS'\" Note:  do not modify the .SH NAME line immediately below!.SH NAMEtcltest \- Test harness support code and utilities.SH SYNOPSIS.nf\fBpackage require tcltest ?2.2?\fR.sp\fBtcltest::test \fIname description ?option value ...?\fR\fBtcltest::test \fIname description ?constraints? body result\fR.sp\fBtcltest::loadTestedCommands\fR\fBtcltest::makeDirectory \fIname ?directory?\fR\fBtcltest::removeDirectory \fIname ?directory?\fR\fBtcltest::makeFile \fIcontents name ?directory?\fR\fBtcltest::removeFile \fIname ?directory?\fR\fBtcltest::viewFile \fIname ?directory?\fR\fBtcltest::cleanupTests \fI?runningMultipleTests?\fR\fBtcltest::runAllTests\fR.sp.VS 2.1\fBtcltest::configure\fR\fBtcltest::configure \fIoption\fR\fBtcltest::configure \fIoption value ?option value ...?\fR\fBtcltest::customMatch \fImode command\fR.VE\fBtcltest::testConstraint \fIconstraint ?value?\fR\fBtcltest::outputChannel \fI?channelID?\fR\fBtcltest::errorChannel \fI?channelID?\fR\fBtcltest::interpreter \fI?interp?\fR.sp\fBtcltest::debug \fI?level?\fR\fBtcltest::errorFile \fI?filename?\fR\fBtcltest::limitConstraints \fI?boolean?\fR\fBtcltest::loadFile \fI?filename?\fR\fBtcltest::loadScript \fI?script?\fR\fBtcltest::match \fI?patternList?\fR\fBtcltest::matchDirectories \fI?patternList?\fR\fBtcltest::matchFiles \fI?patternList?\fR\fBtcltest::outputFile \fI?filename?\fR\fBtcltest::preserveCore \fI?level?\fR\fBtcltest::singleProcess \fI?boolean?\fR\fBtcltest::skip \fI?patternList?\fR\fBtcltest::skipDirectories \fI?patternList?\fR\fBtcltest::skipFiles \fI?patternList?\fR\fBtcltest::temporaryDirectory \fI?directory?\fR\fBtcltest::testsDirectory \fI?directory?\fR\fBtcltest::verbose \fI?level?\fR.sp\fBtcltest::test \fIname description optionList\fR\fBtcltest::bytestring \fIstring\fR\fBtcltest::normalizeMsg \fImsg\fR\fBtcltest::normalizePath \fIpathVar\fR\fBtcltest::workingDirectory \fI?dir?\fR.fi.BE.SH DESCRIPTION.PPThe \fBtcltest\fR package provides several utility commands usefulin the construction of test suites for code instrumented to berun by evaluation of Tcl commands.  Notably the built-in commandsof the Tcl library itself are tested by a test suite using thetcltest package..PPAll the commands provided by the \fBtcltest\fR package are definedin and exported from the \fB::tcltest\fR namespace, as indicated inthe \fBSYNOPSIS\fR above.  In the following sections, all commandswill be described by their simple names, in the interest of brevity..PPThe central command of \fBtcltest\fR is [\fBtest\fR] that definesand runs a test.  Testing with [\fBtest\fR] involves evaluationof a Tcl script and comparing the result to an expected result, asconfigured and controlled by a number of options.  Several othercommands provided by \fBtcltest\fR govern the configuration of[\fBtest\fR] and the collection of many [\fBtest\fR] commands intotest suites..PPSee \fBCREATING TEST SUITES WITH TCLTEST\fR below for an extended exampleof how to use the commands of \fBtcltest\fR to produce test suitesfor your Tcl-enabled code..SH COMMANDS.TP\fBtest\fR \fIname description ?option value ...?\fRDefines and possibly runs a test with the name \fIname\fR anddescription \fIdescription\fR.  The name and description of a testare used in messages reported by [\fBtest\fR] during thetest, as configured by the options of \fBtcltest\fR.  Theremaining \fIoption value\fR arguments to [\fBtest\fR]define the test, including the scripts to run, the conditionsunder which to run them, the expected result, and the meansby which the expected and actual results should be compared.See \fBTESTS\fR below for a complete description of the validoptions and how they define a test.  The [\fBtest\fR] commandreturns an empty string.  .TP\fBtest\fR \fIname description ?constraints? body result\fRThis form of [\fBtest\fR] is provided to support test suites writtenfor version 1 of the \fBtcltest\fR package, and also a simplerinterface for a common usage.  It is the same as[\fBtest\fR \fIname description\fB -constraints \fIconstraints\fB -body\fIbody\fB -result \fIresult\fR].  All other options to [\fBtest\fR]take their default values.  When \fIconstraints\fR is omitted, thisform of [\fBtest\fR] can be distinguished from the first becauseall \fIoption\fRs begin with ``-''..TP\fBloadTestedCommands\fREvaluates in the caller's context the script specified by [\fBconfigure -load\fR] or [\fBconfigure -loadfile\fR].Returns the result of that script evaluation, including any errorraised by the script.  Use this command and the relatedconfiguration options to provide the commands to be tested tothe interpreter running the test suite..TP\fBmakeFile\fR \fIcontents name ?directory?\fRCreates a file named \fIname\fR relative todirectory \fIdirectory\fR and write \fIcontents\fRto that file using the encoding [\fBencoding system\fR].If \fIcontents\fR does not end with a newline, a newlinewill be appended so that the file named \fIname\fRdoes end with a newline.  Because the system encoding is used,this command is only suitable for making text files.The file will be removed by the next evaluationof [\fBcleanupTests\fR], unless it is removed by[\fBremoveFile\fR] first.  The default value of\fIdirectory\fR is the directory [\fBconfigure -tmpdir\fR].Returns the full path of the file created.  Use this commandto create any text file required by a test with contents as needed..TP\fBremoveFile\fR \fIname ?directory?\fRForces the file referenced by \fIname\fR to be removed.  This file nameshould be relative to \fIdirectory\fR.   The default value of\fIdirectory\fR is the directory [\fBconfigure -tmpdir\fR].Returns an empty string.  Use this command to delete filescreated by [\fBmakeFile\fR].  .TP\fBmakeDirectory\fR \fIname ?directory?\fRCreates a directory named \fIname\fR relative to directory \fIdirectory\fR.The directory will be removed by the next evaluation of [\fBcleanupTests\fR],unless it is removed by [\fBremoveDirectory\fR] first.The default value of \fIdirectory\fR is the directory[\fBconfigure -tmpdir\fR].Returns the full path of the directory created.  Use this commandto create any directories that are required to exist by a test..TP\fBremoveDirectory\fR \fIname ?directory?\fRForces the directory referenced by \fIname\fR to be removed. Thisdirectory should be relative to \fIdirectory\fR.The default value of \fIdirectory\fR is the directory[\fBconfigure -tmpdir\fR].Returns an empty string.  Use this command to delete any directoriescreated by [\fBmakeDirectory\fR].  .TP\fBviewFile\fR \fIfile ?directory?\fRReturns the contents of \fIfile\fR, except for anyfinal newline, just as [\fBread -nonewline\fR] would return.This file name should be relative to \fIdirectory\fR.   The default value of \fIdirectory\fR is the directory[\fBconfigure -tmpdir\fR].  Use this commandas a convenient way to turn the contents of a file generatedby a test into the result of that test for matching againstan expected result.  The contents of the file are read usingthe system encoding, so its usefulness is limited to textfiles..TP\fBcleanupTests\fRIntended to clean up and summarize after several tests have beenrun.  Typically called once per test file, at the end of the fileafter all tests have been completed.  For best effectiveness, besure that the [\fBcleanupTests\fR] is evaluated even if an erroroccurs earlier in the test file evaluation.  .spPrints statistics about the tests run and removes files that werecreated by [\fBmakeDirectory\fR] and [\fBmakeFile\fR] since thelast [\fBcleanupTests\fR].  Names of files and directories in the directory [\fBconfigure -tmpdir\fR] created sincethe last [\fBcleanupTests\fR], but not created by[\fBmakeFile\fR] or [\fBmakeDirectory\fR] are printedto [\fBoutputChannel\fR].  This command also restores the originalshell environment, as described by the ::envarray. Returns an empty string..TP\fBrunAllTests\fRThis is a master command meant to run an entire suite of tests,spanning multiple files and/or directories, as governed bythe configurable options of \fBtcltest\fR.  See \fBRUNNING ALL TESTS\fRbelow for a complete description of the many variations possiblewith [\fBrunAllTests\fR]..SH "CONFIGURATION COMMANDS".VS.TP\fBconfigure\fRReturns the list of configurable options supported by \fBtcltest\fR.See \fBCONFIGURABLE OPTIONS\fR below for the full list of options,their valid values, and their effect on \fBtcltest\fR operations..TP\fBconfigure \fIoption\fRReturns the current value of the supported configurable option \fIoption\fR.Raises an error if \fIoption\fR is not a supported configurable option..TP\fBconfigure \fIoption value ?option value ...?\fRSets the value of each configurable option \fIoption\fR to thecorresponding value \fIvalue\fR, in order.  Raises an error ifan \fIoption\fR is not a supported configurable option, or if\fIvalue\fR is not a valid value for the corresponding \fIoption\fR,or if a \fIvalue\fR is not provided.  When an error is raised, theoperation of [\fBconfigure\fR] is halted, and subsequent \fIoption value\fRarguments are not processed..spIf the environment variable \fB::env(TCLTEST_OPTIONS)\fR exists whenthe \fBtcltest\fR package is loaded (by [\fBpackage require tcltest\fR])then its value is taken as a list of arguments to pass to [\fBconfigure\fR].This allows the default values of the configuration options to beset by the environment..TP\fBcustomMatch \fImode script\fRRegisters \fImode\fR as a new legal value of the \fB-match\fR optionto [\fBtest\fR].  When the \fB-match \fImode\fR option ispassed to [\fBtest\fR], the script \fIscript\fR will be evaluatedto compare the actual result of evaluating the body of the testto the expected result.To perform the match, the \fIscript\fR is completed with two additionalwords, the expected result, and the actual result, and the completed scriptis evaluated in the global namespace.The completed script is expected to return a boolean value indicatingwhether or not the results match.  The built-in matching modes of[\fBtest\fR] are \fBexact\fR, \fBglob\fR, and \fBregexp\fR..VE.TP\fBtestConstraint \fIconstraint ?boolean?\fRSets or returns the boolean value associated with the named \fIconstraint\fR.See \fBTEST CONSTRAINTS\fR below for more information..TP\fBinterpreter\fR \fI?executableName?\fRSets or returns the name of the executable to be [\fBexec\fR]ed by[\fBrunAllTests\fR] to run each test file when[\fBconfigure -singleproc\fR] is false.The default value for [\fBinterpreter\fR] is the name of thecurrently running program as returned by [\fBinfo nameofexecutable\fR]..TP\fBoutputChannel\fR \fI?channelID?\fRSets or returns the output channel ID.  This defaults to stdout.Any test that prints test related output should sendthat output to [\fBoutputChannel\fR] rather than lettingthat output default to stdout..TP\fBerrorChannel\fR \fI?channelID?\fRSets or returns the error channel ID.  This defaults to stderr.Any test that prints error messages should sendthat output to [\fBerrorChannel\fR] rather than printingdirectly to stderr..SH "SHORTCUT COMMANDS".TP\fBdebug \fI?level?\fRSame as [\fBconfigure -debug \fI?level?\fR]..TP\fBerrorFile \fI?filename?\fRSame as [\fBconfigure -errfile \fI?filename?\fR]..TP\fBlimitConstraints \fI?boolean?\fRSame as [\fBconfigure -limitconstraints \fI?boolean?\fR]..TP\fBloadFile \fI?filename?\fRSame as [\fBconfigure -loadfile \fI?filename?\fR]..TP\fBloadScript \fI?script?\fRSame as [\fBconfigure -load \fI?script?\fR]..TP\fBmatch \fI?patternList?\fRSame as [\fBconfigure -match \fI?patternList?\fR]..TP\fBmatchDirectories \fI?patternList?\fRSame as [\fBconfigure -relateddir \fI?patternList?\fR]..TP\fBmatchFiles \fI?patternList?\fRSame as [\fBconfigure -file \fI?patternList?\fR]..TP\fBoutputFile \fI?filename?\fRSame as [\fBconfigure -outfile \fI?filename?\fR]..TP\fBpreserveCore \fI?level?\fRSame as [\fBconfigure -preservecore \fI?level?\fR]..TP\fBsingleProcess \fI?boolean?\fRSame as [\fBconfigure -singleproc \fI?boolean?\fR]..TP\fBskip \fI?patternList?\fRSame as [\fBconfigure -skip \fI?patternList?\fR]..TP\fBskipDirectories \fI?patternList?\fRSame as [\fBconfigure -asidefromdir \fI?patternList?\fR]..TP\fBskipFiles \fI?patternList?\fRSame as [\fBconfigure -notfile \fI?patternList?\fR]..TP\fBtemporaryDirectory \fI?directory?\fRSame as [\fBconfigure -tmpdir \fI?directory?\fR]..TP\fBtestsDirectory \fI?directory?\fRSame as [\fBconfigure -testdir \fI?directory?\fR]..TP\fBverbose \fI?level?\fRSame as [\fBconfigure -verbose \fI?level?\fR]..SH "OTHER COMMANDS".PPThe remaining commands provided by \fBtcltest\fR have betteralternatives provided by \fBtcltest\fR or \fBTcl\fR itself.  Theyare retained to support existing test suites, but should be avoidedin new code..TP\fBtest\fR \fIname description optionList\fRThis form of [\fBtest\fR] was provided to enable passing manyoptions spanning several lines to [\fBtest\fR] as a singleargument quoted by braces, rather than needing to backslash quotethe newlines between arguments to [\fBtest\fR].  The \fIoptionList\fRargument is expected to be a list with an even number of elementsrepresenting \fIoption\fR and \fIvalue\fR arguments to passto [\fBtest\fR].  However, these values are not passed directly, asin the alternate forms of [\fBswitch\fR].  Instead, this form makesan unfortunate attempt to overthrow Tcl's substitution rules byperforming substitutions on some of the list elements as an attempt toimplement a ``do what I mean'' interpretation of a brace-enclosed``block''.  The result is nearly impossible to document clearly, andfor that reason this form is not recommended.  See the examples in\fBCREATING TEST SUITES WITH TCLTEST\fR below to see that thisform is really not necessary to avoid backslash-quoted newlines.If you insist on using this form, examinethe source code of \fBtcltest\fR if you want to know the substitutiondetails, or just enclose the third through last argumentto [\fBtest\fR] in braces and hope for the best..TP\fBworkingDirectory\fR \fI?directoryName?\fRSets or returns the current working directory when the test suite isrunning.  The default value for workingDirectory is the directory inwhich the test suite was launched.  The Tcl commands [\fBcd\fR] and[\fBpwd\fR] are sufficient replacements..TP\fBnormalizeMsg\fR \fImsg\fRReturns the result of removing the ``extra'' newlines from \fImsg\fR,where ``extra'' is rather imprecise.  Tcl offers plenty of stringprocessing commands to modify strings as you wish, and[\fBcustomMatch\fR] allows flexible matching of actual and expectedresults.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?