1 package Scope::Upper::TestGenerator;
6 our ($call, $test, $allblocks);
10 our $local_decl = sub {
12 return "local $local_var = $x;\n";
15 our $local_cond = sub {
17 return defined $x ? "($local_var eq $x)" : "(!defined($local_var))";
20 our $local_test = sub {
21 my ($height, $level, $i, $x) = @_;
22 my $cond = $local_cond->(@_);
23 return "ok($cond, 'local h=$height, l=$level, i=$i');\n";
28 [ 'sub {', '}->();' ],
35 push @blocks, [ 'given (1) {', '}' ] if "$]" >= 5.010_001;
38 verbose_is => \&verbose_is,
42 if ("$]" >= 5.010_001) {
44 feature->import('switch');
48 while (my ($name, $code) = each %exports) {
50 *{$pkg.'::'.$name} = $code;
54 @blocks = map [ map "$_\n", @$_ ], @blocks;
56 sub verbose_is ($$;$) {
57 my ($a, $b, $desc) = @_;
59 if (defined $::testcase
60 and (defined $b) ? (not defined $a or $a ne $b) : defined $a) {
61 Test::Leaner::diag(<<DIAG);
62 === This testcase failed ===
64 ==== vvvvv Errors vvvvvv ===
69 Test::Leaner::is($a, $b, $desc);
73 my ($height, $level, $i) = @_;
75 $j = 0 if $j > $#blocks or $j < 0;
76 return [ map "$_\n", @{$blocks[$j]} ];
80 my ($height, $level, $i, $x) = @_;
87 return $call->(@_) if $height < $i;
90 my @blks = $allblocks ? @blocks : _block(@_);
92 my $up = gen($height, $level, $i + 1, $x);
94 my $loct = $local_test->(@_);
97 push @res, join '', $blk->[0], $base, $t, $loct, $blk->[1];
102 $up = gen($height, $level, $i + 1, $x);
104 my $locd = $local_decl->(@_);
105 $loct = $local_test->(@_);
106 for my $base (@$up) {
107 for my $blk (@blks) {
108 push @res, join '', $blk->[0], $locd, $base, $t, $loct, $blk->[1];