File: 10-args.t

package info (click to toggle)
libindirect-perl 0.39-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 440 kB
  • sloc: perl: 3,166; ansic: 1,359; makefile: 8
file content (82 lines) | stat: -rw-r--r-- 2,003 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!perl -T

use strict;
use warnings;

use Test::More tests => 4 + 3 + 1 + 2;

BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} }

sub expect {
 my ($pkg) = @_;
 qr/^Indirect call of method "new" on object "$pkg" at \(eval \d+\) line \d+/;
}

{
 my @warns;
 {
  local $SIG{__WARN__} = sub { push @warns, "@_" };
  eval <<'  HERE';
   return;
   no indirect;
   my $x = new Warn1;
   $x = new Warn2;
  HERE
 }
 my $w1 = shift @warns;
 my $w2 = shift @warns;
 is             $@, '',              'didn\'t croak without arguments';
 like          $w1, expect('Warn1'), 'first warning caught without arguments';
 like          $w2, expect('Warn2'), 'second warning caught without arguments';
 is_deeply \@warns, [ ],             'no more warnings without arguments';
}

for my $fatal (':fatal', 'FATAL', ':Fatal') {
 {
  local $SIG{__WARN__} = sub { die "warn:@_" };
  eval <<"  HERE";
   die qq{shouldn't even compile\n};
   no indirect '$fatal';
   my \$x = new Croaked;
   \$x = new NotReached;
  HERE
 }
 like $@, expect('Croaked'), "croaks when $fatal is specified";
}

{
 {
  local $SIG{__WARN__} = sub { "warn:@_" };
  eval <<'  HERE';
   die qq{shouldn't even compile\n};
   no indirect 'whatever', hook => sub { die 'hook:' . join(':', @_) . "\n" };
   my $x = new Hooked;
   $x = new AlsoNotReached;
  HERE
 }
 like $@, qr/^hook:Hooked:new:\(eval\s+\d+\):\d+$/, 'calls the specified hook';
}

{
 my $no_hook_and_fatal = qr/^The 'fatal' and 'hook' options are mutually exclusive at \(eval \d+\) line \d+/;

 {
  local $SIG{__WARN__} = sub { die "warn:@_" };
  eval <<'  HERE';
   die qq{shouldn't even compile\n};
   no indirect 'fatal', hook => sub { };
   new NotReached;
  HERE
 }
 like $@, $no_hook_and_fatal, '"no indirect qw<fatal hook>" croaks';

 {
  local $SIG{__WARN__} = sub { die "warn:@_" };
  eval <<'  HERE';
   die qq{shouldn't even compile\n};
   no indirect hook => sub { }, 'fatal';
   new NotReached;
  HERE
 }
 like $@, $no_hook_and_fatal, '"no indirect qw<hook fatal>" croaks';
}