You are looking at a very old, but free version of the course. If you are interesed the most recent version, check it out on the Perl Maven site.

5.7. Write the ok function

Example 5-8. examples/intro/t04_calc.t

#!/usr/bin/perl
use strict;
use warnings;

ok(`./mycalc 1  + 1` == 2);
ok(`./mycalc 2 + 2` == 4);
ok(`./mycalc 2 + 2 + 2` == 6);

sub ok {
    my ($ok) = @_;
    print $ok ? "ok\n" : "not ok\n";
}

Output:

Example 5-9. examples/intro/t04_calc.out

ok
ok
not ok

But why reinvent the wheel ?

Besides, if there are lots of tests, we would need some way to easily recognise which test(s) fail. So we should put a counter on our tests.


If you are interested in on-site trainings by the author, please contact me directly.