]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/12-reap-block.t
Importing Scope-Upper-0.01
[perl/modules/Scope-Upper.git] / t / 12-reap-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/reap/;
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 [ "reap \\&check => $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::local = sub {
25  my ($height, $level, $i, $x) = @_;
26  return $i == $height - $level ? "\$x = $x;\n" : "local \$x = $x;\n";
27 };
28
29 local $Scope::Upper::TestGenerator::testlocal = sub { '' };
30
31 local $Scope::Upper::TestGenerator::allblocks = 1;
32
33 our ($x, $testcase);
34
35 sub check { $x = (defined $x) ? ($x ? 0 : $x . 'x') : 0 }
36
37 {
38  no warnings 'redefine';
39  *is = sub ($$;$) {
40   my ($a, $b, $desc) = @_;
41   if (defined $testcase
42       and (defined $b) ? (not defined $a or $a != $b) : defined $a) {
43    diag <<DIAG;
44 === This testcase failed ===
45 $testcase
46 ==== vvvvv Errors vvvvvv ===
47 DIAG
48    undef $testcase;
49   }
50   Test::More::is($a, $b, $desc);
51  }
52 }
53
54 for my $level (0 .. 1) {
55  my $height = $level + 1;
56  my $tests = Scope::Upper::TestGenerator::gen($height, $level);
57  for (@$tests) {
58   $testcase = $_;
59   $x = undef;
60   eval;
61   diag $@ if $@;
62  }
63 }