This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
op/lex_assign.t: fix intermittent failures
authorDavid Mitchell <davem@iabyn.com>
Tue, 7 Jun 2016 16:41:20 +0000 (17:41 +0100)
committerDavid Mitchell <davem@iabyn.com>
Tue, 7 Jun 2016 16:48:20 +0000 (17:48 +0100)
The bulk of this test script tests whether ops which are capable of
the OA_TARGLEX optimisation return the same results with lexical and
package var assignments, i.e.

    my $a;
    $a = OP;
    $b = OP;
    is($a,$b);

When OP is 'time', the two calls can return different times, resulting in
occasional intermittent failures. So move time into it's custom test which
can cope with a delta of 1.

Similarly if the op is <*>, parallel testing can result in temporary files
appearing in the current directory, resulting in different returns.
However, since glob doesn't actually have the 'T' (OA_TARGLEX) set in
regen/opcodes, this test is moot - so skip it.

If glob ever does ever get OA_TARGLEX, and so need to be tested, it may
require some subtlety, such as globbing for a pattern that won't match any
temporary files.

t/op/lex_assign.t

index c4a5062..3e7a008 100644 (file)
@@ -214,6 +214,18 @@ is($@, '', 'ex-PVBM assert'.$@);
     }
 }
 
+# time() can't be tested using the standard framework since two successive
+# calls may return differing values.
+
+{
+    my $a;
+    $a = time;
+    $b = time;
+    my $diff = $b - $a;
+    cmp_ok($diff, '>=', 0,  "time is monotically increasing");
+    cmp_ok($diff, '<',  2,  "time delta is small");
+}
+
 
 done_testing();
 
@@ -222,7 +234,7 @@ ref $xref                   # ref
 ref $cstr                      # ref nonref
 `$runme -e "print qq[1\\n]"`                           # backtick skip(MSWin32)
 `$undefed`                     # backtick undef skip(MSWin32)
-<*>                            # glob
+'???'                          # glob  (not currently OA_TARGLEX)
 <OP>                           # readline
 'faked'                                # rcatline
 (@z = (1 .. 3))                        # aassign
@@ -355,7 +367,7 @@ getpgrp                             # getpgrp
 setpgrp                                # setpgrp
 getpriority $$, $$             # getpriority
 '???'                          # setpriority
-time                           # time
+'???'                          # time
 localtime $^T                  # localtime
 gmtime $^T                     # gmtime
 '???'                          # sleep: can randomly fail