]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/lib/Scope/Upper/TestGenerator.pm
Rework how Scope::Upper::TestGenerator generates its 'local' tests
[perl/modules/Scope-Upper.git] / t / lib / Scope / Upper / TestGenerator.pm
index 9ef65b8849474977047cd193d473d7755520c9ac..0b3a8e631433eb7a4cffb8e5387b4f041b576f00 100644 (file)
@@ -3,17 +3,24 @@ package Scope::Upper::TestGenerator;
 use strict;
 use warnings;
 
-our ($call, $test, $local, $testlocal, $allblocks);
+our ($call, $test, $allblocks);
 
-$local = sub {
+our $local_var = '$x';
+
+our $local_decl = sub {
+ my $x = $_[3];
+ return "local $local_var = $x;\n";
+};
+
+our $local_cond = sub {
  my $x = $_[3];
- return "local \$x = $x;\n";
+ return defined $x ? "($local_var eq $x)" : "(!defined($local_var))";
 };
 
-$testlocal = sub {
+our $local_test = sub {
  my ($height, $level, $i, $x) = @_;
- my $j = defined $x ? $x : 'undef';
- return "is(\$x, $j, 'x h=$height, l=$level, i=$i');\n";
+ my $cond = $local_cond->(@_);
+ return "ok($cond, 'local h=$height, l=$level, i=$i');\n";
 };
 
 my @blocks = (
@@ -51,7 +58,7 @@ sub gen {
  my $up   = gen($height, $level, $i + 1, $x);
  for my $base (@$up) {
   for my $blk (@blks) {
-   push @res, $blk->[0] . $base . $test->(@_) . $testlocal->(@_) . $blk->[1];
+   push @res, $blk->[0] . $base . $test->(@_) . $local_test->(@_) . $blk->[1];
   }
  }
  $_[3] = $i + 1;
@@ -59,7 +66,7 @@ sub gen {
  for my $base (@$up) {
   for my $blk (@blks) {
    push @res, $blk->[0] .
-               $local->(@_) . $base . $test->(@_) . $testlocal->(@_)
+               $local_decl->(@_) . $base . $test->(@_) . $local_test->(@_)
               . $blk->[1];
   }
  }