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.017_011) {
44 warnings->unimport('experimental::smartmatch');
47 if ("$]" >= 5.010_001) {
49 feature->import('switch');
53 while (my ($name, $code) = each %exports) {
55 *{$pkg.'::'.$name} = $code;
59 @blocks = map [ map "$_\n", @$_ ], @blocks;
61 sub verbose_is ($$;$) {
62 my ($a, $b, $desc) = @_;
64 if (defined $::testcase
65 and (defined $b) ? (not defined $a or $a ne $b) : defined $a) {
66 Test::Leaner::diag(<<DIAG);
67 === This testcase failed ===
69 ==== vvvvv Errors vvvvvv ===
74 Test::Leaner::is($a, $b, $desc);
78 my ($height, $level, $i) = @_;
80 $j = 0 if $j > $#blocks or $j < 0;
81 return [ map "$_\n", @{$blocks[$j]} ];
85 my ($height, $level, $i, $x) = @_;
92 return $call->(@_) if $height < $i;
95 my @blks = $allblocks ? @blocks : _block(@_);
97 my $up = gen($height, $level, $i + 1, $x);
99 my $loct = $local_test->(@_);
100 for my $base (@$up) {
101 for my $blk (@blks) {
102 push @res, join '', $blk->[0], $base, $t, $loct, $blk->[1];
107 $up = gen($height, $level, $i + 1, $x);
109 my $locd = $local_decl->(@_);
110 $loct = $local_test->(@_);
111 for my $base (@$up) {
112 for my $blk (@blks) {
113 push @res, join '', $blk->[0], $locd, $base, $t, $loct, $blk->[1];