$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
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
This metacommand enables debug tests with the [[_ASSERT]] macro. | |||
Line 12: | Line 12: | ||
{{PageAvailability}} | {{PageAvailability}} | ||
* '''QB64 1 | * '''QB64 2.1 and up''' (QB64 Team) | ||
* '''QBPE 0.5 and up''' (QB64 Phoenix Edition) | * '''QBPE 0.5 and up''' (QB64 Phoenix Edition) | ||
{{PageExamples}} | {{PageExamples}} | ||
;Example:Adding test checks for parameter inputs in a function. | |||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|$ASSERTS}}:CONSOLE | {{Cl|$ASSERTS}}:CONSOLE | ||
{{Cl|DO}} | {{Cl|DO}} | ||
a = {{Cl|INT}}({{Cl|RND}} * 10) | a = {{Cl|INT}}({{Cl|RND}} * 10) | ||
Line 27: | Line 27: | ||
{{Cl|_LIMIT}} 3 | {{Cl|_LIMIT}} 3 | ||
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|_KEYHIT}} | {{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|_KEYHIT}} | ||
{{Cl|FUNCTION}} myFunc$ (value {{Cl|AS}} {{Cl|SINGLE}}) | {{Cl|FUNCTION}} myFunc$ (value {{Cl|AS}} {{Cl|SINGLE}}) | ||
{{Cl|_ASSERT}} value > 0, "Value cannot be zero" | {{Cl|_ASSERT}} value > 0, "Value cannot be zero" | ||
{{Cl|_ASSERT}} value <= 10, "Value cannot exceed 10" | {{Cl|_ASSERT}} value <= 10, "Value cannot exceed 10" | ||
{{Cl|IF}} value > 1 {{Cl|THEN}} plural$ = "s" | {{Cl|IF}} value > 1 {{Cl|THEN}} plural$ = "s" | ||
myFunc$ = {{Cl|STRING$}}(value, "*") + {{Cl|STR$}}(value) + " star" + plural$ + " :-)" | myFunc$ = {{Cl|STRING$}}(value, "*") + {{Cl|STR$}}(value) + " star" + plural$ + " :-)" |
Revision as of 22:31, 30 April 2022
This metacommand enables debug tests with the _ASSERT macro.
Syntax
Description
- If an error message is passed to the _ASSERT statement, it is displayed in the console window if $ASSERTS:CONSOLE is used.
Availability
- QB64 2.1 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