]> git.vpit.fr Git - perl/modules/indirect.git/blob - t/30-scope.t
Importing indirect-0.01.tar.gz
[perl/modules/indirect.git] / t / 30-scope.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 my $total;
7 BEGIN {
8  $total = 8;
9 }
10
11 use Test::More tests => $total + 1;
12
13 use IPC::Cmd qw/run/;
14
15 (my $success, my $err_code, undef, undef, my $stderr)
16  = run command => [
17           $^X,
18           map('-I' . $_, @INC),
19           '-c',
20           't/data/mixed.d'
21    ];
22 unless ($success) {
23  $stderr = pop @$stderr if ref $stderr eq 'ARRAY';
24  BAIL_OUT("Failed to execute data file (error $err_code) : $stderr");
25 }
26 $stderr = join "\n", @$stderr if ref $stderr eq 'ARRAY';
27
28 my %fail = map { $_ => 1 } 2, 3, 5, 7;
29 my %failed;
30 my $extra_fail = 0;
31
32 while ($stderr =~ /^Indirect\s+call\s+of\s+method\s+"([^"]+)"\s+on\s+object\s+"([^"]+)"/mg) {
33  my ($m, $o) = ($1, $2);
34  my $id;
35  if ($o =~ /^P(\d+)$/) {
36   $id = $1;
37  } else {
38   diag "$m $o";
39   ++$extra_fail;
40  }
41  if ($id) {
42   if (exists $fail{$id}) {
43    pass("test $id failed as expected");
44    delete $fail{$id};
45    $failed{$id} = 1;
46   } else {
47    fail("test $id shouldn't have failed");
48   }
49  }
50 }
51
52 pass("test $_ hasn't failed") for grep { !$failed{$_} } 1 .. $total;
53 fail("test $_ should have failed") for sort { $a <=> $b } keys %fail;
54 is($extra_fail, 0, 'no extra fails');