develooper Front page | perl.perl5.porters | Postings from September 2005

Re: [TODO] rewrite Math::Complex' Complex.t to use Test::More

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
September 25, 2005 15:24
Subject:
Re: [TODO] rewrite Math::Complex' Complex.t to use Test::More
Message ID:
20050925222431.GD19599@windhund.schwern.org
On Sun, Sep 25, 2005 at 11:43:30AM +0300, Jarkko Hietaniemi wrote:
> Someone else than me :-) should rewrite the test to use more
> modern testing frameworks.  Note: large parts of the current
> test are "data-driven", I have no experience on how well e.g.
> Test::More suits that, if it doesn't (I am thinking of useful
> reporting of failures: where to say that the failure happened
> if all you've got is a loop reading the __DATA__?) this might
> open up a place to enhance Test::More, too.

You can use diag() and the test name to give the extra information, or you
can just continue to print it out with a leading #.  In most cases the extra
diagnostics will not be necessary because Test::More's failure diagnostics 
already give you that information.  For example...

    my $z = cplx(  1,  1);
    $z->Re(2);
    $z->Im(3);
    print "# $test Re(z) = ",$z->Re(), " Im(z) = ", $z->Im(), " z = $z\n";
    print 'not ' unless Re($z) == 2 and Im($z) == 3;

becomes

    my $z = cplx(  1,  1);
    is( $z, '1+i' );

    $z->Re(2);
    $z->Im(3);
    
    cmp_ok( Re($z), '==', 2 );
    cmp_ok( Im($z), '==', 3 );

and should it fail you'll see something like:

1..3
not ok 1
#   Failed test in Complex.t at line 5.
#          got: '1+2i'
#     expected: '1+i'
not ok 2
#   Failed test in Complex.t at line 10.
#          got: 3
#     expected: 2
not ok 3
#   Failed test in Complex.t at line 11.
#          got: 4
#     expected: 3
# Looks like you failed 3 tests of 3.


-- 
Michael G Schwern     schwern@pobox.com     http://www.pobox.com/~schwern
Insulting our readers is part of our business model.
        http://somethingpositive.net/sp07122005.shtml

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About