In ext/POSIX/t/is.t, make better use of Test::More.
authorNicholas Clark <nick@ccl4.org>
Wed, 31 Aug 2011 09:32:17 +0000 (11:32 +0200)
committerNicholas Clark <nick@ccl4.org>
Thu, 1 Sep 2011 19:54:10 +0000 (21:54 +0200)
cmp_ok() will give better diagnostics than ok(). Using skip_all() is terser,
and will give better diagnostics.

ext/POSIX/t/is.t

index a0f5a45..e029004 100644 (file)
@@ -1,15 +1,16 @@
 #!./perl -w
 
+use strict;
+use Test::More;
+use Config;
+
 BEGIN {
-    require Config; import Config;
-    if ($^O ne 'VMS' and $Config{'extensions'} !~ /\bPOSIX\b/) {
-       print "1..0\n";
-       exit 0;
-    }
+    plan(skip_all => "\$^O eq '$^O'") if $^O eq 'VMS';
+    plan(skip_all => "POSIX is unavailable")
+       unless $Config{extensions} =~ /\bPOSIX\b/;
 }
 
 use POSIX;
-use strict ;
 
 # E.g. \t might or might not be isprint() depending on the locale,
 # so let's reset to the default.
@@ -70,11 +71,8 @@ foreach my $s (keys %classes) {
 
 # Expected number of tests is one each for every combination of a
 # known is<xxx> function and string listed above.
-use Test::More;
 plan(tests => keys(%classes) * keys(%functions));
 
-
-#
 # Main test loop: Run all POSIX::is<xxx> tests on each string defined above.
 # Only the character classes listed for that string should return 1.  We
 # always run all functions on every string, and expect to get 0 for the
@@ -85,6 +83,6 @@ foreach my $s (sort keys %classes) {
        my $expected = exists $classes{$s}->{$f};
        my $actual   = eval "POSIX::$f( \$s )";
 
-       ok( $actual == $expected, "$f('$s') == $actual");
+       cmp_ok($actual, '==', $expected, "$f('$s')");
     }
 }