NAME

assert - Evaluate assertions and throw errors if failed. Useful for debugging and validity testing.

SYNOPSIS

assert conditions

DESCRIPTION

This command is used to perform a series of tests inside a Tcl script (usually validity tests, such as range testing and type checking). The argument conditions is a newline-separated Tcl string containing a sequence of conditions (ie boolean expressions) to be checked. The syntax of these conditions is the same that is used by the if and expr commands. Assert will test these conditions sequentially until a test fails, in this case an exception is thrown. If all tests are successful then assert returns a null string.

Assert is exception-aware. That means it throws exceptions that can be handled by try statements. The exception type thrown is Assertion.

KNOWN BUGS/LIMITATIONS

Conditions cannot spawn multiple lines, even if they are well-formed Tcl lists. This is due to the condition block being split at each newline character. For an expression to spawn several lines, each line must end with a backslash "\" character. For example: is invalid, whereas is allowed. This in inconsistent with expr, where both forms are allowed, so this is likely to change in future versions (if enough people ask for that ;-).

SEE ALSO

expr(n), if(n), try

KEYWORDS

assertion, debugging, validity