On Tue, Feb 03, 2004 at 08:41:13PM +0000, Fergal Daly wrote:
> package MyModule::OKSwapper;
> 
> require Test::More;
> require Exporter;
> @ISA = qw( Exporter);
> @EXPORT= qw( ok );
> 
> sub ok
> {
>       @_ = 1;
>       goto &Test::More::ok;
> }
> 
> Then, when you fix all the ok()s in a file, just delete the

Test's ok() compares its two arguments (umm, usually).  Test::More's ok() 
simply checks if the first argument is true.  Your code above will cause all 
the ok()s to simply pass without any actual testing done.  Bad.  The test 
will run and pass but won't be testing anything.  You might as well just 
comment out all the ok() calls.

I think what you want is this:

        sub ok {
                goto &Test::More::is;
        }

Then the original intent of the tests will be performed.

However, this only emulates part of Test::ok's functionality.  It performs
a different test based on what the second argument looks like, part of the
reason I changed its behavior in Test::More--ambiguity.  So to
do it for real, you'd have to take all of these different modes of
operation into account and call ok, is, like... as appropriate.

Something like this should give a good first order approximation:

package Test::ok;

require Exporter;
@EXPORT = qw(ok);

use Test::Builder;
my $TB = Test::Builder->new;

sub ok {
    my @args = @_;

    # Run all sub references.
    for (0..1) {
        $args[$_] = $args[$_]->() if ref $args[$_] eq 'CODE';
    }

    my $result;
    if( @args == 1 ) {
        $result = $TB->ok(@args);       # single argument == ok
    }
    elsif( $TB->maybe_regex($args[1]) ) {
        $result = $TB->like(@args);     # 2nd arg a regex == like
    }
    else {
        $result = $TB->is_eq(@args);    # everything else == is
    }

    $TB->diag($args[2]) if $args[2] and !$result;

    return $result;
}

1;


-- 
Michael G Schwern        [EMAIL PROTECTED]  http://www.pobox.com/~schwern/
Please Captain, not in front of the Klingons.

Reply via email to