=head2 Test the manual
Simplest way to build up a decent testing suite is to just test what
-the manual says it does. [3] Let's pull something out of the
-L<Date::ICal/SYNOPSIS> and test that all it's bits work.
+the manual says it does. [3] Let's pull something out of the
+L<Date::ICal/SYNOPSIS> and test that all its bits work.
#!/usr/bin/perl -w
# Looks like you failed 1 tests of 8.
Whoops, a failure! [4] Test::Simple helpfully lets us know on what line
-the failure occured, but not much else. We were supposed to get 17,
+the failure occurred, but not much else. We were supposed to get 17,
but we didn't. What did we get?? Dunno. We'll have to re-run the
test in the debugger or throw in some print statements to find out.
be inclined to just throw more in as you think of them.
Only problem is, every time we add to that we have to keep adjusting
the C<use Test::More tests =E<gt> ##> line. That can rapidly get
-annoying. Instead we use C<no_plan>. This means we're just running
-some tests, don't know how many. [6]
+annoying. There's two ways to make this work better.
+
+First, we can calculate the plan dynamically using the C<plan()>
+function.
+
+ use Test::More;
+ use Date::ICal;
+
+ my %ICal_Dates = (
+ ...same as before...
+ );
+
+ # For each key in the hash we're running 8 tests.
+ plan tests => keys %ICal_Dates * 8;
+
+Or to be even more flexible, we use C<no_plan>. This means we're just
+running some tests, don't know how many. [6]
use Test::More 'no_plan'; # instead of tests => 32
the date in the Date::ICal test suite. So I'll write one.
use Test::More tests => 1;
+ use Date::ICal;
my $ical = Date::ICal->new;
$ical->ical('20201231Z');
=head2 Testing with taint mode.
Taint mode is a funny thing. It's the globalest of all global
-features. Once you turn it on it effects I<all> code in your program
+features. Once you turn it on, it affects I<all> code in your program
and I<all> modules used (and all the modules they use). If a single
piece of code isn't taint clean, the whole thing explodes. With that
in mind, it's very important to ensure your module works under taint
#!/usr/bin/perl -Tw
- use Test::More 'no_plan';
-
...test normally here...
So when you say C<make test> it will be run with taint mode and