Example 5-10. examples/intro/t05_calc.t
#!/usr/bin/perl use strict; use warnings; # tell how many tests you are going to write. This is our "plan" use Test::Simple tests => 3; # the ok function of Test::Simple prints "ok" or "not ok" ok `./mycalc 1 + 1` == 2; ok `./mycalc 2 + 2` == 4; ok `./mycalc 2 + 2 + 2` == 6;
Output:
Example 5-11. examples/intro/t05_calc.out
1..3 ok 1 ok 2 not ok 3 # Failed test in t05_calc.t at line 11. # Looks like you failed 1 test of 3.
It is more verbose, it has a couple of additional useful piece of information: 1..3 says how many tests we were planning then we get the tests numbered and we even get a small explanation when the test fails.
| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| Write the ok function | Up | Add names to the tests |