]> git.vpit.fr Git - perl/modules/indirect.git/blob - t/10-args.t
bb44e978fb1e346c02e01bd9db1f01f7c171e884
[perl/modules/indirect.git] / t / 10-args.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 4 + 1 + 1;
7
8 sub expect {
9  my ($pkg) = @_;
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+\d+/;
11 }
12
13 {
14  my @warns;
15  local $SIG{__WARN__} = sub { push @warns, "@_" };
16  eval <<'HERE';
17   die qq{ok\n};
18   no indirect;
19   my $x = new Warn1;
20   $x = new Warn2;
21 HERE
22  my $w1 = shift @warns;
23  my $w2 = shift @warns;
24  is             $@, "ok\n",          'didn\'t croak without arguments';
25  like          $w1, expect('Warn1'), 'first warning caught without arguments';
26  like          $w2, expect('Warn2'), 'second warning caught without arguments';
27  is_deeply \@warns, [ ],             'no more warnings without arguments';
28 }
29
30 {
31  local $SIG{__WARN__} = sub { die "warn:@_" };
32  eval <<'HERE';
33   die qq{shouldn't even compile\n};
34   no indirect ':fatal', hook => sub { die 'should not be called' };
35   my $x = new Fatal;
36   $x = new NotReached;
37 HERE
38  like $@, expect('Fatal'), 'croaks when :fatal is specified';
39 }
40
41 {
42  local $SIG{__WARN__} = sub { "warn:@_" };
43  eval <<'HERE';
44   die qq{shouldn't even compile\n};
45   no indirect 'whatever', hook => sub { die 'hook:' . join(':', @_) . "\n" }, ':fatal';
46   my $x = new Hooked;
47   $x = new AlsoNotReached;
48 HERE
49  like $@, qr/^hook:Hooked:new:\(eval\s+\d+\):\d+$/, 'calls the specified hook';
50 }