local $Scope::Upper::TestGenerator::test = sub {
my ($height, $level, $i) = @_;
my $j = $i < $height - $level ? 1 : 'undef';
- return "is(\$main::y, $j, 'y h=$height, l=$level, i=$i');\n";
+ return "verbose_is(\$main::y, $j, 'y h=$height, l=$level, i=$i');\n";
};
our ($x, $y, $testcase);
sub check { $y = 0 unless defined $y; ++$y }
-{
- no warnings 'redefine';
- *is = sub ($$;$) {
- my ($a, $b, $desc) = @_;
- if (defined $testcase
- and (defined $b) ? (not defined $a or $a != $b) : defined $a) {
- diag <<DIAG;
-=== This testcase failed ===
-$testcase
-==== vvvvv Errors vvvvvv ===
-DIAG
- undef $testcase;
- }
- Test::Leaner::is($a, $b, $desc);
- }
-}
-
for my $level (0 .. 2) {
for my $height ($level + 1 .. $level + 2) {
my $tests = Scope::Upper::TestGenerator::gen($height, $level);
- for (@$tests) {
- $testcase = $_;
+ for $testcase (@$tests) {
$x = $y = undef;
- eval;
+ eval $testcase;
diag $@ if $@;
}
}
local $Scope::Upper::TestGenerator::test = sub {
my ($height, $level, $i, $x) = @_;
my $j = $i < $height - $level ? 0 : (defined $x ? $x : 'undef');
- return "is(\$x, $j, 'x h=$height, l=$level, i=$i');\n";
+ return "verbose_is(\$x, $j, 'x h=$height, l=$level, i=$i');\n";
};
local $Scope::Upper::TestGenerator::local_decl = sub {
sub check { $x = (defined $x) ? ($x ? 0 : $x . 'x') : 0 }
-{
- no warnings 'redefine';
- *is = sub ($$;$) {
- my ($a, $b, $desc) = @_;
- if (defined $testcase
- and (defined $b) ? (not defined $a or $a != $b) : defined $a) {
- diag <<DIAG;
-=== This testcase failed ===
-$testcase
-==== vvvvv Errors vvvvvv ===
-DIAG
- undef $testcase;
- }
- Test::Leaner::is($a, $b, $desc);
- }
-}
-
for my $level (0 .. 1) {
my $height = $level + 1;
my $tests = Scope::Upper::TestGenerator::gen($height, $level);
- for (@$tests) {
- $testcase = $_;
+ for $testcase (@$tests) {
$x = undef;
- eval;
+ eval $testcase;
diag $@ if $@;
}
}
local $Scope::Upper::TestGenerator::test = sub {
my ($height, $level, $i) = @_;
my $j = ($i == $height - $level) ? 1 : 'undef';
- return "is(\$main::y, $j, 'y h=$height, l=$level, i=$i');\n";
+ return "verbose_is(\$main::y, $j, 'y h=$height, l=$level, i=$i');\n";
};
our ($x, $y, $testcase);
-{
- no warnings 'redefine';
- *is = sub ($$;$) {
- my ($a, $b, $desc) = @_;
- if (defined $testcase
- and (defined $b) ? (not defined $a or $a != $b) : defined $a) {
- diag <<DIAG;
-=== This testcase failed ===
-$testcase
-==== vvvvv Errors vvvvvv ===
-DIAG
- undef $testcase;
- }
- Test::Leaner::is($a, $b, $desc);
- }
-}
-
for my $level (0 .. 2) {
for my $height ($level + 1 .. $level + 2) {
my $tests = Scope::Upper::TestGenerator::gen($height, $level);
- for (@$tests) {
- $testcase = $_;
+ for $testcase (@$tests) {
$x = $y = undef;
- eval;
+ eval $testcase;
diag $@ if $@;
}
}
local $Scope::Upper::TestGenerator::test = sub {
my ($height, $level, $i, $x) = @_;
my $j = ($i == $height - $level) ? 0 : (defined $x ? $x : 'undef');
- return "is(\$x, $j, 'x h=$height, l=$level, i=$i');\n";
+ return "verbose_is(\$x, $j, 'x h=$height, l=$level, i=$i');\n";
};
local $Scope::Upper::TestGenerator::local_test = sub { '' };
our ($x, $testcase);
-{
- no warnings 'redefine';
- *is = sub ($$;$) {
- my ($a, $b, $desc) = @_;
- if (defined $testcase
- and (defined $b) ? (not defined $a or $a != $b) : defined $a) {
- diag <<DIAG;
-=== This testcase failed ===
-$testcase
-==== vvvvv Errors vvvvvv ===
-DIAG
- undef $testcase;
- }
- Test::Leaner::is($a, $b, $desc);
- }
-}
-
for my $level (0 .. 1) {
my $height = $level + 1;
my $tests = Scope::Upper::TestGenerator::gen($height, $level);
- for (@$tests) {
- $testcase = $_;
+ for $testcase (@$tests) {
$x = undef;
- eval;
+ eval $testcase;
diag $@ if $@;
}
}
for my $level (0 .. 2) {
for my $height ($level + 1 .. $level + 2) {
my $tests = Scope::Upper::TestGenerator::gen($height, $level);
- for (@$tests) {
- $testcase = $_;
+ for $testcase (@$tests) {
$x = undef;
@a = (1, 2);
- eval;
+ eval $testcase;
diag $@ if $@;
}
}
for my $level (0 .. 2) {
for my $height ($level + 1 .. $level + 2) {
my $tests = Scope::Upper::TestGenerator::gen($height, $level);
- for (@$tests) {
- $testcase = $_;
+ for $testcase (@$tests) {
$x = undef;
%h = ();
- eval;
+ eval $testcase;
diag $@ if $@;
}
}
local $Scope::Upper::TestGenerator::test = sub {
my ($height, $level, $i, $x) = @_;
my $j = ($i == $height - $level) ? 0 : (defined $x ? $x : 11);
- return "is(\$a[1], $j, 'x h=$height, l=$level, i=$i');\n";
+ return "verbose_is(\$a[1], $j, 'x h=$height, l=$level, i=$i');\n";
};
local $Scope::Upper::TestGenerator::local_var = '$a[1]';
for my $level (0 .. 1) {
my $height = $level + 1;
my $tests = Scope::Upper::TestGenerator::gen($height, $level);
- for (@$tests) {
- $testcase = $_;
+ for $testcase (@$tests) {
@a = (10, 11);
- eval;
+ eval $testcase;
diag $@ if $@;
}
}
local $Scope::Upper::TestGenerator::test = sub {
my ($height, $level, $i, $x) = @_;
my $j = ($i == $height - $level) ? 0 : (defined $x ? $x : 'undef');
- return "is(\$h{a}, $j, 'x h=$height, l=$level, i=$i');\n";
+ return "verbose_is(\$h{a}, $j, 'x h=$height, l=$level, i=$i');\n";
};
local $Scope::Upper::TestGenerator::local_var = '$h{a}';
for my $level (0 .. 1) {
my $height = $level + 1;
my $tests = Scope::Upper::TestGenerator::gen($height, $level);
- for (@$tests) {
- $testcase = $_;
+ for $testcase (@$tests) {
%h = ();
- eval;
+ eval $testcase;
diag $@ if $@;
}
}
local $Scope::Upper::TestGenerator::test = sub {
my ($height, $level, $i) = @_;
my $j = $i < $height - $level ? 1 : 'undef';
- return "is(\$main::y, $j, 'y h=$height, l=$level, i=$i');\n";
+ return "verbose_is(\$main::y, $j, 'y h=$height, l=$level, i=$i');\n";
};
our ($x, $y, $testcase);
sub check { $y = 0 unless defined $y; ++$y }
-{
- no warnings 'redefine';
- *is = sub ($$;$) {
- my ($a, $b, $desc) = @_;
- if (defined $testcase
- and (defined $b) ? (not defined $a or $a != $b) : defined $a) {
- diag <<DIAG;
-=== This testcase failed ===
-$testcase
-==== vvvvv Errors vvvvvv ===
-DIAG
- undef $testcase;
- }
- Test::Leaner::is($a, $b, $desc);
- }
-}
-
for my $level (0 .. 4) {
for my $height ($level + 1 .. $level + 2) {
my $tests = Scope::Upper::TestGenerator::gen($height, $level);
- for (@$tests) {
- $testcase = $_;
+ for $testcase (@$tests) {
$x = $y = undef;
- eval;
+ eval $testcase;
diag $@ if $@;
}
}
[ 'eval q[', '];' ],
);
+push @blocks, [ 'given (1) {', '}' ] if "$]" >= 5.010_001;
+
+my %exports = (
+ verbose_is => \&verbose_is,
+);
+
sub import {
if ("$]" >= 5.010_001) {
- push @blocks, [ 'given (1) {', '}' ];
require feature;
feature->import('switch');
}
+
+ my $pkg = caller;
+ while (my ($name, $code) = each %exports) {
+ no strict 'refs';
+ *{$pkg.'::'.$name} = $code;
+ }
}
@blocks = map [ map "$_\n", @$_ ], @blocks;
+sub verbose_is ($$;$) {
+ my ($a, $b, $desc) = @_;
+
+ if (defined $::testcase
+ and (defined $b) ? (not defined $a or $a ne $b) : defined $a) {
+ Test::Leaner::diag(<<DIAG);
+=== This testcase failed ===
+$::testcase
+==== vvvvv Errors vvvvvv ===
+DIAG
+ undef $::testcase;
+ }
+
+ Test::Leaner::is($a, $b, $desc);
+}
+
sub _block {
my ($height, $level, $i) = @_;
my $j = $height - $i;