X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Findirect.git;a=blobdiff_plain;f=t%2F21-bad.t;h=5984ef03ba031984995b00508c9d464162b7ba57;hp=9f8f3ff0de6a5da8c40f90b81dbde18e7c6dcbdf;hb=f136bf535929d8e3d552f0e1c28e44bcc7b5c006;hpb=676ba859b2e1c5e7808bf1a12432e28997d660c9 diff --git a/t/21-bad.t b/t/21-bad.t index 9f8f3ff..5984ef0 100644 --- a/t/21-bad.t +++ b/t/21-bad.t @@ -11,11 +11,13 @@ use warnings; my ($tests, $reports); BEGIN { - $tests = 52; - $reports = 53; + $tests = 82; + $reports = 94; } -use Test::More tests => 3 * (4 * $tests + $reports) + 2; +use Test::More tests => 3 * (4 * $tests + $reports) + 4; + +BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} } my ($obj, $x); our ($y, $bloop); @@ -27,10 +29,11 @@ sub expect { map { my ($meth, $obj, $file, $line) = @$_; - $_ = quotemeta for $meth, $obj; - $file = '\(eval \d+\)' unless defined $file; - $line = '\d+' unless defined $line; - qr/^Indirect call of method "$meth" on object "$obj" at $file line $line/ + $meth = quotemeta $meth; + $obj = ($obj =~ /^\s*\{/) ? "a block" : "object \"\Q$obj\E\""; + $file = '\((?:re_)?eval \d+\)' unless defined $file; + $line = '\d+' unless defined $line; + qr/^Indirect call of method "$meth" on $obj at $file line $line/ } eval $expected; } @@ -41,7 +44,7 @@ sub try { @warns = (); { - local $SIG{__WARN__} = sub { push @warns, join(' ', @_) }; + local $SIG{__WARN__} = sub { push @warns, @_ }; eval $code; } } @@ -95,7 +98,10 @@ SKIP: } } +SKIP: { + skip 'No space tests on perl 5.11' => 4 + @expected + if $] >= 5.011 and $] < 5.012; my $code = $code; $code =~ s/\$/\$ \n\t /g; @@ -115,11 +121,17 @@ SKIP: } eval { - my $warn; - local $SIG{__WARN__} = sub { $warn = join ' ', @_ }; - eval "die qq{ok\n}; no indirect 'hlagh'; \$obj = new Hlagh1;"; - is($@, "ok\n", 'no indirect "hlagh" didn\'t croak'); - like($warn, qr/^Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"Hlagh1"/, 'no indirect "hlagh" enables the pragma'); + my @warns; + { + local $SIG{__WARN__} = sub { push @warns, @_ }; + eval "return; no indirect 'hlagh'; \$obj = new Hlagh1;"; + } + is $@, '', 'no indirect "hlagh" didn\'t croak'; + is @warns, 1, 'only one warning'; + my $warn = shift @warns; + like $warn, qr/^Indirect call of method "new" on object "Hlagh1"/, + 'no indirect "hlagh" enables the pragma'; + is_deeply \@warns, [ ], 'nothing more'; } __DATA__ @@ -128,6 +140,10 @@ $obj = new Hlagh; ---- [ 'new', 'Hlagh' ] #### +$obj = new Hlagh if 0; +---- +[ 'new', 'Hlagh' ] +#### $obj = new Hlagh(); ---- [ 'new', 'Hlagh' ] @@ -354,3 +370,124 @@ new Hlagh (meh $x) Hlagh->new(meh $x) ---- [ 'meh', '$x' ] +#### +$obj = "apple ${\(new Hlagh)} pear" +---- +[ 'new', 'Hlagh' ] +#### +$obj = "apple @{[new Hlagh]} pear" +---- +[ 'new', 'Hlagh' ] +#### +$obj = "apple ${\(new $x)} pear" +---- +[ 'new', '$x' ] +#### +$obj = "apple @{[new $x]} pear" +---- +[ 'new', '$x' ] +#### +$obj = "apple ${\(new $y)} pear" +---- +[ 'new', '$y' ] +#### +$obj = "apple @{[new $y]} pear" +---- +[ 'new', '$y' ] +#### +$obj = "apple ${\(new $x qq|${\(stuff $y)}|)} pear" +---- +[ 'stuff', '$y' ], [ 'new', '$x' ] +#### +$obj = "apple @{[new $x qq|@{[stuff $y]}|]} pear" +---- +[ 'stuff', '$y' ], [ 'new', '$x' ] +#### # local $_ = "foo"; +s/foo/return; new Hlagh/e; +---- +[ 'new', 'Hlagh' ] +#### # local $_ = "bar"; +s/foo/return; new Hlagh/e; +---- +[ 'new', 'Hlagh' ] +#### # local $_ = "foo"; +s/foo/return; new $x/e; +---- +[ 'new', '$x' ] +#### # local $_ = "bar"; +s/foo/return; new $x/e; +---- +[ 'new', '$x' ] +#### # local $_ = "foo"; +s/foo/return; new $y/e; +---- +[ 'new', '$y' ] +#### # local $_ = "bar"; +s/foo/return; new $y/e; +---- +[ 'new', '$y' ] +#### +"foo" =~ /(?{new Hlagh})/; +---- +[ 'new', 'Hlagh' ] +#### +"foo" =~ /(?{new $x})/; +---- +[ 'new', '$x' ] +#### +"foo" =~ /(?{new $y})/; +---- +[ 'new', '$y' ] +#### +"foo" =~ /(??{new Hlagh})/; +---- +[ 'new', 'Hlagh' ] +#### +"foo" =~ /(??{new $x})/; +---- +[ 'new', '$x' ] +#### +"foo" =~ /(??{new $y})/; +---- +[ 'new', '$y' ] +#### +meh { }; +---- +[ 'meh', '{' ] +#### +meh { + 1; +}; +---- +[ 'meh', '{' ] +#### +meh { + 1; + 1; +}; +---- +[ 'meh', '{' ] +#### +meh { new Hlagh; 1; }; +---- +[ 'new', 'Hlagh' ], [ 'meh', '{' ] +#### +meh { feh $x; 1; }; +---- +[ 'feh', '$x' ], [ 'meh', '{' ] +#### +meh { feh $x; use indirect; new Hlagh; 1; }; +---- +[ 'feh', '$x' ], [ 'meh', '{' ] +#### +meh { feh $y; 1; }; +---- +[ 'feh', '$y' ], [ 'meh', '{' ] +#### +meh { feh $x; 1; } new Hlagh, feh $y; +---- +[ 'feh', '$x' ], [ 'new', 'Hlagh' ], [ 'feh', '$y' ], [ 'meh', '{' ] +#### +$obj = "apple @{[new { feh $x; meh $y; 1 }]} pear" +---- +[ 'feh', '$x' ], [ 'meh', '$y' ], [ 'new', '{' ]