Search code examples
smalltalkassertionsgnu-smalltalk

Smalltalk and Assertions


Tryng out some smalltalk + TDD + "good practices" I've run into a kinda ugly block:

How do I do an assertion in GNU Smalltalk?

I'm just looking for a simple ifFalse: [Die] kind of thing


Solution

  • This is the code for assert: from Squeak (which I recommend you use rather than GNU):

    assert: aBlock 
        "Throw an assertion error if aBlock does not evaluates to true."
        aBlock value
            ifFalse: [AssertionFailure signal: 'Assertion failed']