test for exception

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

test for exception

John Almberg
I have a setter method that tests input for validity using 'assert'.  
It looks like this:

aVariableName: aNumber
        self assert: [(aNumber >= self minValue) & (aNumber <= self maxValue)]
                description: 'invalid value'.
        aVariableName := aNumber.

The program needs to blow up if an invalid number is assigned. I  
don't want to just quietly ignore the invalid assignment. That's why  
I have this assertion.

Anyway, the assertion blows up just fine, but now I'd like to write a  
test that checks to see what happens if I try to assign an invalid  
number.

I *think* I should use something like:

        self should: [anObject aVariableName = anInvalidNumber] raise: ???

raise: is supposed to get the ExceptionEvent, but I'm not sure how to  
find out which event this would be. The debugger doesn't seem to show  
this when the assertion fails.

How do I know which exception event is raised? Or am I on the wrong  
track completely?

Thanks: John

       

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: test for exception

John Almberg
Lots of digging later...

Okay! I think I found the ExceptionEvent I need. It's the  
appropriately named 'AssertionFailure'.

For anyone who might be interested at some future date, the following  
test works:

        self should: [ anObject aSetter: anInvalidNumber] raise:  
AssertionFailure.
       
Cool!

-- John


On Aug 14, 2007, at 4:02 PM, John Almberg wrote:

> I have a setter method that tests input for validity using  
> 'assert'. It looks like this:
>
> aVariableName: aNumber
> self assert: [(aNumber >= self minValue) & (aNumber <= self  
> maxValue)]
> description: 'invalid value'.
> aVariableName := aNumber.
>
> The program needs to blow up if an invalid number is assigned. I  
> don't want to just quietly ignore the invalid assignment. That's  
> why I have this assertion.
>
> Anyway, the assertion blows up just fine, but now I'd like to write  
> a test that checks to see what happens if I try to assign an  
> invalid number.
>
> I *think* I should use something like:
>
> self should: [anObject aVariableName = anInvalidNumber] raise: ???
>
> raise: is supposed to get the ExceptionEvent, but I'm not sure how  
> to find out which event this would be. The debugger doesn't seem to  
> show this when the assertion fails.
>
> How do I know which exception event is raised? Or am I on the wrong  
> track completely?
>
> Thanks: John
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Websites for On-line Collectible Dealers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Identry, LLC
John Almberg
(631) 546-5079
[hidden email]
www.identry.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners