[Pharo-project] About testing that ensure works

Stéphane Ducasse stephane.ducasse at inria.fr
Sun Apr 24 12:05:41 CEST 2011

> i am puzzled. You wanna to be sure that ensure block are executed?
> It is.

I want to write a test that shows and tests the withOrganizer:do: semantics.
In particular that the ensure is executed and that the context set by the withOrganizer: is only present
in the do: block.

> However if error was triggered during ensure block evaluation, it may
> not complete everything you put there.

Sure this is normal.

> And for test you can use non-local return to trigger ensure block:

>        | current empty |
>        current := RPackageOrganizer default.
>        empty := RPackageOrganizer basicNew initialize.
> [
>        RPackage withOrganizer: empty
>                 do: [ self error ].
> ] on: Error do: [:ex |  ].
>        self assert: (SystemAnnouncer announcer hasSubscriber: current).
>        self deny: (SystemAnnouncer announcer hasSubscriber: empty)

Yes this is what I was thinking to do. because a self error alone was not.


More information about the Pharo-project mailing list