tcltest.n

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

N
1,066
字号
.TP\fBnormalizePath\fR \fIpathVar\fRResolves symlinks in a path, thus creating a path without internalredirection.  It is assumed that \fIpathVar\fR is absolute.\fIpathVar\fR is modified in place.  The Tcl command [\fBfile normalize\fR]is a sufficient replacement..TP\fBbytestring\fR \fIstring\fRConstruct a string that consists of the requested sequence of bytes,as opposed to a string of properly formed UTF-8 characters using thevalue supplied in \fIstring\fR.  This allows the tester to createdenormalized or improperly formed strings to pass to C procedures thatare supposed to accept strings with embedded NULL types and confirmthat a string result has a certain pattern of bytes.  This isexactly equivalent to the Tcl command [\fBencoding convertfrom identity\fR]..SH TESTS.PPThe [\fBtest\fR] command is the heart of the \fBtcltest\fR package.Its essential function is to evaluate a Tcl script and comparethe result with an expected result.  The options of [\fBtest\fR]define the test script, the environment in which to evaluate it,the expected result, and how the compare the actual result tothe expected result.  Some configuration options of \fBtcltest\fRalso influence how [\fBtest\fR] operates..PPThe valid options for [\fBtest\fR] are summarized:.CS.ta 0.8itest \fIname\fR \fIdescription\fR	?-constraints \fIkeywordList|expression\fR?	?-setup \fIsetupScript\fR?	?-body \fItestScript\fR?	?-cleanup \fIcleanupScript\fR?	?-result \fIexpectedAnswer\fR?	?-output \fIexpectedOutput\fR?	?-errorOutput \fIexpectedError\fR?	?-returnCodes \fIcodeList\fR?	?-match \fImode\fR?.CEThe \fIname\fR may be any string.  It is conventional to choosea \fIname\fR according to the pattern:.CS\fItarget\fR-\fImajorNum\fR.\fIminorNum\fR.CEFor white-box (regression) tests, the target should be the name of theC function or Tcl procedure being tested.  For black-box tests, thetarget should be the name of the feature being tested.  Some conventionscall for the names of black-box tests to have the suffix \fB_bb\fR.Related tests should share a major number.  As a test suite evolves,it is best to have the same test name continue to correspond to thesame test, so that it remains meaningful to say things like ``Testfoo-1.3 passed in all releases up to 3.4, but began failing inrelease 3.5.''.PPDuring evaluation of [\fBtest\fR], the \fIname\fR will be comparedto the lists of string matching patterns returned by[\fBconfigure -match\fR], and [\fBconfigure -skip\fR].  The testwill be run only if \fIname\fR matches any of the patterns from[\fBconfigure -match\fR] and matches none of the patternsfrom [\fBconfigure -skip\fR]..PPThe \fIdescription\fR should be a short textual description of thetest.  The \fIdescription\fR is included in output produced by thetest, typically test failure messages.  Good \fIdescription\fR valuesshould briefly explain the purpose of the test to users of a test suite.The name of a Tcl or C function being tested should be included in thedescription for regression tests.  If the test case exists to reproducea bug, include the bug ID in the description. .PPValid attributes and associated values are:.TP\fB-constraints \fIkeywordList|expression\fRThe optional \fB-constraints\fR attribute can be list of one or morekeywords or an expression.  If the \fB-constraints\fR value is a list ofkeywords, each of these keywords should be the name of a constraintdefined by a call to [\fBtestConstraint\fR].  If any of the listedconstraints is false or does not exist, the test is skipped.  If the\fB-constraints\fR value is an expression, that expressionis evaluated. If the expression evaluates to true, then the test is run.Note that the expression form of \fB-constraints\fR may interfere with theoperation of [\fBconfigure -constraints\fR] and[\fBconfigure -limitconstraints\fR], and is not recommended.Appropriate constraints should be added to any tests that shouldnot always be run.  That is, conditional evaluation of a testshould be accomplished by the \fB-constraints\fR option, not byconditional evaluation of [\fBtest\fR].  In that way, the samenumber of tests are always reported by the test suite, thoughthe number skipped may change based on the testing environment.The default value is an empty list.  See \fBTEST CONSTRAINTS\fR below for a list of built-in constraints and information on how to add your own constraints..TP\fB-setup \fIscript\fRThe optional \fB-setup\fR attribute indicates a \fIscript\fR that will be runbefore the script indicated by the \fB-body\fR attribute.  If evaluationof \fIscript\fR raises an error, the test will fail.  The default valueis an empty script..TP\fB-body \fIscript\fRThe \fB-body\fR attribute indicates the \fIscript\fR to run to carry out the test.  It must return a result that can be checked for correctness.If evaluation of \fIscript\fR raises an error, the test will fail.The default value is an empty script..TP\fB-cleanup \fIscript\fRThe optional \fB-cleanup\fR attribute indicates a \fIscript\fR that will berun after the script indicated by the \fB-body\fR attribute.If evaluation of \fIscript\fR raises an error, the test will fail.The default value is an empty script..TP\fB-match \fImode\fRThe \fB-match\fR attribute determines how expected answers supplied by\fB-result\fR, \fB-output\fR, and \fB-errorOutput\fR are compared.  Validvalues for \fImode\fR are \fBregexp\fR, \fBglob\fR, \fBexact\fR, andany value registered by a prior call to [\fBcustomMatch\fR].  The defaultvalue is \fBexact\fR..TP\fB-result \fIexpectedValue\fRThe \fB-result\fR attribute supplies the \fIexpectedValue\fR against whichthe return value from script will be compared. The default value isan empty string..TP\fB-output \fIexpectedValue\fRThe \fB-output\fR attribute supplies the \fIexpectedValue\fR against whichany output sent to \fBstdout\fR or [\fBoutputChannel\fR] during evaluationof the script(s) will be compared.  Note that only output printed using[\fBputs\fR] is used for comparison.  If \fB-output\fR is not specified,output sent to \fBstdout\fR and [\fBoutputChannel\fR] is not processed forcomparison..TP\fB-errorOutput \fIexpectedValue\fRThe \fB-errorOutput\fR attribute supplies the \fIexpectedValue\fR againstwhich any output sent to \fBstderr\fR or [\fBerrorChannel\fR] during evaluation of the script(s) will be compared. Note that only outputprinted using [\fBputs\fR] is used for comparison.  If \fB-errorOutput\fRis not specified, output sent to \fBstderr\fR and [\fBerrorChannel\fR] isnot processed for comparison..TP\fB-returnCodes \fIexpectedCodeList\fRThe optional \fB-returnCodes\fR attribute supplies \fIexpectedCodeList\fR,a list of return codes that may be accepted from evaluation of the\fB-body\fR script.  If evaluation of the \fB-body\fR script returnsa code not in the \fIexpectedCodeList\fR, the test fails.  Allreturn codes known to [\fBreturn\fR], in both numeric and symbolicform, including extended return codes, are acceptable elements inthe \fIexpectedCodeList\fR.  Default value is \fB{ok return}\fR..PPTo pass, a test must successfully evaluate its \fB-setup\fR, \fB-body\fR,and \fB-cleanup\fR scripts.  The return code of the \fB-body\fR script andits result must match expected values, and if specified, output and errordata from the test must match expected \fB-output\fR and \fB-errorOutput\fRvalues.  If any of these conditions are not met, then the test fails.Note that all scripts are evaluated in the context of the callerof [\fBtest\fR]..PPAs long as [\fBtest\fR] is called with valid syntax and legalvalues for all attributes, it will not raise an error.  Testfailures are instead reported as output written to [\fBoutputChannel\fR].In default operation, a successful test produces no output.  The outputmessages produced by [\fBtest\fR] are controlled by the[\fBconfigure -verbose\fR] option as described in \fBCONFIGURABLE OPTIONS\fRbelow.  Any output produced by the test scripts themselves should beproduced using [\fBputs\fR] to [\fBoutputChannel\fR] or[\fBerrorChannel\fR], so that users of the test suite mayeasily capture output with the [\fBconfigure -outfile\fR] and[\fBconfigure -errfile\fR] options, and so that the \fB-output\fRand \fB-errorOutput\fR attributes work properly..SH "TEST CONSTRAINTS".PPConstraints are used to determine whether or not a test should be skipped.Each constraint has a name, which may be any string, and a booleanvalue.  Each [\fBtest\fR] has a \fB-constraints\fR value which is alist of constraint names.  There are two modes of constraint control.Most frequently, the default mode is used, indicated by a settingof [\fBconfigure -limitconstraints\fR] to false.  The test will runonly if all constraints in the list are true-valued.  Thus,the \fB-constraints\fR option of [\fBtest\fR] is a convenient, symbolicway to define any conditions required for the test to be possible ormeaningful.  For example, a [\fBtest\fR] with \fB-constraints unix\fRwill only be run if the constraint \fBunix\fR is true, which indicatesthe test suite is being run on a Unix platform..PPEach [\fBtest\fR] should include whatever \fB-constraints\fR arerequired to constrain it to run only where appropriate.  Severalconstraints are pre-defined in the \fBtcltest\fR package, listedbelow.  The registration of user-defined constraints is performedby the [\fBtestConstraint\fR] command.  User-defined constraintsmay appear within a test file, or within the script specifiedby the [\fBconfigure -load\fR] or [\fBconfigure -loadfile\fR]options..PPThe following is a list of constraints pre-defined by the\fBtcltest\fR package itself:.TP\fIsingleTestInterp\fRtest can only be run if all test files are sourced into a single interpreter.TP\fIunix\fRtest can only be run on any Unix platform.TP\fIwin\fRtest can only be run on any Windows platform.TP\fInt\fRtest can only be run on any Windows NT platform.TP\fI95\fRtest can only be run on any Windows 95 platform.TP\fI98\fRtest can only be run on any Windows 98 platform.TP\fImac\fRtest can only be run on any Mac platform.TP\fIunixOrWin\fRtest can only be run on a Unix or Windows platform.TP\fImacOrWin\fRtest can only be run on a Mac or Windows platform.TP\fImacOrUnix\fRtest can only be run on a Mac or Unix platform.TP\fItempNotWin\fRtest can not be run on Windows.  This flag is used to temporarilydisable a test. .TP\fItempNotMac\fRtest can not be run on a Mac.  This flag is usedto temporarily disable a test..TP\fIunixCrash\fRtest crashes if it's run on Unix.  This flag is used to temporarilydisable a test. .TP\fIwinCrash\fRtest crashes if it's run on Windows.  This flag is used to temporarilydisable a test. .TP\fImacCrash\fRtest crashes if it's run on a Mac.  This flag is used to temporarilydisable a test. .TP\fIemptyTest\fRtest is empty, and so not worth running, but it remains as aplace-holder for a test to be written in the future.  This constrainthas value false to cause tests to be skipped unless the user specifiesotherwise..TP\fIknownBug\fRtest is known to fail and the bug is not yet fixed.  This constrainthas value false to cause tests to be skipped unless the user specifiesotherwise..TP\fInonPortable\fRtest can only be run in some known development environment.Some tests are inherently non-portable because they depend on thingslike word length, file system configuration, window manager, etc.This constraint has value false to cause tests to be skipped unlessthe user specifies otherwise.  .TP\fIuserInteraction\fRtest requires interaction from the user.  This constraint hasvalue false to causes tests to be skipped unless the user specifiesotherwise.  .TP\fIinteractive\fRtest can only be run in if the interpreter is in interactive mode (when the global tcl_interactive variable is set to 1)..TP\fInonBlockFiles\fRtest can only be run if platform supports setting files intononblocking mode .TP\fIasyncPipeClose\fRtest can only be run if platform supports async flush and async closeon a pipe .TP\fIunixExecs\fRtest can only be run if this machine has Unix-style commands\fBcat\fR, \fBecho\fR, \fBsh\fR, \fBwc\fR, \fBrm\fR, \fBsleep\fR,\fBfgrep\fR, \fBps\fR, \fBchmod\fR, and \fBmkdir\fR available.TP\fIhasIsoLocale\fRtest can only be run if can switch to an ISO locale.TP\fIroot\fRtest can only run if Unix user is root.TP\fInotRoot\fRtest can only run if Unix user is not root.TP\fIeformat\fRtest can only run if app has a working version of sprintf with respectto the "e" format of floating-point numbers..TP\fIstdio\fRtest can only be run if [\fBinterpreter\fR] can be [\fBopen\fR]edas a pipe..PPThe alternative mode of constraint control is enabled by setting[\fBconfigure -limitconstraints\fR] to true.  With that configurationsetting, all existing constraints other than those in the constraintlist returned by [\fBconfigure -constraints\fR] are set to false.When the value of [\fBconfigure -constraints\fR]is set, all those constraints are set to true.  The effect is thatwhen both options [\fBconfigure -constraints\fR] and[\fBconfigure -limitconstraints\fR] are in use, only those tests includingonly constraints from the [\fBconfigure -constraints\fR] listare run; all others are skipped.  For example, one might setup a configuration with.CSconfigure -constraints knownBug \e          -limitconstraints true \e          -verbose pass.CEto run exactly those tests that exercise known bugs, and discoverwhether any of them pass, indicating the bug had been fixed.  .SH "RUNNING ALL TESTS".PPThe single command [\fBrunAllTests\fR] is evaluated to run an entiretest suite, spanning many files and directories.  The configurationoptions of \fBtcltest\fR control the precise operations.  The[\fBrunAllTests\fR] command begins by printing a summary of itsconfiguration to [\fBoutputChannel\fR]..PPTest files to be evaluated are sought in the directory[\fBconfigure -testdir\fR].  The list of files in that directorythat match any of the patterns in [\fBconfigure -file\fR] andmatch none of the patterns in [\fBconfigure -notfile\fR] is generatedand sorted.  Then each file will be evaluated in turn.  If[\fBconfigure -singleproc\fR] is true, then each file willbe [\fBsource\fR]d in the caller's context.  If if is false,then a copy of [\fBinterpreter\fR] will be [\fBexec\fR]d toevaluate each file.  The multi-process operation is usefulwhen testing can cause errors so severe that a process terminates.  Although such an error may terminate a childprocess evaluating one file, the master process can continuewith the rest of the test suite.  In multi-process operation,the configuration of \fBtcltest\fR in the master process ispassed to the child processes as command line arguments,with the exception of [\fBconfigure -outfile\fR].  The[\fBrunAllTests\fR] command in themaster process collects all output from the child processesand collates their results into one master report.  Anyreports of individual test failures, or messages requestedby a [\fBconfigure -verbose\fR] setting are passed directlyon to [\fBoutputChannel\fR] by the master process..PPAfter evaluating all selected test files, a summary of theresults is printed to [\fBoutputChannel\fR].  The summaryincludes the total number of [\fBtest\fR]s evaluated, brokendown into those skipped, those passed, and those failed.The summary also notes the number of files evaluated, and the namesof any files with failing tests or errors.  A list of

⌨️ 快捷键说明

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