Wiki

Changes between Initial Version and Version 1 of Assert

Show
Ignore:
Timestamp:
02/15/10 01:41:38 (15 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Assert

    v1 v1  
     1= Assert =  
     2 
     3The assert statement provides a way to verify the internal state of your code.  
     4To the assertion, you provide a [wiki:ConditionalExpr conditional expression] that is  
     5expected to evaluate true.[[BR]] 
     6If the verification fails (condition is false), an exception (!AssertException) is raised. 
     7 
     8The exception reports the source code of the condition, the file name, the line number,  
     9the current object and information provided as an optional second argument to the assert.  
     10However, it's rarely necessary to provide a second, informational argument because a  
     11failed assertion also reports the value of every subexpression of the condition.  
     12 
     13For example  
     14{{{ assert obj.foo < bar }}} 
     15failing its assertion will report the value of obj.foo, obj and bar.  
     16This makes assertions quick to write and easy to diagnose. 
     17 
     18== Grammar == 
     19{{{ 
     20assert <condition> [, info] 
     21}}} 
     22 
     23== Platform == 
     24 
     25== Examples == 
     26{{{ 
     27assert i > 0 
     28 
     29assert obj.foo < bar 
     30 
     31assert not badValue   # test that a boolean value is false 
     32 
     33assert obj   # assert obj not null 
     34assert name.length # assert name is not 0 length   
     35 
     36assert 'result=' in resultString  
     37 
     38# assert with explicit info message 
     39assert _didReset, 'Have not reset. Probably subclass overrides _reset but did not invoke base.' 
     40}}} 
     41 
     42 
     43== Notes ==