<div dir="ltr"><div dir="ltr"><div>I don't know if we want to introduce such verbose style, but I'm having great fun with it.<br></div><div>It's a bit like literate programming, except that no text is intermixed with instructions, it's all instructions...</div><div>Also i made an effort to not add too much syntactic sugar (unlike some tests frameworks with similar goals).</div><div>Correctly naming the temporary variables is sufficient for carrying the meaning.</div><div><br></div><div>Declaration of the temporaries constitute a sort of specification alone (the menu).</div><div>It also decompose the task of writing the test in small units (the cook).</div><div>Finally, we can orchestrate those units into the annouced sequence and eat our cake (the dinner).</div><div><div><br></div><div>It's typically in the spirit of what Chrisoph did propose with its dynamic objects.<br></div></div><div>Of course, not exactly in the spirit of SUnit/Smalltalk...</div><div>The blocks should be methods, either in the TestCase or some other fixture...</div><div>But then, we have all the pieces (and specification) scattered.</div><div><br></div><div>We can compare with the unadorned version which is what we usually write:</div><div><br></div><div>testFinalizationOfEquals<br>      "self run: #testFinalizationOfEquals"<br>       <br>      | o1 o2 |<br>     o1 := 'hello' copy.<br>   o2 := 'hello' copy.<br>   self assert: (o1 = o2 and: [o1 ~~ o2]) description: 'precondition'.<br>   o1 toFinalizeSend: #add: to: log with: 'first object finalized'.<br>      o2 toFinalizeSend: #add: to: log with: 'second object finalized'.<br>     self assert: 0 equals: log size.<br>      o1 := o2 := nil. Smalltalk garbageCollect.<br>    self assert: 2 equals: log asSet size.</div></div><div><br></div><div>Maybe you will prefer the later. </div><div>But the story is completely implicit in the later case.<br></div><div>IMO this makes the cognitive effort greater.</div><div>We have to somehow reverse engineer the intentions.<br></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le sam. 25 avr. 2020 à 18:23, <<a href="mailto:commits@source.squeak.org">commits@source.squeak.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Nicolas Cellier uploaded a new version of Tests to project The Inbox:<br>
<a href="http://source.squeak.org/inbox/Tests-nice.431.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/inbox/Tests-nice.431.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: Tests-nice.431<br>
Author: nice<br>
Time: 25 April 2020, 6:22:55.980578 pm<br>
UUID: b1757425-0f7a-4912-8f40-561468f42bba<br>
Ancestors: Tests-mt.430<br>
<br>
Restore #testFinalizationOfEquals<br>
<br>
The method was failing, a discussion occurred on mantis, and an updated test was proposed<br>
<a href="http://bugs.squeak.org/view.php?id=6347" rel="noreferrer" target="_blank">http://bugs.squeak.org/view.php?id=6347</a><br>
<br>
In the interim, the method was removed in System-edc.102 putting it out of the radar<br>
(this was a drastic way of *fixing the failing test*)<br>
<br>
This is an attempt to revisit the verbose version of the test.<br>
<br>
=============== Diff against Tests-mt.430 ===============<br>
<br>
Item was added:<br>
+ ----- Method: ObjectFinalizerTests>>assertThat:after: (in category 'running') -----<br>
+ assertThat: conditionBlock after: actionBlock<br>
+       "syntactic sugar for the scenario"<br>
+       actionBlock value.<br>
+       self should: conditionBlock.!<br>
<br>
Item was added:<br>
+ ----- Method: ObjectFinalizerTests>>assertThat:and:after: (in category 'running') -----<br>
+ assertThat: preconditionBlock and: precondition2 after: actionBlock<br>
+       "syntactic sugar for the scenario"<br>
+       actionBlock value.<br>
+       self should: preconditionBlock.<br>
+       self should: precondition2!<br>
<br>
Item was added:<br>
+ ----- Method: ObjectFinalizerTests>>testFinalizationOfEquals (in category 'tests') -----<br>
+ testFinalizationOfEquals<br>
+       "self run: #testFinalizationOfEquals"<br>
+       <br>
+       "THE MENU:"<br>
+       | settingUpAPairOfObjects o1 o2<br>
+               objectsAreEqual<br>
+               ofDifferentIdentity<br>
+       registeringAFinalizationActionForEachObject<br>
+               noActionIsTriggered<br>
+       forcingFinalizationOfObjects<br>
+               bothActionsAreTriggered |<br>
+ <br>
+       "THE COOK:"<br>
+       settingUpAPairOfObjects :=<br>
+               [o1 := 'hello' copy.<br>
+                o2 := 'hello' copy].<br>
+       registeringAFinalizationActionForEachObject :=<br>
+               [o1 toFinalizeSend: #add: to: log with: 'first object finalized'.<br>
+                o2 toFinalizeSend: #add: to: log with: 'second object finalized'].<br>
+       forcingFinalizationOfObjects :=<br>
+               [o1 := o2 := nil. Smalltalk garbageCollect].<br>
+       <br>
+       objectsAreEqual := [o1 = o2].<br>
+       ofDifferentIdentity := [o1 ~~ o2].<br>
+       noActionIsTriggered := [log size = 0].<br>
+       bothActionsAreTriggered := [log asSet size = 2].<br>
+ <br>
+       "THE DINNER:"<br>
+       self<br>
+               assertThat: objectsAreEqual<br>
+               and: ofDifferentIdentity<br>
+               after: settingUpAPairOfObjects.<br>
+       self<br>
+               assertThat: noActionIsTriggered<br>
+               after: registeringAFinalizationActionForEachObject.<br>
+       self<br>
+               assertThat: bothActionsAreTriggered<br>
+               after: forcingFinalizationOfObjects!<br>
<br>
<br>
</blockquote></div></div>