On Tue, 9 Apr 2002, Michael G Schwern wrote:

> > I'm not sure exactly what the purpose of this is; your test will
> > still fail if it dies even when not in a lives_ok block, right?
>
> It'll fail and take the whole rest of the test program with it.  Some
> testing systems like to abort the test script on failure.  Perl's
> doesn't.

I'm not entirely sure I buy this, since the framework seems perfectly
happy to tell me that something is wrong whether I complete all
the tests in a script or not. But it's hardly a point worth arguing.

> Aegis, in particular, pretty much requires tests to always
> exit gracefully, passing or not.

As perl does: when it dies, it exits "gracefully" with error code
255 indicating that the test failed? Or am I misunderstanding how
Aegis works?

But this discussion has been good, actually, because it's made me
start to think about alternatives to the Test::More way of doing
things. I always find myself enclosing tests in blocks so I can
have local variables, anyway:

    {
        my foo = new Foo();
        # etc. etc.
    }

    {
        my foo = new Foo();
        # different tests here
    }

Well, one might as well work it this way:

    sub test (&) {
        my $rsCode = shift;
        my $result = eval { &$rsCode };
        if ($result) {
            # Test worked.
        } else {
            # Test failed.
        }
    }

    test {
        # ....
        assertEquals($expected, $actual, $message);
    }

And then assertEquals can die if it fails, letting you know that
that test failed. This lets you go on to the next test even if you
get an exception, and it also removes the need to give a count of
the number of tests you're running.

(And yes, it's not a co-incidence that this looks a lot like Beck
and Gamma's unit test frameworks for Java and Smalltalk.)

Thoughts?

cjs
-- 
Curt Sampson  <[EMAIL PROTECTED]>   +81 90 7737 2974   http://www.netbsd.org
    Don't you know, in this new Dark Age, we're all light.  --XTC

Reply via email to