[squeak-dev] The Inbox: Tests-nice.431.mcz

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Sat Apr 25 16:47:00 UTC 2020


I don't know if we want to introduce such verbose style, but I'm having
great fun with it.
It's a bit like literate programming, except that no text is intermixed
with instructions, it's all instructions...
Also i made an effort to not add too much syntactic sugar (unlike some
tests frameworks with similar goals).
Correctly naming the temporary variables is sufficient for carrying the
meaning.

Declaration of the temporaries constitute a sort of specification alone
(the menu).
It also decompose the task of writing the test in small units (the cook).
Finally, we can orchestrate those units into the annouced sequence and eat
our cake (the dinner).

It's typically in the spirit of what Chrisoph did propose with its dynamic
objects.
Of course, not exactly in the spirit of SUnit/Smalltalk...
The blocks should be methods, either in the TestCase or some other
fixture...
But then, we have all the pieces (and specification) scattered.

We can compare with the unadorned version which is what we usually write:

testFinalizationOfEquals
"self run: #testFinalizationOfEquals"

| o1 o2 |
o1 := 'hello' copy.
o2 := 'hello' copy.
self assert: (o1 = o2 and: [o1 ~~ o2]) description: 'precondition'.
o1 toFinalizeSend: #add: to: log with: 'first object finalized'.
o2 toFinalizeSend: #add: to: log with: 'second object finalized'.
self assert: 0 equals: log size.
o1 := o2 := nil. Smalltalk garbageCollect.
self assert: 2 equals: log asSet size.

Maybe you will prefer the later.
But the story is completely implicit in the later case.
IMO this makes the cognitive effort greater.
We have to somehow reverse engineer the intentions.

Le sam. 25 avr. 2020 à 18:23, <commits at source.squeak.org> a écrit :

> Nicolas Cellier uploaded a new version of Tests to project The Inbox:
> http://source.squeak.org/inbox/Tests-nice.431.mcz
>
> ==================== Summary ====================
>
> Name: Tests-nice.431
> Author: nice
> Time: 25 April 2020, 6:22:55.980578 pm
> UUID: b1757425-0f7a-4912-8f40-561468f42bba
> Ancestors: Tests-mt.430
>
> Restore #testFinalizationOfEquals
>
> The method was failing, a discussion occurred on mantis, and an updated
> test was proposed
> http://bugs.squeak.org/view.php?id=6347
>
> In the interim, the method was removed in System-edc.102 putting it out of
> the radar
> (this was a drastic way of *fixing the failing test*)
>
> This is an attempt to revisit the verbose version of the test.
>
> =============== Diff against Tests-mt.430 ===============
>
> Item was added:
> + ----- Method: ObjectFinalizerTests>>assertThat:after: (in category
> 'running') -----
> + assertThat: conditionBlock after: actionBlock
> +       "syntactic sugar for the scenario"
> +       actionBlock value.
> +       self should: conditionBlock.!
>
> Item was added:
> + ----- Method: ObjectFinalizerTests>>assertThat:and:after: (in category
> 'running') -----
> + assertThat: preconditionBlock and: precondition2 after: actionBlock
> +       "syntactic sugar for the scenario"
> +       actionBlock value.
> +       self should: preconditionBlock.
> +       self should: precondition2!
>
> Item was added:
> + ----- Method: ObjectFinalizerTests>>testFinalizationOfEquals (in
> category 'tests') -----
> + testFinalizationOfEquals
> +       "self run: #testFinalizationOfEquals"
> +
> +       "THE MENU:"
> +       | settingUpAPairOfObjects o1 o2
> +               objectsAreEqual
> +               ofDifferentIdentity
> +       registeringAFinalizationActionForEachObject
> +               noActionIsTriggered
> +       forcingFinalizationOfObjects
> +               bothActionsAreTriggered |
> +
> +       "THE COOK:"
> +       settingUpAPairOfObjects :=
> +               [o1 := 'hello' copy.
> +                o2 := 'hello' copy].
> +       registeringAFinalizationActionForEachObject :=
> +               [o1 toFinalizeSend: #add: to: log with: 'first object
> finalized'.
> +                o2 toFinalizeSend: #add: to: log with: 'second object
> finalized'].
> +       forcingFinalizationOfObjects :=
> +               [o1 := o2 := nil. Smalltalk garbageCollect].
> +
> +       objectsAreEqual := [o1 = o2].
> +       ofDifferentIdentity := [o1 ~~ o2].
> +       noActionIsTriggered := [log size = 0].
> +       bothActionsAreTriggered := [log asSet size = 2].
> +
> +       "THE DINNER:"
> +       self
> +               assertThat: objectsAreEqual
> +               and: ofDifferentIdentity
> +               after: settingUpAPairOfObjects.
> +       self
> +               assertThat: noActionIsTriggered
> +               after: registeringAFinalizationActionForEachObject.
> +       self
> +               assertThat: bothActionsAreTriggered
> +               after: forcingFinalizationOfObjects!
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200425/f41d5848/attachment.html>


More information about the Squeak-dev mailing list