$ASSERTS
Jump to navigation
Jump to search
The $ASSERTS metacommand enables debug tests with the _ASSERT macro.
Syntax
- $ASSERTS
- $ASSERTS:CONSOLE
Description
- This metacommand does not require a comment ' or REM before it. There is no space between the metacommand name, the colon and the CONSOLE parameter.
- If this metacommand is used in a program and any of the set _ASSERT checkpoints will fail, then the program will stop with an _ASSERT failed error.
- Detailed error messages passed to the _ASSERT statement will be displayed in the console window, but only if $ASSERTS:CONSOLE is used.
- The $ASSERTS metacommand serves as main switch to enable debug tests during development. Later you just need to remove the metacommand while leaving all the _ASSERT statements in place for later debugging sessions, they are simply ignored without the metacommand.
- In newer versions a precompiler flag named _ASSERTS_ is available (see Availability):
Availability
- Since QB64-PE v4.0.0 the precompiler flag _ASSERTS_ indicates the state of $ASSERTS at compile time.
Examples
- Example
- Adding test checks for parameter inputs in a function.
$ASSERTS:CONSOLE DO a = INT(RND * 10) b$ = myFunc$(a) PRINT a, , b$ _LIMIT 3 LOOP UNTIL _KEYHIT END FUNCTION myFunc$ (value AS SINGLE) _ASSERT value > 0, "Value cannot be zero" _ASSERT value <= 10, "Value cannot exceed 10" IF value > 1 THEN plural$ = "s" myFunc$ = STRING$(value, "*") + STR$(value) + " star" + plural$ + " :-)" END FUNCTION |
See also