X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F85-stress-unwind.t;h=5242747a024f7d96a5cf60a4d1dcfd3ae56eafe7;hb=3d4ca2c41333ec02ffd7c0247dc6f15820c99b7d;hp=acd44521984471b05fbd0712838da7d3d0f3e0cc;hpb=d3fe85111edf0d4cbd702f67eea3bf359bd8b485;p=perl%2Fmodules%2FScope-Upper.git diff --git a/t/85-stress-unwind.t b/t/85-stress-unwind.t index acd4452..5242747 100644 --- a/t/85-stress-unwind.t +++ b/t/85-stress-unwind.t @@ -8,12 +8,25 @@ use Test::Leaner 'no_plan'; use Scope::Upper qw; -our ($call, @args); +# perl 5.8.0 is not happy when @args is a lexical, so we have to use a global. +# It's slightly faster too. + +our @args; + +my $args_code; +if ("$]" < 5.008) { + # perl 5.6.x is really bad at closures, hence make it compile a function call + # instead. + *_get_args = sub { @args }; + $args_code = '_get_args()'; +} else { + $args_code = '@args'; +} -$call = sub { +my $call = sub { my ($height, $level, $i) = @_; $level = $level ? 'UP ' x $level : 'HERE'; - return [ [ "unwind(\@args => $level)\n", [ \@args ] ] ]; + return [ [ "unwind($args_code => $level)\n", [ \@args ] ] ]; }; # @_[0 .. $#_] also ought to work, but it sometimes evaluates to nonsense in @@ -99,35 +112,37 @@ sub expect { return linearize @acc; } -sub runtests { - my ($height, $level) = @_; - my $i; - my $tests = gen @_; - for (@$tests) { - ++$i; - no warnings 'void'; - my $res = linearize eval $_->[0]; - my $exp; - if ($@) { - $res = '*TEST DID NOT COMPILE*'; - } else { - $exp = expect $_->[1]; - } - if ($res ne $exp) { - diag < ]); + +for my $height (0 .. 1) { + for my $level (0 .. 1) { + my $i; + my $tests = gen $height, $level; + for (@$tests) { + my ($code, $exp_spec) = @$_; + ++$i; + my $desc = "stress unwind $height $level $i"; + my $cb = do { + no warnings 'void'; + eval "sub { $code }"; + }; + if ($@) { + fail "$desc : test did not compile" for 1 .. @arg_lists; + } else { + for (@arg_lists) { + @args = @$_; + my $res = linearize $cb->(); + my $exp = expect $exp_spec; + if ($res ne $exp) { + diag <[0]; +$code; ==== vvvvv Errors vvvvvv === DIAG + } + is $res, $exp, "$desc [@args]"; + } + } } - is $res, $exp, "stress unwind $height $level $i"; } } - -for ([ ], [ 'A' ], [ qw ]) { - @args = @$_; - runtests 0, 0; - runtests 0, 1; - runtests 1, 0; - runtests 1, 1; -}