X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F22-bad-mixed.t;h=bcb9203410cef9d7b6c96e6f9c87f608f87c9d79;hb=0a8741013832fe465960ec1d6c7618f697f3d21e;hp=3a01f463bbe19124219dac69a05ba0f09e37ad39;hpb=16e155017652cb3e07702075aae4bbdc512e1480;p=perl%2Fmodules%2Findirect.git diff --git a/t/22-bad-mixed.t b/t/22-bad-mixed.t index 3a01f46..bcb9203 100644 --- a/t/22-bad-mixed.t +++ b/t/22-bad-mixed.t @@ -1,6 +1,6 @@ #!perl -T -package Dongs; +package NotEmpty; sub new; @@ -9,37 +9,73 @@ package main; use strict; use warnings; -use Test::More tests => 3 * 4; +use Test::More tests => 3 * 9; + +BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} } sub meh; +my @warns; + +sub try { + my ($code) = @_; + + @warns = (); + { + local $SIG{__WARN__} = sub { push @warns, @_ }; + eval $code; + } +} + { - local $/ = "####\n"; + local $/ = "####"; while () { chomp; s/\s*$//; + s/(.*?)$//m; + my ($skip, $prefix) = split /#+/, $1; + $skip = 0 unless defined $skip; + $prefix = '' unless defined $prefix; + s/\s*//; - local $SIG{__WARN__} = sub { die 'warn:' . join(' ', @_) }; +SKIP: + { + skip "$_: $skip" => 9 if do { local $@; eval $skip }; - eval "die qq{ok\\n}; use indirect; $_"; - is($@, "ok\n", "use indirect: $_"); + { + local $_ = $_; + s/Pkg/Empty/g; - eval "die qq{ok\n}; no indirect; $_"; - is($@, "ok\n", "no indirect: $_"); + try "return; $prefix; use indirect; $_"; + is $@, '', "use indirect: $_"; + is @warns, 0, 'correct number of reports'; - s/Hlagh/Dongs/g; + try "return; $prefix; no indirect; $_"; + is $@, '', "no indirect: $_"; + is @warns, 0, 'correct number of reports'; + } - eval "die qq{ok\\n}; use indirect; $_"; - is($@, "ok\n", "use indirect, defined: $_"); + { + local $_ = $_; + s/Pkg/NotEmpty/g; - eval "die qq{the code compiled but it shouldn't have\n}; no indirect; $_"; - like($@, qr/^warn:Indirect\s+call\s+of\s+method\s+"meh"\s+on\s+object\s+"Dongs"/, "no indirect, defined: $_"); + try "return; $prefix; use indirect; $_"; + is $@, '', "use indirect, defined: $_"; + is @warns, 0, 'correct number of reports'; + + try "return; $prefix; no indirect; $_"; + is $@, '', "use indirect, defined: $_"; + is @warns, 1, 'correct number of reports'; + like $warns[0], qr/^Indirect call of method "meh" on object "NotEmpty" at \(eval \d+\) line \d+/, 'report 0 is correct'; + } + } } } __DATA__ -meh Hlagh->new; + +meh Pkg->new; #### -meh Hlagh->new(); +meh Pkg->new(); #### -meh Hlagh->new, "Wut"; +meh Pkg->new, "Wut";