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.10. Enlarge our test suit

Example 5-14. examples/intro/t10_calc.t

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

my %tests = (
    '1 + 1'     => 2,
    '2 + 2'     => 4,
    '2 + 2 + 2' => 6,
    '1+1'       => 2,
    '0+ -1'     => -1,
    '0-1'       => -1,
    '-1+1'      => 0,
);

use Test::Simple tests => 7;

foreach my $t ( keys %tests ) {
    ok( `./mycalc $t` == $tests{$t}, $t );
}

Example 5-15. examples/intro/t10_calc.out

1..7
ok 1 - 0-1
ok 2 - 1 + 1
ok 3 - -1+1
ok 4 - 0+ -1
ok 5 - 1+1
not ok 6 - 2 + 2 + 2
#   Failed test '2 + 2 + 2'
#   in t10_calc.t at line 18.
ok 7 - 2 + 2
# Looks like you failed 1 test of 7.

There is a small problem though. When you add a new test to the hash, you also have to remember to update the tests => 7 line.

There are a number of solution to this problem


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