I've implemented a few ExternalStrctures (as part of an "FFI effort"), and for some of them I want to implement finalization for reclaiming the external memory.
I'm trying to write some tests for that, and thought a good way to know if #finalize
is called is to change the behaviour for the particular instance I'm using for testing. I'd rather not pollute the implementation with code for supporting tests if possible.
I believe mocking specific methods and changing specific instance behavior is in general a good tool for testing.
I know it's possible in other dialects, and I've implemented it myself in the past in Squeak using #doesNotUnderstand
, but I'd like to know if there's a cleaner way, possibly supported by the VM.
Is there a way to change how a particular instance answers a particular message in Cuis/Squeak/Pharo?
Luciano gave this wonderful example:
EllipseMorph copy compile: 'defaultColor ^Color red'; new :: openInWorld
The mail thread is here: http://cuis-smalltalk.org/pipermail/cuis-dev_cuis-smalltalk.org/2016-March/000458.html