]> git.vpit.fr Git - perl/modules/indirect.git/blob - t/30-scope.t
Fix a rare edge case for package whose names are prefix of 'main'
[perl/modules/indirect.git] / t / 30-scope.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 my $tests;
7 BEGIN { $tests = 8 }
8
9 use Test::More tests => $tests + 1;
10
11 my %wrong = map { $_ => 1 } 2, 3, 5, 7;
12
13 {
14  my $code = do { local $/; <DATA> };
15  my @warns;
16  {
17   local $SIG{__WARN__} = sub { push @warns, join '', 'warn:', @_ };
18   eval "die qq{ok\\n}; $code";
19  }
20  my $left = 0;
21  my %res = map {
22   if (/"P(\d+)"/) {
23    $1 => $_
24   } else {
25    ++$left; ()
26   }
27  } @warns;
28  for (1 .. $tests) {
29   my $w = $res{$_};
30   if ($wrong{$_}) {
31    like($w, qr/^warn:Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"P$_"/, "$_ should warn");
32   } else {
33    is($w, undef, "$_ shouldn't warn");
34   }
35  }
36  is($left, 0, 'nothing left');
37 }
38
39 __DATA__
40 my $a = new P1;
41
42 {
43  no indirect;
44  my $b = new P2;
45  {
46   my $c = new P3;
47  }
48  {
49   use indirect;
50   my $d = new P4;
51  }
52  my $e = new P5;
53 }
54
55 my $f = new P6;
56
57 no indirect;
58
59 my $g = new P7;
60
61 use indirect;
62
63 my $h = new P8;