[squeak-dev] The Inbox: SUnit-ct.124.mcz
christoph.thiede at student.hpi.uni-potsdam.de
christoph.thiede at student.hpi.uni-potsdam.de
Sun Jan 16 19:31:10 UTC 2022
There is already #should:raise:withExceptionDo: which purposes exactly this purpose.
Can I change the behavior of the #should:raise: selectors so that they answer the result of aBlock if there was no error? For instance, this should just work:
result := TestCase new should: [2/0] raise: ZeroDivide withExceptionDo: [:ex | ex resume: 42]
(Fun fact: Today, you can even find that existing selector with my refurbished method finder from SimulationStudio:
| case |
case := TestCase new.
Sandbox
findSelectorsFor: case
arguments: {[Dictionary new at: 0]. KeyNotFound. [:ex | self assert: ex key = 0]}
thatAnswer: case "a Set(#should:raise:withExceptionDo: #addModelMenuItemsTo:forMorph:hand: #toFinalizeSend:to:with: #should:raise:description:)"
:-) )
---
Sent from Squeak Inbox Talk
On 2020-03-20T19:01:48+00:00, commits at source.squeak.org wrote:
> Christoph Thiede uploaded a new version of SUnit to project The Inbox:
> http://source.squeak.org/inbox/SUnit-ct.124.mcz
>
> ==================== Summary ====================
>
> Name: SUnit-ct.124
> Author: ct
> Time: 20 March 2020, 8:01:47.398237 pm
> UUID: d936b6a0-e7c7-2742-a817-35fa6511a15a
> Ancestors: SUnit-mt.121
>
> Proposal for discussion: Adds assertion message #should:raise:then: to allow for interactively working with expected exceptions. If you like, we could also talk about #should:raise:that: (however, I still like BlockClosure >> #handles:*).
>
> Examples:
>
> TestCase new in: [:test |
>
> test
> should: [
> test
> should: [self error: #foo]
> raise: Error
> then: #pass]
> raise: UnhandledError.
>
> test
> should: [self error: #foo]
> raise: Error
> then: [:ex |
> test assert: #foo equals: ex messageText].
>
> ]
>
> * See exception patterns: http://forum.world.st/The-Inbox-Kernel-ct-1292-mcz-tp5109282p5109284.html
>
> =============== Diff against SUnit-mt.121 ===============
>
> Item was added:
> + ----- Method: TestCase>>should:raise:then: (in category 'accessing') -----
> + should: aBlock raise: anExceptionalEvent then: aHandlerBlock
> +
> + | raised result |
> + raised := false.
> + result := aBlock
> + on: anExceptionalEvent
> + do: [:ex |
> + raised := true.
> + aHandlerBlock cull: ex].
> + self assert: raised.
> + ^ result!
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220116/dfbe7052/attachment.html>
More information about the Squeak-dev
mailing list
|