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.

use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/../lib";
use MyTools;

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";


not ok

But why reinvent the wheel ?