From: Vincent Pit Date: Fri, 19 Jun 2009 15:59:20 +0000 (+0200) Subject: Only generate the non-ref test once X-Git-Tag: v0.03~4 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=e540e218ec393e9e39bb2ac0dae6e7a586fef9c9;p=perl%2Fmodules%2Fautovivification.git Only generate the non-ref test once --- diff --git a/t/lib/autovivification/TestCases.pm b/t/lib/autovivification/TestCases.pm index 87dfd09..19ce7ea 100644 --- a/t/lib/autovivification/TestCases.pm +++ b/t/lib/autovivification/TestCases.pm @@ -60,38 +60,35 @@ sub testcase_ok { $opts = 'default'; $use = ''; } - my @testcases = ( + my @base = ([ $var, $init, $code, $exp, $use ]); + if ($var =~ /\$/) { + my @nonref = @{$base[0]}; + $nonref[0] =~ s/^\$/$sigil/; + for ($nonref[1], $nonref[2]) { + s/\Q$sigil$var\E/$nonref[0]/g; + s/\Q$var\E\->/$var/g; + } + my $simple = $nonref[2] !~ /->/; + my $plain_deref = $nonref[2] =~ /\Q$nonref[0]\E/; + my $empty = { '@' => '[ ]', '%' => '{ }' }->{$sigil}; + if (($simple + and ( $nonref[3] =~ m!qr/\^Reference vivification forbidden.*?/! + or $nonref[3] =~ m!qr/\^Can't vivify reference.*?/!)) + or ($plain_deref + and $nonref[3] =~ m!qr/\^Can't use an undefined value as a.*?/!)) { + $nonref[1] = ''; + $nonref[2] = 1; + $nonref[3] = "'', 1, $empty"; + } + $nonref[3] =~ s/,\s*undef\s*$/, $empty/; + push @base, \@nonref; + } + my @testcases = map { + my ($var, $init, $code, $exp, $use) = @$_; [ $var, $init, $code, $exp, $use, $opts, 0 ], [ $var, "use strict; $init", $code, $exp, $use, $opts, 1 ], [ $var, "no strict; $init", $code, $exp, $use, $opts, 1 ], - ); - my @extra; - for (@testcases) { - my $var = $_->[0]; - if ($var =~ /\$/) { - my @new = @$_; - $new[0] =~ s/^\$/$sigil/; - for ($new[1], $new[2]) { - s/\Q$sigil$var\E/$new[0]/g; - s/\Q$var\E\->/$var/g; - } - my $simple = $new[2] !~ /->/; - my $plain_deref = $new[2] =~ /\Q$new[0]\E/; - my $empty = { '@' => '[ ]', '%' => '{ }' }->{$sigil}; - if (($simple - and ( $new[3] =~ m!qr/\^Reference vivification forbidden.*?/! - or $new[3] =~ m!qr/\^Can't vivify reference.*?/!)) - or ($plain_deref - and $new[3] =~ m!qr/\^Can't use an undefined value as a.*?/!)) { - $new[1] = ''; - $new[2] = 1; - $new[3] = "'', 1, $empty"; - } - $new[3] =~ s/,\s*undef\s*$/, $empty/; - push @extra, \@new; - } - } - push @testcases, @extra; + } @base; for (@testcases) { my ($testcase, $desc) = generate(@$_); my @N = (0 .. 9);