[fpc-pascal] Testing if exception raised in fpcUnit
idokan at gmail.com
Mon Nov 5 13:49:11 CET 2012
On Mon, Nov 5, 2012 at 2:45 PM, Michael Van Canneyt
<michael at freepascal.org> wrote:
> On Mon, 5 Nov 2012, ik wrote:
>> I wish to test if a method has raised an exception for a value
>> (something that should make the test pass) or not.
>> For example:
>> function TestNum(ch : Char) : Byte;
>> if UpCase(ch) in ['A'..'F', '0'..'9'] then
>> raise Exception.Create('Invalid char was given.');
>> I want to test the code with Char like 'y' for example, to make sure
>> that it does raises the exception.
>> Does AssertException is the proper method for such test ?
So how do I do it ?
TRunMethod = procedure of object;
If I pass it a function, it don't really like it:
AssertException(ExceptionWasNotRaisd, EMsgPackWrongType, @MsgPackType.AsByte);
convert_testcase.pas(592,60) Error: Incompatible type for arg no. 3:
Got "<procedure variable type of function:Byte of object;Register>",
expected "<procedure variable type of procedure of object;Register>"
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
More information about the fpc-pascal