$ASSERTS: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
m (Removed protection from "$ASSERTS") |
No edit summary |
||
Line 1: | Line 1: | ||
The [[$ASSERTS]] [[metacommand]] enables debug tests with the [[_ASSERT]] macro. | |||
{{PageSyntax}} | {{PageSyntax}} | ||
:[[$ASSERTS]][:CONSOLE | : [[$ASSERTS]] | ||
: [[$ASSERTS]]:CONSOLE | |||
{{PageDescription}} | {{PageDescription}} | ||
* | * 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 '''{{Text|_ASSERT failed| | * If this metacommand is used in a program and any of the set [[_ASSERT]] checkpoints will fail, then the program will stop with an '''{{Text|_ASSERT failed|red}}''' error. | ||
* Detailed error messages passed to the [[_ASSERT]] statement will be displayed in the console window, but only if [[$ASSERTS|$ASSERTS:CONSOLE]] is used. | * Detailed error messages passed to the [[_ASSERT]] statement will be displayed in the console window, but only if [[$ASSERTS|$ASSERTS:CONSOLE]] is used. | ||
Line 49: | Line 50: | ||
{{PageNavigation}} | {{PageNavigation}} | ||
[[Category:Final]] |
Revision as of 22:02, 15 June 2022
The $ASSERTS metacommand enables debug tests with the _ASSERT macro.
Syntax
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.
- Note
- This metacommand is the main switch to enable debug tests during development. Later just remove this metacommand to compile the program without debugging code, all the _ASSERT statements may remain in the code for later debugging sessions, they are simply ignored without this metacommand.
Availability
- QB64 1.4 and up (QB64 Team)
- QBPE 0.5 and up (QB64 Phoenix Edition)
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 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