From: Vincent Pit Date: Sun, 9 Sep 2012 10:14:22 +0000 (+0200) Subject: Factor our verbose is() in Scope::Upper::TestGenerator X-Git-Tag: v0.20~19 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FScope-Upper.git;a=commitdiff_plain;h=824b421b73e313d2eb4fd950c231272c1a52ed58 Factor our verbose is() in Scope::Upper::TestGenerator --- diff --git a/t/11-reap-level.t b/t/11-reap-level.t index d5f639e..2844541 100644 --- a/t/11-reap-level.t +++ b/t/11-reap-level.t @@ -19,37 +19,19 @@ local $Scope::Upper::TestGenerator::call = sub { 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 <= 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(<