]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/11-reap-level.t
Importing Scope-Upper-0.01
[perl/modules/Scope-Upper.git] / t / 11-reap-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/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) = @_;
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 sub check { $y = 0 unless defined $y; ++$y }
27
28 {
29  no warnings 'redefine';
30  *is = sub ($$;$) {
31   my ($a, $b, $desc) = @_;
32   if (defined $testcase
33       and (defined $b) ? (not defined $a or $a != $b) : defined $a) {
34    diag <<DIAG;
35 === This testcase failed ===
36 $testcase
37 ==== vvvvv Errors vvvvvv ===
38 DIAG
39    undef $testcase;
40   }
41   Test::More::is($a, $b, $desc);
42  }
43 }
44
45 for my $level (0 .. 4) {
46  for my $height ($level + 1 .. $level + 2) {
47   my $tests = Scope::Upper::TestGenerator::gen($height, $level);
48   for (@$tests) {
49    $testcase = $_;
50    $x = $y = undef;
51    eval;
52    diag $@ if $@;
53   }
54  }
55 }