Turn on UTF-8 flag only if the $str is valid utf8
[p5sagit/p5-mst-13.2.git] / lib / Test / Tutorial.pod
index bd5b91d..a57d047 100644 (file)
@@ -137,8 +137,8 @@ So now you'd see...
 =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
 
@@ -298,8 +298,23 @@ C<%ICal_Dates>.  Now that it's less work to test with more dates, you'll
 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
 
@@ -436,6 +451,7 @@ Thumbing through the Date::ICal man page, I came across this:
 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');