From 2c7f3c5f2babd5a6ed944bc3b01123eeb2e80f10 Mon Sep 17 00:00:00 2001 From: jenn Date: Sat, 26 Jun 1999 03:47:59 +0000 Subject: This file contains what used to be in the tests/README file and documents the tcltest package. --- doc/tcltest.n | 542 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 542 insertions(+) create mode 100644 doc/tcltest.n diff --git a/doc/tcltest.n b/doc/tcltest.n new file mode 100644 index 0000000..d5feea6 --- /dev/null +++ b/doc/tcltest.n @@ -0,0 +1,542 @@ +'\" +'\" Copyright (c) 1990-1994 The Regents of the University of California +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" Copyright (c) 1998-1999 Scriptics Corporation +'\" +'\" 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.1 1999/06/26 03:47:59 jenn Exp $ +'\" +.so man.macros +.TH "Tcltest" n 8.1 Tcl "Tcl Built-In Commands" +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcltest \- Test harness support code and utilities +.SH SYNOPSIS +\fBpackage require tcltest ?1.0?\fP +.sp +\fB::tcltest::test \fIname desc ?constraint? script expectedAnswer\fR +.sp +\fB::tcltest::cleanupTests \fI?calledFromAll?\fR +.sp +\fB::tcltest::dotests \fIfile pattern\fR +.sp +\fB::tcltest::makeFile \fIcontents name\fR +.sp +\fB::tcltest::removeFile \fIname\fR +.sp +\fB::tcltest::makeDirectory \fIname\fR +.sp +\fB::tcltest::removeDirectory \fIname\fR +.sp +\fB::tcltest::viewFile \fIname\fR +.sp +\fB::tcltest::normalizeMsg \fImsg\fR +.sp +\fB::tcltest::grep \fIexpression list\fR +.sp +\fB::tcltest::bytestring \fIstring\fR +.sp +\fB::tcltest::set_iso8850_1_locale +.sp +\fB::tcltest::restore_locale +.sp +\fB::tcltest::saveState +.sp +\fB::tcltest::restoreState +.sp +\fB::tcltest::threadReap +.BE +.SH DESCRIPTION +.PP +The \fBtcltest\fR package provides the user with utility tools for +writing and running tests in the Tcl test suite. It can also be used +to create a customized test harness for an extension. +.PP +The Tcl test suite consists of multiple .test files, each of which +contains multiple test cases. Each test case consists of a call to +the test command, which specifies the name of test, a short +description, any constraints that apply to the test case, the script +to be run, and expected results. See the sections \fI"Tests"\fR and +\fI"Test Constraints"\fR and \fI"Test Files and How to Run Them"\fR +for more details. +.PP +It is also possible to add to this test harness to create your own +customized test harness implementation. For more defails, see the +section \fI"How to Customize the Test Harness"\fR. +.PP +This approach to testing was designed and initially implemented by +Mary Ann May-Pumphrey of Sun Microsystems in the early 1990's. Many +thanks to her for donating her work back to the public Tcl release. +.SH COMMANDS +.TP +\fB::tcltest::test\fP \fIname desc ?constraints? script expectedAnswer\fR +The \fB::tcltest::test\fR command is used to run a test script defined +within a test file. It prints an error message if the test fails. If +\fB::tcltest::verbose\fR has been set (either by using \fB-verbose\fR +or by manually setting the value of the variable) it can also print +out a message if the test passed or was skipped. The test will be +skipped if it doesn't match the \fB::tcltest::match\fR variable, if it +matches an element in \fB::tcltest::skip\fR, or if one of the elements +of \fIconstraint\fR turns out not to be true. See the \fI"Writing a new +test"\fR section for more details on this command. +.TP +\fB::tcltest::cleanupTests\fP \fI?calledFromAll?\fR +This command should be called at the end of a test file. It prints +statistics about the tests run and removes files that were created by +\fB::tcltest::makeDirectory\fR and \fB::tcltest::makeFile\fR. Names +of files created without the \fB::tcltest::makeFile\fR command are +printed. This command also restores the original shell +environment. The default value for \fIcalledFromAll\fR is false. +.TP +\fB::tcltest::dotests\fP \fIfile pattern\fR +Source a test file and run tests of the specified pattern. +.TP +\fB::tcltest::makeFile\fP \fIcontents name\fR +Create a file that will be automatically be removed by +\fB::tcltest::cleanupTests\fR at the end of a test run. +.TP +\fB::tcltest::removeFile\fP \fIname\fR +Force a file to be removed +.TP +\fB::tcltest::makeDirectory\fP \fIname\fR +Create a directory that will automatically be removed by +\fB::tcltest::cleanupTests\fR at the end of a test run. +.TP +\fB::tcltest::removeDirectory\fP \fIname\fR +Force a directory to be removed. +.TP +\fB::tcltest::viewFile\fP \fIname\fR +Returns the contents of a file. +.TP +\fB::tcltest::normalizeMsg\fP \fImsg\fR +Remove extra newlines from a string. +.TP +\fB::tcltest::grep\fP \fIexpression list\fR +Evaluate a given expression against each element of a list and return all +elements for which \fIexpression\fR evaluates to true. Use of the +keyword \fICURRENT_ELEMENT\fR within \fIexpression\fR will flag the +proc to use the value of the current element within the expression. +Use of the \fICURRENT_ELEMENT\fR keyword is optional. If it is left +out, it is assumed to be the final argument to the expression provided. +Examples of usage: +.DS +set subList [grep {CURRENT_ELEMENT == 1} $listOfNumbers] +set subList [grep {regexp {abc} CURRENT_ELEMENT} $listOfStrings] +grep {regexp a} $someList +.DE +.TP +\fB::tcltest::bytestring\fP \fIstring\fR +Construct a string that consists of the requested sequence of bytes, +as opposed to a string of properly formed UTF-8 characters. +.TP +\fB::tcltest::set_iso8859_1_locale\fP +Set the locale to iso8859_1 +.TP +\fB::tcltest::restore_locale\fP +Restore the locale to its original setting +.TP +\fB::tcltest::saveState\fP +Save the procedure and global variable names +.TP +\fB::tcltest::restoreState\fP +Restore the procedure and global variable names +.TP +\fB::tcltest::threadReap\fP +Kill all threads except for the main thread +.SH TESTS +The \fBtest\fR procedure runs a test script and prints an error +message if the script's result does not match the expected result. +The following is the spec for the \fBtest\fR command: +.DS +test ??