]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/22-localize-block.t
Importing Scope-Upper-0.01
[perl/modules/Scope-Upper.git] / t / 22-localize-block.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More 'no_plan'; 
7
8 use Scope::Upper qw/localize/;
9
10 use lib 't/lib';
11 use Scope::Upper::TestGenerator;
12
13 local $Scope::Upper::TestGenerator::call = sub {
14  my ($height, $level, $i) = @_;
15  return [ "localize '\$x' => 0 => $level;\n" ];
16 };
17
18 local $Scope::Upper::TestGenerator::test = sub {
19  my ($height, $level, $i, $x) = @_;
20  my $j = ($i == $height - $level) ? 0 : (defined $x ? $x : 'undef');
21  return "is(\$x, $j, 'x h=$height, l=$level, i=$i');\n";
22 };
23
24 local $Scope::Upper::TestGenerator::testlocal = sub { '' };
25
26 local $Scope::Upper::TestGenerator::allblocks = 1;
27
28 our ($x, $testcase);
29
30 {
31  no warnings 'redefine';
32  *is = sub ($$;$) {
33   my ($a, $b, $desc) = @_;
34   if (defined $testcase
35       and (defined $b) ? (not defined $a or $a != $b) : defined $a) {
36    diag <<DIAG;
37 === This testcase failed ===
38 $testcase
39 ==== vvvvv Errors vvvvvv ===
40 DIAG
41    undef $testcase;
42   }
43   Test::More::is($a, $b, $desc);
44  }
45 }
46
47 for my $level (0 .. 1) {
48  my $height = $level + 1;
49  my $tests = Scope::Upper::TestGenerator::gen($height, $level);
50  for (@$tests) {
51   $testcase = $_;
52   $x = undef;
53   eval;
54   diag $@ if $@;
55  }
56 }