[Pharo-project] About testing that ensure works

Igor Stasenko siguctua at gmail.com
Sun Apr 24 00:45:38 CEST 2011


First question what i wanna ask is:
- why do you need to play with two different instances of organizer,
and especially in such manner (temporary swapping forth and back)?

This code doesn't looks to be good.


On 24 April 2011 00:44, Stéphane Ducasse <stephane.ducasse at inria.fr> wrote:
> Hi guys
>
> in RPackage there is a method named withOrganizer:do:  defined as follows and I would like to test it to understand really if it does
> what it says.
>
> withOrganizer: aNewOrganizer do: aBlock
>        "Perform an action locally to aNewOrganizer. Does not impact any other organizers."
>
>        | old shouldRegisterAtTheEnd|
>        [
>        old := self organizer.
>        shouldRegisterAtTheEnd := false.
>        old hasRegistered ifTrue: [
>                old unregister.
>                shouldRegisterAtTheEnd := true.
>                ].
>        self organizer: aNewOrganizer.
>        aBlock cull: aNewOrganizer.] ensure: [
>                self organizer: old.
>                shouldRegisterAtTheEnd ifTrue: [
>                        self organizer register.
>                        ].
>                aNewOrganizer unregister.
>                ]
>
>
> So I wrote two tests
>
> testWithDoIsCorrectlyReinstallingDefault
>        "self debug: #testWithDoIsCorrectlyReinstallingDefault"
>
>        | current empty |
>        current := RPackageOrganizer default.
>        empty := RPackageOrganizer basicNew initialize.
>        RPackage withOrganizer: empty
>                 do: [ self assert: (SystemAnnouncer announcer hasSubscriber: empty).
>                        self deny: (SystemAnnouncer announcer hasSubscriber: current)].
>        self assert: (SystemAnnouncer announcer hasSubscriber: current).
>        self deny: (SystemAnnouncer announcer hasSubscriber: empty)
>
>
> and
>
>
> testWithDoIsCorrectlyReinstallingDefaultEvenIfHalt
>        "self debug: #testWithDoIsCorrectlyReinstallingDefaultEvenIfHalt"
>
>        | current empty |
>        current := RPackageOrganizer default.
>        empty := RPackageOrganizer basicNew initialize.
>        RPackage withOrganizer: empty
>                 do: [ self error.
>                        self assert: (SystemAnnouncer announcer hasSubscriber: empty).
>                        self deny: (SystemAnnouncer announcer hasSubscriber: current)].
>        self assert: (SystemAnnouncer announcer hasSubscriber: current).
>        self deny: (SystemAnnouncer announcer hasSubscriber: empty)
>
> Now I would like to make sure that I raise an error or whaever to make sure that the ensure: block argument
> is executed. Does anybody have an idea how I can do that. because self error does not work.
>
> Stef
>
>
>
>
>



-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Pharo-project mailing list