]> git.vpit.fr Git - perl/modules/indirect.git/blob - t/11-line.t
Only enable the pragma during compile time
[perl/modules/indirect.git] / t / 11-line.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 3 * 4;
7
8 sub expect {
9  my ($pkg, $line) = @_;
10  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/;
11 }
12
13 {
14  local $/ = "####";
15  while (<DATA>) {
16   chomp;
17   s/^\s+//;
18
19   my ($code, $lines) = split /#+/, $_, 2;
20   $lines = eval "[ sort ($lines) ]";
21   if ($@) {
22    diag "Couldn't parse line numbers: $@";
23    next;
24   }
25
26   my (@warns, @lines);
27   {
28    local $SIG{__WARN__} = sub { push @warns, "@_" };
29    eval "return; no indirect hook => sub { push \@lines, \$_[3] }; $code";
30   }
31
32   is        $@,              '',     'did\'t croak';
33   is_deeply \@warns,         [ ],    'didn\'t warn';
34   is_deeply [ sort @lines ], $lines, 'correct line numbers';
35  }
36 }
37
38 __DATA__
39 my $x = new X;             # 1
40 ####
41 my $x = new
42   X;                       # 1
43 ####
44 my $x = new X; $x = new X; # 1, 1
45 ####
46 my $x = new
47  X new
48     X;                     # 1, 2