| 1 | <html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 | <title>asserterror</title> |
| 3 | <style> |
| 4 | td { padding-left: 5pt; padding-right: 5pt; } |
| 5 | th { padding-left: 5pt; padding-right: 5pt; } |
| 6 | code { white-space: pre-wrap; } |
| 7 | dd { white-space: pre-wrap; } |
| 8 | </style> |
| 9 | </head><body bgcolor="#FFFFFF"> |
| 10 | |
| 11 | <table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Monaco,Courier" size=6 color="#999900"><b> |
| 12 | asserterror |
| 13 | </b></font></table></table> |
| 14 | <p>A keyword that can be used in <a href="Scripting.html">Scripting</a>, to test whether an expected error message is indeed generated.</p> |
| 15 | <h2>Examples</h2> |
| 16 | <code> <b>asserterror</b> Unknown variable<br></code> |
| 17 | <code> a = 2 * b + 3<br></code> |
| 18 | <p>The line <code><font size=+1>a = 2 * b + 3</font></code> contains the unknown variable <code><font size=+1>b</font></code>. Therefore, the script would normally issue an error message like</p> |
| 19 | <code> Unknown variable:<br></code> |
| 20 | <code> « a = 2 * b<br></code> |
| 21 | <code> <br></code> |
| 22 | <code> Script line 2 not performed or completed:<br></code> |
| 23 | <code> « a = 2 * b + 3 »<br></code> |
| 24 | <code> Menu command “Run” not completed.<br></code> |
| 25 | <p>The line with <b><code><font size=+1>asserterror</font></code></b> prevents the error message from being popped up, and instead checks that the error message contains the string “Unknown variable”, which it does.</p> |
| 26 | <p>This one works differently:</p> |
| 27 | <code> b = 4<br></code> |
| 28 | <code> <b>asserterror</b> Unknown variable<br></code> |
| 29 | <code> a = 2 * b + 3<br></code> |
| 30 | <p>In this case the expected error message does not occur, and the script exits with the following error message:</p> |
| 31 | <code> Script assertion fails in line 2: error « Unknown variable » not raised.<br></code> |
| 32 | <code> Instead: no error.<br></code> |
| 33 | <code> <br></code> |
| 34 | <code> Script line 3 not performed or completed:<br></code> |
| 35 | <code> « a = 2 * b + 3 »<br></code> |
| 36 | <code> Menu command “Run” not completed.<br></code> |
| 37 | <p>Another case:</p> |
| 38 | <code> <b>asserterror</b> What is blabla<br></code> |
| 39 | <code> a = Create Sound from blabla: 1, 2, 3<br></code> |
| 40 | <p>In this case a different error message than the expected error message occurs, and the script exits with the following error message:</p> |
| 41 | <code> Script assertion fails in line 1: error « What is blabla » not raised.<br></code> |
| 42 | <code> Instead: Command “Create Sound from blabla:” not available for current selection.<br></code> |
| 43 | <code> <br></code> |
| 44 | <code> Script line 2 not performed or completed:<br></code> |
| 45 | <code> « a = Create Sound from blabla: 1, 2, 3 »<br></code> |
| 46 | <code> Menu command “Run” not completed.<br></code> |
| 47 | <h3>Links to this page</h3> |
| 48 | <ul> |
| 49 | <li><a href="_padLeft-S_.html"><code><font size=+1>padLeft$</font></code></a> |
| 50 | <li><a href="_padOrTruncateLeft-S_.html"><code><font size=+1>padOrTruncateLeft$</font></code></a> |
| 51 | <li><a href="_padOrTruncateRight-S_.html"><code><font size=+1>padOrTruncateRight$</font></code></a> |
| 52 | <li><a href="_padRight-S_.html"><code><font size=+1>padRight$</font></code></a> |
| 53 | <li><a href="_randomImax_.html"><code><font size=+1>randomImax</font></code></a> |
| 54 | <li><a href="_truncateLeft-S_.html"><code><font size=+1>truncateLeft$</font></code></a> |
| 55 | <li><a href="_truncateRight-S_.html"><code><font size=+1>truncateRight$</font></code></a> |
| 56 | <li><a href="Functions.html">Functions</a> |
| 57 | </ul> |
| 58 | <hr> |
| 59 | <address> |
| 60 | <p>© Paul Boersma 2023,2026</p> |
| 61 | </address> |
| 62 | </body> |
| 63 | </html> |