]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/21-localize-level.t
Importing Scope-Upper-0.01
[perl/modules/Scope-Upper.git] / t / 21-localize-level.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 '\$main::y' => 1 => $level;\n" ];
16 }; 
17
18 local $Scope::Upper::TestGenerator::test = sub {
19  my ($height, $level, $i) = @_;
20  my $j = ($i == $height - $level) ? 1 : 'undef';
21  return "is(\$main::y, $j, 'y h=$height, l=$level, i=$i');\n";
22 };
23
24 our ($x, $y, $testcase);
25
26 {
27  no warnings 'redefine';
28  *is = sub ($$;$) {
29   my ($a, $b, $desc) = @_;
30   if (defined $testcase
31       and (defined $b) ? (not defined $a or $a != $b) : defined $a) {
32    diag <<DIAG;
33 === This testcase failed ===
34 $testcase
35 ==== vvvvv Errors vvvvvv ===
36 DIAG
37    undef $testcase;
38   }
39   Test::More::is($a, $b, $desc);
40  }
41 }
42
43 for my $level (0 .. 4) {
44  for my $height ($level + 1 .. $level + 2) {
45   my $tests = Scope::Upper::TestGenerator::gen($height, $level);
46   for (@$tests) {
47    $testcase = $_;
48    $x = $y = undef;
49    eval;
50    diag $@ if $@;
51   }
52  }
53 }