Failling Tests are green if BlockCannotReturn exception
Hi, I observed this unexpected behavior in test classes.In a test class define a method : testBlock    |aBlock|    aBlock := [ ^1 ].    aBlock value.    self assert: false. Althought the assertion is false at the end of the test, the test is green.Actually, It does not matter what you put after aBlock value, the test always succedes (I tried to put a self halt, it does not execute) I tried this both in Pharo 4 and 5 under Windows and MacOS. Any ideas? Cheers Abdelghani
Hi Abdelghani, this is actually correct behavior: by putting [ ^1 ] , you are specifying that the method should return 1 when the block is executed. So the result of aBlock value is that the method returns 1. If you want that the result of evaluating the block is 1, you should just put [ 1 ] Hope this helps,
On Jan 11, 2016, at 20:26, abdelghani ALIDRA <alidrandco@yahoo.fr> wrote:
Hi,
I observed this unexpected behavior in test classes. In a test class define a method :
testBlock |aBlock| aBlock := [ ^1 ]. aBlock value. self assert: false.
Althought the assertion is false at the end of the test, the test is green. Actually, It does not matter what you put after aBlock value, the test always succedes (I tried to put a self halt, it does not execute) I tried this both in Pharo 4 and 5 under Windows and MacOS.
Any ideas?
Cheers Abdelghani
---> Save our in-boxes! http://emailcharter.org <--- Johan Fabry - http://pleiad.cl/~jfabry PLEIAD and RyCh labs - Computer Science Department (DCC) - University of Chile
Hi, It is expected. When you evaluate a block with a return, the method containing the block definition (here testBlock) will return. So the test will pass. BTW, you donât need to put a return in a block. By default, the last instruction will be returned. Cheers, Vincent From: Pharo-users [mailto:pharo-users-bounces@lists.pharo.org] On Behalf Of abdelghani ALIDRA Sent: mardi 12 janvier 2016 00:26 To: Any Question About Pharo Is Welcome Subject: [Pharo-users] Failling Tests are green if BlockCannotReturn exception Hi, I observed this unexpected behavior in test classes. In a test class define a method : testBlock |aBlock| aBlock := [ ^1 ]. aBlock value. self assert: false. Althought the assertion is false at the end of the test, the test is green. Actually, It does not matter what you put after aBlock value, the test always succedes (I tried to put a self halt, it does not execute) I tried this both in Pharo 4 and 5 under Windows and MacOS. Any ideas? Cheers Abdelghani
2016-01-12 0:40 GMT+01:00 Vincent BLONDEAU < vincent.blondeau@polytech-lille.net>:
Hi,
It is expected.
When you evaluate a block with a return, the method containing the block definition (here testBlock) will return.
So the test will pass.
BTW, you donât need to put a return in a block. By default, the last instruction will be returned.
[ ^ 1 ] => non local return [ 1 ] => local return The 2 blocks are very different from each other. One returns to the closure activation sender, while the other returns to the closure creating context sender. See the chapter 14.4 Returning from inside a Block from the free book Deep Into Pharo <http://deepintopharo.com/> So I would not say you don't need to put a return in a block. You want to put a return or not depending on the behavior you want.
Cheers,
Vincent
*From:* Pharo-users [mailto:pharo-users-bounces@lists.pharo.org] *On Behalf Of *abdelghani ALIDRA *Sent:* mardi 12 janvier 2016 00:26 *To:* Any Question About Pharo Is Welcome *Subject:* [Pharo-users] Failling Tests are green if BlockCannotReturn exception
Hi,
I observed this unexpected behavior in test classes.
In a test class define a method :
*testBlock |aBlock| aBlock := [ ^1 ]. aBlock value. self assert: false.*
Althought the assertion is false at the end of the test, the test is green.
Actually, It does not matter what you put after *aBlock value*, the test always succedes (I tried to put a self halt, it does not execute)
I tried this both in Pharo 4 and 5 under Windows and MacOS.
Any ideas?
Cheers
Abdelghani
On 12 Jan 2016, at 00:26, abdelghani ALIDRA <alidrandco@yahoo.fr> wrote:
Hi,
I observed this unexpected behavior in test classes. In a test class define a method :
testBlock |aBlock| aBlock := [ ^1 ]. aBlock value. self assert: false.
Althought the assertion is false at the end of the test, the test is green. Actually, It does not matter what you put after aBlock value, the test always succedes (I tried to put a self halt, it does not execute)
The test is 'does an explicit return from a block return from the whole method'. Of course it does. But if it would not, you would arrive at the self assert: false and the test would fail. You see ? BTW, this can also be written as self fail - search for the senders of that message for more examples.
I tried this both in Pharo 4 and 5 under Windows and MacOS.
Any ideas?
Cheers Abdelghani
Thank you all for your responses. I see your point about returning from a block. Because the return in this example is very explicit. But what if I put (by mistake) a return in a block in a method that is called by the test method (or even in a method that is called by another method that is called by the test method) then I would have no reason to doubt my test was successful whereas it would have failed if it was run till the last assertion. My point is, would it not be interesting to report tests that were not run successfully till the end? Abdelghani De : Sven Van Caekenberghe <sven@stfx.eu> à: abdelghani ALIDRA <alidrandco@yahoo.fr>; Any question about pharo is welcome <pharo-users@lists.pharo.org> Envoyé le : Mardi 12 janvier 2016 7h35 Objet : Re: [Pharo-users] Failling Tests are green if BlockCannotReturn exception
On 12 Jan 2016, at 00:26, abdelghani ALIDRA <alidrandco@yahoo.fr> wrote:
Hi,
I observed this unexpected behavior in test classes. In a test class define a method :
testBlock   |aBlock|   aBlock := [ ^1 ].   aBlock value.   self assert: false.
Althought the assertion is false at the end of the test, the test is green. Actually, It does not matter what you put after aBlock value, the test always succedes (I tried to put a self halt, it does not execute)
The test is 'does an explicit return from a block return from the whole method'. Of course it does. But if it would not, you would arrive at the self assert: false and the test would fail. You see ? BTW, this can also be written as self fail - search for the senders of that message for more examples.
I tried this both in Pharo 4 and 5 under Windows and MacOS.
Any ideas?
Cheers Abdelghani
On 13 Jan 2016, at 18:42, abdelghani ALIDRA <alidrandco@yahoo.fr> wrote:
Thank you all for your responses.
I see your point about returning from a block. Because the return in this example is very explicit. But what if I put (by mistake) a return in a block in a method that is called by the test method (or even in a method that is called by another method that is called by the test method) then I would have no reason to doubt my test was successful whereas it would have failed if it was run till the last assertion.
My point is, would it not be interesting to report tests that were not run successfully till the end?
An empty test is successful. A test only fails when an assertion fails. Assertions must be written explicitly. Your suggestion is not per se a bad idea, it is just not within the contract of SUnit, I think.
Abdelghani
De : Sven Van Caekenberghe <sven@stfx.eu> à : abdelghani ALIDRA <alidrandco@yahoo.fr>; Any question about pharo is welcome <pharo-users@lists.pharo.org> Envoyé le : Mardi 12 janvier 2016 7h35 Objet : Re: [Pharo-users] Failling Tests are green if BlockCannotReturn exception
On 12 Jan 2016, at 00:26, abdelghani ALIDRA <alidrandco@yahoo.fr> wrote:
Hi,
I observed this unexpected behavior in test classes. In a test class define a method :
testBlock |aBlock| aBlock := [ ^1 ]. aBlock value. self assert: false.
Althought the assertion is false at the end of the test, the test is green. Actually, It does not matter what you put after aBlock value, the test always succedes (I tried to put a self halt, it does not execute)
The test is 'does an explicit return from a block return from the whole method'. Of course it does. But if it would not, you would arrive at the self assert: false and the test would fail. You see ?
BTW, this can also be written as self fail - search for the senders of that message for more examples.
I tried this both in Pharo 4 and 5 under Windows and MacOS.
Any ideas?
Cheers Abdelghani
participants (5)
-
abdelghani ALIDRA -
Clément Bera -
Johan Fabry -
Sven Van Caekenberghe -
Vincent BLONDEAU