[http://www.tcl.tk/man/tcl/TclCmd/tcltest.htm%|%official reference]: http://tmml.sourceforge.net/doc/tcl/tcltest.html [https://wuhrr.wordpress.com/2011/03/28/getting-started-with-tcltest/%|%Getting Started with tcltest], [Hai Vu], 2011-03-28: http://www.tcl.tk/man/tcl8.5/TclCmd/tcltest.htm [https://wuhrr.wordpress.com/2011/03/29/tcltest-part-2-multi-module-test-suite/%|%tcltest Part 2: Multi-Module Test Suite], [Hai Vu], 2011-03-29: Version 2, distributed with Tcl from version 8.4, is much more flexible in the The tcltest 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. Tcltest is bundled into the [Tcl] software core distribution. kind of matching it permits. See [tcltest customMatch] for some examples. Scripts for `test` options like `-setup`, `-body`, and `-cleanup` are evaluated When working with tcltest, recall that the [return] command is not just for procedures, but can be used in scripts, such as the body of a test. See [return], [source], and [eval] for other details. The last line of a test is often [return] or [set]. Customizing the output format of cleanupTests is not very feasible at this Scripts for [[test]] options like ''-setup'', ''-body'', and '--cleanup'' are evaluated in the caller's scope. This is the same rule as for other control structure commands like [if] or [while]. Any command that takes a script as an argument and controls something about how that script is evaluated can be viewed as a kind of control structure. Another aspect of the control structure behaviour of [[test]] is that '''-constraints'' makes execution of other scripts conditional. time, as it is used as a programmatic interface for sub-processes in [runAllTests]. ** Alternatives ** [New Test Package] ** Running tcltest ** [tcltap], a simple alternative for the small test To run the Tcl source code test suite against another installed Tcl interpreter: ======none tclsh all.tcl ====== ** Tutorials ** | [http://web.archive.org/web/20080804010056/www.tclscripting.com/articles/apr06/article2.html%|%Installing tcltest%|%] |[Bryan Oakley] ,2006. How to install tcltest | | [http://web.archive.org/web/20080617153002/www.tclscripting.com/articles/apr06/article1.html%|%Getting started with tcltest%|%] | by [Bryan Oakley] ,2006. How to use tcltest | *** Run a Tcl test in verbose mode *** ** Examples ** A wonderful addition to this page would be instructions on how to run [How to write tcltest result values] [DGP] answers: [Your first tcltests] ======none *** complex results *** [RHS] One way to handle tests that the ''-result'' option can't handle is to do something like: test mytest-1.1 { test mytest-1.1 { Calling my proc should always return a list of at least length 3 } -body { set result [myProc a b c d e] # -result can't handle {>= llength 3}, so we test it here expr { [llength $result] >= 3 } } -result {1} ---- [customMatch] can also be used to the same effect: Define a script that compares a an actual result with a target result. Then use [customMatch] to "register" that script for the ''-match'' option. The script should return a boolean option indicating match or no match. ---- ** Other ** [A look at the Tcl test suite with gcov] ** Testimonials ** [VI] : 2003/10/02. We at [http://www.comit.com] use Tcl (and Tk) extensively. We use Tcl for hardware testing in simulation (think multimillion-gate , multifunction asic verification). One of the major factors in our initial decision to use Tcl and our continuing to use tcl is tcltest. We use most tcltest features including constraints and are very pleased with the easy configuration of tests and the reporting. I do have gripes, but relatively minor, and since it is pure Tcl, we can change it anyways.. [PYK] 2015-04-09: One strategy for some complex tests is to set `-result` to <> A wonderful addition to this page would be instructions on how to run one particular test, using verbose mode, for the purpose of reporting test suite failures to a package developer. [[A Pythoneer has written an article--which [DGP] answers: make TESTFLAGS='-verbose tpse -file safe.test' test ---- [CL] can locate if helpful--illustrating use of PyUnit with Roman numeral conversion. In the absence of any other inspiration, maybe someone wants to steal that example ...]] [RS], off page topic: See also [Roman numbers] for Tcl routines. ---- [AK]: Most modules in [tcllib] come with .test files using tcltest for regression testing. [davidw] 2003-10-03: I am doing some work to improve tcltest, specifically to give it an API so that you can programmatically fetch information about the test results. I would love to hear what sorts of features you would find useful - feel free to drop me email. [davidw] 2003/10/03: I am doing some work to improve tcltest, specifically to give it an API so that you can programmatically fetch information about the test results. I would love to hear what sorts of features you would find useful - feel free to drop me email. ---- [disneylogic] It would be useful to have a callback option, prefixed determine the correctness of a test. In lieu of demanding a real value to compare or abusing return codes, this would adjust 'tcltest' to perform more like SUnit [http://sourceforge.net/projects/sunit/] in the Beck testing framework [http://www.xprogramming.com/testfram.htm]. I encountered this when I was trying to write a routine to do sampling without replacement and could not specify a specific result to use to compare. If there is already some way of doing this, please, please specify it here! I waded through the man page for a bit and couldn't find anything, particularly in the usage of 'test' section. [DGP]: Can you provide an example of what a test '''[DGP]''' Can you provide an example of what a test for `test` ? Assume the reader knows nothing about for [test] ? Assume the reader knows nothing about ---- [LV]: I have a programming ''itch'' and am wondering if tcltest will help me scratch this itch. [LV] I have a programming ''itch'' and am wondering if tcltest will help me scratch this itch. Problem: set up regression testing of a client/server command line and stdout/return code related pair of applications. Currently, I'd love to find some help, tutorials, examples, etc. of how others are successfully doing this sort of thing with the result being test cases that are nearly trivial to read and write. I'd like to '''not''' have to teach people all of tcl before they can write new test cases. Ideally, having a half dozen or so examples should provide enough context to write additional code. I'd also like suggestions for '''best practices''' relating to this sort of use of tcltest. Thanks! ---- [fermulator]: If a particular test spews out a bunch of debug information (i.e. 'test debug mode'), is there a way to redirect stdout, for a specific test, to /dev/null? I can't seem to find a way to hide stdout. It's basically: [fermulator] If a particular test spews out a bunch of debug information (i.e. 'test debug mode'), is there a way to redirect stdout, for a specific test, to /dev/null? I can't seem to find a way to hide stdout. It's basically: ====== test print_debug_true { test print_debug_true \ { work as expected (no errors are caught). } -setup { } \ -setup \ { $myObj setDebug true } -body { } \ -body \ { # If it fails, error out, else return PASS. if { [catch {$myObj doStuff} err] } { if { [catch {$myObj doStuff} err] } \ { } return PASS } -result {PASS} } \ -result {PASS} When I run the above test, stdout on the test output gets spammed with a whack of debug information, and it "skews" the high level view of which tests are running, passing, failing, etc. <> <> Testing | Package | Command | Tcl | Arts and crafts of Tcl-Tk programming <> Testing | Package | Command | Tcl | Tcl syntax help | Arts and crafts of Tcl-Tk programming