Fix long-standing bug in t/op/inc.t, whereby ok() ignored a failed match.
authorNicholas Clark <nick@ccl4.org>
Sat, 12 Mar 2011 22:16:46 +0000 (22:16 +0000)
committerNicholas Clark <nick@ccl4.org>
Sat, 12 Mar 2011 22:20:25 +0000 (22:20 +0000)
Unlike test.pl and Test::More, the home-rolled ok() in t/op/inc.t didn't have
a prototype. Hence its arguments are in *list* context, meaning that any match
will return an *empty list* if it fails. Provided ok() was called with a
second, true, parameter, the failed match would not be noticed, because ok()
would register a test pass, because it would now be testing the (intended)
second parameter.

Add a prototype, and fix the logic for the tests affected.
Fortunately this wasn't concealing any bugs.

t/op/inc.t

index 88a34b2..5b6ede2 100644 (file)
@@ -6,7 +6,7 @@ print "1..56\n";
 
 my $test = 1;
 
-sub ok {
+sub ok ($;$$) {
   my ($pass, $wrong, $err) = @_;
   if ($pass) {
     print "ok $test\n";
@@ -224,9 +224,11 @@ for my $n (47..113) {
            unless $start_p == $check;
     }
 
-    foreach ([$start_p, '++$i', 'pre-inc'], [$start_p, '$i++', 'post-inc'],
-            [$start_n, '--$i', 'pre-dec'], [$start_n, '$i--', 'post-dec']) {
-       my ($start, $action, $description) = @$_;
+    foreach ([$start_p, '++$i', 'pre-inc', 'inc'],
+            [$start_p, '$i++', 'post-inc', 'inc'],
+            [$start_n, '--$i', 'pre-dec', 'dec'],
+            [$start_n, '$i--', 'post-dec', 'dec']) {
+       my ($start, $action, $description, $act) = @$_;
        foreach my $warn (0, 1) {
            my $warn_line = ($warn ? 'use' : 'no') . " warnings 'imprecision';";
 
@@ -250,7 +252,7 @@ EOC
                    print STDERR "# $_" foreach @warnings;
                }
                foreach (@warnings) {
-                   unless (ok (/Lost precision when incrementing \d+/, $_)) {
+                   unless (ok (/Lost precision when ${act}rementing -?\d+/, $_)) {
                        print STDERR "# $_"
                    }
                }