Assert command: Difference between revisions
(Created page with "__TOC__ {| |width="50%"| '''Action:''' |width="50%"| <span class="f_Para">Performs an equality or inequality comparison between a) the value of program data or a working_wit...") |
No edit summary |
||
Line 3: | Line 3: | ||
|width="50%"| '''Action:''' | |width="50%"| '''Action:''' | ||
|width="50%"| | |width="50%"| | ||
<span class="f_Para">Performs an equality or inequality comparison between a) the value of program data or a [[ | <span class="f_Para">Performs an equality or inequality comparison between a) the value of program data or a [[Working with macro variables|macro variable]] or [[Working with Client functions (Debugger)|Client function]], and b) a constant or the value of a macro variable or macro function. For example: </span> | ||
<span class="f_CodeExample">assert %i=</span><span class="f_=XmpPrintTable">=</span><span class="f_CodeExample">666 </span> | <span class="f_CodeExample">assert %i=</span><span class="f_=XmpPrintTable">=</span><span class="f_CodeExample">666 </span> | ||
Line 9: | Line 9: | ||
<span class="f_Para">This command lets you create simple testing macros that ensure that key elements in your code have the values you expect. If the comparison expression you construct with </span><span class="f_Monospace">assert</span><span class="f_Para"> is not logically true, you receive a failure message. If true, you receive no confirmation. </span> | <span class="f_Para">This command lets you create simple testing macros that ensure that key elements in your code have the values you expect. If the comparison expression you construct with </span><span class="f_Monospace">assert</span><span class="f_Para"> is not logically true, you receive a failure message. If true, you receive no confirmation. </span> | ||
<span class="f_Monospace">assert</span><span class="f_Para"> failure messages are displayed in the [[ | <span class="f_Monospace">assert</span><span class="f_Para"> failure messages are displayed in the [[Using the console and command line#The Console|console]], if it is open. Otherwise, they are displayed in a Windows message box. They have the following format: </span> | ||
<span class="f_CodeExample">Assert failed: </span><span class="f_CodeExample" style="font-style: italic;">failing_assert_statem</span><span class="f_CodeExample">ent </span> | <p class="syntax"><span class="f_CodeExample">Assert failed: </span><span class="f_CodeExample" style="font-style: italic;">failing_assert_statem</span><span class="f_CodeExample">ent </span></p> | ||
<span class="f_Para">For example: </span> | <span class="f_Para">For example: </span> | ||
<p class="syntax"><span class="f_CodeExample">Assert failed: assert &b </span><span class="f_=XmpPrintTable">=</span><span class="f_CodeExample"> "no way" </span></p> | |||
<span class="f_CodeExample">Assert failed: assert &b </span><span class="f_=XmpPrintTable">=</span><span class="f_CodeExample"> "no way" </span> | |||
<span class="f_Para">The </span><span class="f_Monospace">assert</span><span class="f_Para"> command syntax follows: </span> | <span class="f_Para">The </span><span class="f_Monospace">assert</span><span class="f_Para"> command syntax follows: </span> | ||
<p class="syntax"> | <p class="syntax">'''ASSERT''' | ||
'''ASSERT''' | |||
{&var|%x|g.x|f.x|$listcnt(x)|$listinf(x,y)|&&function} | {&var|%x|g.x|f.x|$listcnt(x)|$listinf(x,y)|&&function} | ||
{=|==|!=|<>} | {=|==|!=|<>} | ||
{string|[-]n|&var|&&function} | {string|[-]n|&var|&&function}</p> | ||
</p> | |||
where: | where: | ||
*<span class="f_ListBul1">&</span><span class=" | *<span class="f_ListBul1">&</span><span class="term">var</span><span class="f_ListBul1"> is a previously defined macro variable. </span> | ||
*<span class=" | *<span class="f_MonoItal">%</span><span class="term">x</span><span class="f_ListBul1"> is a mainframe variable. </span> | ||
*<span class="f_ListBul1">g.</span><span class="term">x</span><span class="f_ListBul1"> is a Debugger [[watch_global_variables.html|global variable reference]]. </span> | |||
*<span class="f_ListBul1">f.</span><span class="term">x</span><span class="f_ListBul1"> is a Debugger [[watching_fields.html|field reference]], possibly with a subscript. </span> | |||
*<span class="f_ListBul1">$listcnt/$listinf are the Debugger functions for [[watching_$lists.html|viewing $list counts and elements.]] </span> | *<span class="f_ListBul1">$listcnt/$listinf are the Debugger functions for [[watching_$lists.html|viewing $list counts and elements.]] </span> | ||
*<span class="f_ListBul1">&&</span><span class="term">function</span><span class="f_ListBul1"> is a macro function. </span> | |||
*<span class="term">string</span><span class="f_ListBul1"> is a quoted string constant (double or single quotes are valid). </span> | |||
*<span class="f_ListBul1">[-]</span><span class="term">n</span><span class="f_ListBul1"> is an integer constant with an optional leading minus sign. </span> | |||
<span class="f_Para">Here are examples of valid </span><span class="term">assert</span><span class="f_Para"> statements: </span> | |||
<span class="f_Para">Here are examples of valid </span><span class=" | |||
<p class="syntax"><span class="f_CodeExample">assert g.JACK </span><span class="f_=XmpPrintTable">=</span><span class="f_CodeExample"> "No play makes Jack a dull boy." </span> | |||
<span class="f_CodeExample"> ASSERt %s</span><span class="f_=XmpPrintTable">=</span><span class="f_CodeExample">'Hey Moe' </span> | <span class="f_CodeExample"> ASSERt %s</span><span class="f_=XmpPrintTable">=</span><span class="f_CodeExample">'Hey Moe' </span> | ||
<span class="f_CodeExample">ASSERT $listcnt(%g)</span><span class="f_=XmpPrintTable">=</span><span class="f_CodeExample">2 </span> | <span class="f_CodeExample">ASSERT $listcnt(%g)</span><span class="f_=XmpPrintTable">=</span><span class="f_CodeExample">2 </span> | ||
<span class="f_CodeExample">ASSERT $listinf(%g,2) </span><span class="f_=XmpPrintTable">=</span><span class="f_CodeExample"> " makes Jack a dull boy." </span> | <span class="f_CodeExample">ASSERT $listinf(%g,2) </span><span class="f_=XmpPrintTable">=</span><span class="f_CodeExample"> " makes Jack a dull boy." </span> | ||
<span class="f_CodeExample">assert &this </span><span class="f_=XmpPrintTable">=</span><span class="f_CodeExample"> 'that' </span> | <span class="f_CodeExample">assert &this </span><span class="f_=XmpPrintTable">=</span><span class="f_CodeExample"> 'that' </span> | ||
<span class="f_CodeExample">assert &this <> &that </span> | <span class="f_CodeExample">assert &this <> &that </span> | ||
<span class="f_EmphRed">Notes:</span><span class="f_NotesTable"> </span></p> | |||
*<span class="f_ListBul1">The</span><span class="f_NotesTable"> </span><span class="f_Monospace">[[&&assertFailureCount|&&assertFailureCount]]</span><span class="f_NotesTable">, </span><span class="f_Monospace">[[&&assertSuccessCount|&&assertSuccessCount]]</span><span class="f_NotesTable">, </span><span class="f_ListBul1">and</span><span class="f_NotesTable"> </span><span class="f_Monospace">[[&&assertStatus|&&assertStatus]]</span><span class="f_NotesTable"> </span><span class="f_ListBul1">Client</span><span class="f_NotesTable"> </span><span class="f_ListBul1">functions, as well as </span><span class="f_Monospace">[[&&globalAssertFailureCount|&&globalAssertFailureCount]]</span><span class="f_NotesTable">, </span><span class="f_Monospace">[[&&globalAssertSuccessCount|&&globalAssertSuccessCount]]</span><span class="f_NotesTable">, </span><span class="f_ListBul1">and</span><span class="f_NotesTable"> </span><span class="f_Monospace">[[&&globalAssertStatus|&&globalAssertStatus]],</span><span class="f_ListBul1"> report</span><span class="f_NotesTable"> </span><span class="f_Monospace">assert</span><span class="f_NotesTable"> </span><span class="f_ListBul1">command results. </span> | |||
*<span class="f_ListBul1">The</span><span class="f_NotesTable"> </span><span class="f_Monospace">[[ | |||
*<span class="f_ListBul1">If you are specifying a Client [[ | *<span class="f_ListBul1">If you are specifying a Client [[Setting up the ui.xml file#To set up a ui.xml file:|mapping command]] and your assertion includes an ampersand character (</span><span class="f_Monospace">&</span><span class="f_ListBul1">) or the not equal operator (</span><span class="f_Monospace"><></span><span class="f_ListBul1">), you must XML entity encode the character. For example, to map the command </span><span class="f_Monospace">assert &i<>6</span><span class="f_ListBul1">, you specify it like this: </span> | ||
<span class="f_CodeExListTable" style="font-size: 12px;"><mapping</span><span class="f_CodeExListTable" style="font-size: 11px; font-family: 'Arial Narrow';"> </span><span class="f_CodeExListTable" style="font-size: 12px;">command</span><span class="f_=XmpPrintTable" style="font-size: 12px;">=</span><span class="f_CodeExListTable" style="font-size: 12px;">"assert</span><span class="f_CodeExListTable" style="font-size: 11px; font-family: 'Arial Narrow';"> </span><span class="f_CodeExListTable" style="font-size: 12px;">&amp;i&lt;&gt;6"</span><span class="f_CodeExListTable" style="font-size: 11px; font-family: 'Arial Narrow';"> </span><span class="f_CodeExListTable" style="font-size: 12px;">button</span><span class="f_=XmpPrintTable" style="font-size: 12px;">=</span><span class="f_CodeExListTable" style="font-size: 12px;">"button9"/> </span> | <p class="syntax"><span class="f_CodeExListTable" style="font-size: 12px;"><mapping</span><span class="f_CodeExListTable" style="font-size: 11px; font-family: 'Arial Narrow';"> </span><span class="f_CodeExListTable" style="font-size: 12px;">command</span><span class="f_=XmpPrintTable" style="font-size: 12px;">=</span><span class="f_CodeExListTable" style="font-size: 12px;">"assert</span><span class="f_CodeExListTable" style="font-size: 11px; font-family: 'Arial Narrow';"> </span><span class="f_CodeExListTable" style="font-size: 12px;">&amp;i&lt;&gt;6"</span><span class="f_CodeExListTable" style="font-size: 11px; font-family: 'Arial Narrow';"> </span><span class="f_CodeExListTable" style="font-size: 12px;">button</span><span class="f_=XmpPrintTable" style="font-size: 12px;">=</span><span class="f_CodeExListTable" style="font-size: 12px;">"button9"/> </span></p> | ||
|- | |- | ||
| '''Client menu:''' | | '''Client menu:''' |
Revision as of 17:09, 7 October 2022
Action: |
Performs an equality or inequality comparison between a) the value of program data or a macro variable or Client function, and b) a constant or the value of a macro variable or macro function. For example: assert %i==666 This command lets you create simple testing macros that ensure that key elements in your code have the values you expect. If the comparison expression you construct with assert is not logically true, you receive a failure message. If true, you receive no confirmation. assert failure messages are displayed in the console, if it is open. Otherwise, they are displayed in a Windows message box. They have the following format: Assert failed: failing_assert_statement For example: Assert failed: assert &b = "no way" The assert command syntax follows: ASSERT {&var|%x|g.x|f.x|$listcnt(x)|$listinf(x,y)|&&function} {=|==|!=|<>} {string|[-]n|&var|&&function} where:
Here are examples of valid assert statements: assert g.JACK = "No play makes Jack a dull boy." ASSERt %s='Hey Moe' ASSERT $listcnt(%g)=2 ASSERT $listinf(%g,2) = " makes Jack a dull boy." assert &this = 'that' assert &this <> &that Notes:
<mapping command="assert &i<>6" button="button9"/> |
Client menu: | -- |
Introduced: | Build 28 |