X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Findirect.git;a=blobdiff_plain;f=t%2F11-line.t;fp=t%2F11-line.t;h=6832844cc7ff28ee8f3d880ed1a2c1aad361ac6a;hp=0000000000000000000000000000000000000000;hb=eb4b05d5ad6eec232107b4688e59685bc54f7a65;hpb=9e8840b03b5cfb27dc88d7e1e85533fc6bbef6b5 diff --git a/t/11-line.t b/t/11-line.t new file mode 100644 index 0000000..6832844 --- /dev/null +++ b/t/11-line.t @@ -0,0 +1,48 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More tests => 3 * 4; + +sub expect { + my ($pkg, $line) = @_; + return qr/^Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"$pkg"\s+at\s+\(eval\s+\d+\)\s+line\s+$line/; +} + +{ + local $/ = "####"; + while () { + chomp; + s/^\s+//; + + my ($code, $lines) = split /#+/, $_, 2; + $lines = eval "[ sort ($lines) ]"; + if ($@) { + diag "Couldn't parse line numbers: $@"; + next; + } + + my (@warns, @lines); + { + local $SIG{__WARN__} = sub { push @warns, "@_" }; + eval "return; no indirect hook => sub { push \@lines, \$_[3] }; $code"; + } + + is $@, '', 'did\'t croak'; + is_deeply \@warns, [ ], 'didn\'t warn'; + is_deeply [ sort @lines ], $lines, 'correct line numbers'; + } +} + +__DATA__ +my $x = new X; # 1 +#### +my $x = new + X; # 1 +#### +my $x = new X; $x = new X; # 1, 1 +#### +my $x = new + X new + X; # 1, 2