[squeak-dev] Loading mczs into Environments

Frank Shearar frank.shearar at gmail.com
Fri Dec 20 22:44:34 UTC 2013


So I hacked up something that will let me actually properly load MC
definitions into an Environment, letting me inspect this:

| either |
either := Environment named: #EitherEnv.
either import: Smalltalk globals.
[(MCCacheRepository default loadVersionFromFileNamed:
'Either-fbs.9.mcz') load] on: EnvironmentRequest do: [:e | e resume:
either].
either

and then evaluate this in the inspector:

((self classNamed: #Left) value: 2) printString

to yield 'Left 2'.

Other than monkeying a bit with MCClassDefinition >> #createClass, I
had to make MCMethodDefinition >> #actualClass Environmentally aware:

| environment |
    environment := EnvironmentRequest signal ifNil: [Smalltalk].
    ^ environment at: className ifPresent: [ :actualClass |
        classIsMeta
            ifTrue: [actualClass classSide]
            ifFalse: [actualClass]]

(I pretty much stole this from MethodReference >> #actualClass.)

Now I haven't committed the changes because I think that there's a
better way to make Monticello Environment aware, and that's by
restructuring the tests.

At the moment we load MC definitions into Smalltalk, like
MCMethodDefinitionTest:

testLoadAndUnload
    |definition|
    definition := self mockMethod: #one class: 'MCMockClassA' source:
'one ^2' meta: false.
    self assert: self mockInstanceA one = 1.
    definition load.
    self assert: self mockInstanceA one = 2.
    definition unload.
    self deny: (self mockInstanceA respondsTo: #one)

We could (a) make these tests much less
touching-the-global-state-icky, _and_ thoroughly test MC's
Environmental credentials by changing these tests to load into a test
Environment that we throw away.

Thoughts? It's a couple hours work that I might get around to at some
point over the next three weeks (it is Xmas, after all). But if some
keen bean had time just, you know, lying around, waiting to be used on
something productive, this would be an excellent place to apply that
time.

frank


More information about the Squeak-dev mailing list