Refactor - Write the ok function


As we are not only testers but also developers we quickly notice the repeating pattern and decide to move it to a function so we will write less code. As we would like to be short, we call the function ok(). As we'll see we are not the only ones who want to type as little as possible.
This ok() function gets a "true" or "false" value (that is the result of a comparison such as == in our examples.)
Reminder: In Perl undef, 0, "" and "0" count as false and all other values as true.

examples/test-simple/tests/t06.pl
use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/../lib";
use MySimpleCalc qw(sum);

ok( sum(1, 1)    == 2 );
ok( sum(2, 2)    == 4 );
ok( sum(2, 2, 2) == 6 );

sub ok {
    my ($true) = @_;

    if ($true) {
        print "ok\n";
    } else {
        print "not ok\n";
    }
}

Output:


ok
ok
not ok

But why reinvent the wheel ?