argument of ifNotNil: must be a 0-argument block

David T. Lewis lewis at mail.msen.com
Sat Sep 2 23:55:47 UTC 2006


On Sat, Sep 02, 2006 at 03:00:10PM -0700, Andreas Raab wrote:
> David T. Lewis wrote:
> >>>No, the compiler got it exactly right. It was faithfully optimizing  
> >>>the chosen definition of #ifNotNil: - whoever changed the  
> >>>definition "got it wrong" since the definition should not be  
> >>>changed without also changing the optimization in the compiler.
> >>>
> >>>But what's *really* annoying to me is that this change went unnoticed.
> >>Indeed I think that we should invest in tests and a testserver
> >
> >Tests are good, but they do not detect this kind of problem.
> 
> Why not? If the purpose of a test is to detect a problem then the 
> inability to load a simple test like:
> 
> testIfNotNilArg
>   self assert: (3 ifNotNil:[:val| val = 3])
> 
> is precisely pointing out that there is a problem, e.g., the test 
> detected the problem and served its intended purposes.

Agreed, the test would not load, and that would indicated a problem.
But if I understood right, this test does *not* describe the correct
implementation if #ifNotNil:.

What I meant is that if the intended behavior is something like this
(sorry for the totally bogus example):

  testIfNotNilArg
     self
       should: [3 ifNotNil: [:val | v = 3]]
       raise: SyntaxError
       whoseDescriptionIncludes: 'argument of ifNotNil: must be a 0-argument block'

and if it were possible to have written and compiled such a unit test,
and if the person implementing #infNotNil: had both the foresight and the
motivation to have done so, then the test still would not have detected
the inappropriate change to to the method source of #ifNotNil (at least
not until you tried to recompile the unit test).

I was refering to the hypothetical perfect world in which unit tests
were broadly implemented, and we were relying on them to catch problems
such as this one. It would not have worked in this case. But you are
right that attempting to write a new test (that documented the incorrect
behavior) at the time of making the change would have detected the problem.

Dave




More information about the Squeak-dev mailing list