]> git.vpit.fr Git - perl/modules/indirect.git/blob - t/30-scope.t
Test that the code compiled fine in t/30-scope.t
[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 + 2;
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   is($@, "ok\n", 'DATA compiled fine');
20  }
21  my $left = 0;
22  my %res = map {
23   if (/"P(\d+)"/) {
24    $1 => $_
25   } else {
26    ++$left; ()
27   }
28  } @warns;
29  for (1 .. $tests) {
30   my $w = $res{$_};
31   if ($wrong{$_}) {
32    like($w, qr/^warn:Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"P$_"/, "$_ should warn");
33   } else {
34    is($w, undef, "$_ shouldn't warn");
35   }
36  }
37  is($left, 0, 'nothing left');
38 }
39
40 __DATA__
41 my $a = new P1;
42
43 {
44  no indirect;
45  my $b = new P2;
46  {
47   my $c = new P3;
48  }
49  {
50   use indirect;
51   my $d = new P4;
52  }
53  my $e = new P5;
54 }
55
56 my $f = new P6;
57
58 no indirect;
59
60 my $g = new P7;
61
62 use indirect;
63
64 my $h = new P8;