]> git.vpit.fr Git - perl/modules/indirect.git/blob - t/20-bad.t
Test 'package A; sub foo; foo A->new' that gets deparsed as 'A->foo->new'
[perl/modules/indirect.git] / t / 20-bad.t
1 #!perl -T
2
3 package Dongs;
4
5 sub new;
6
7 package main;
8
9 use strict;
10 use warnings;
11
12 use Test::More tests => 33 * 4 + 2;
13
14 my ($obj, $x);
15
16 {
17  local $/ = "####\n";
18  while (<DATA>) {
19   chomp;
20   local $SIG{__WARN__} = sub { die 'warn:' . join(' ', @_) };
21   {
22    use indirect;
23    eval "die qq{ok\\n}; $_";
24   }
25   is($@, "ok\n", "use indirect: $_");
26   {
27    no indirect;
28    eval "die qq{the code compiled but it shouldn't have\n}; $_";
29   }
30   like($@, qr/^warn:Indirect\s+call\s+of\s+method\s+"(?:new|meh|HlaghHlagh)"\s+on\s+object\s+"(?:Hlagh|newnew|\$x|\$_)"/, "no indirect: $_");
31   s/Hlagh/Dongs/g;
32   {
33    use indirect;
34    eval "die qq{ok\\n}; $_";
35   }
36   is($@, "ok\n", "use indirect, defined: $_");
37   {
38    no indirect;
39    eval "die qq{the code compiled but it shouldn't have\n}; $_";
40   }
41   like($@, qr/^warn:Indirect\s+call\s+of\s+method\s+"(?:new|meh|DongsDongs)"\s+on\s+object\s+"(?:Dongs|newnew|\$x|\$_)"/, "no indirect, defined: $_");
42  }
43 }
44
45 eval {
46  no indirect 'hlagh';
47  my $warn;
48  local $SIG{__WARN__} = sub { $warn = join ' ', @_ };
49  eval "die qq{the code compiled but it shouldn't have\n}; \$obj = new Hlagh1;";
50  like($warn, qr/^Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"Hlagh1"/, 'no indirect "hlagh" enables the pragma');
51  eval "die qq{the code compiled but it shouldn't have\n}; \$obj = new Hlagh2;";
52  like($warn, qr/^Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"Hlagh2"/, 'no indirect "hlagh" doesn\'t croak');
53 }
54
55 __DATA__
56 $obj = new Hlagh;
57 ####
58 $obj = new Hlagh();
59 ####
60 $obj = new Hlagh(1);
61 ####
62 $obj = new Hlagh(1, 2);
63 ####
64 $obj = new        Hlagh            ;
65 ####
66 $obj = new        Hlagh     (      )      ;
67 ####
68 $obj = new        Hlagh     (      1        )     ;
69 ####
70 $obj = new        Hlagh     (      1        ,       2        )     ;
71 ####
72 $obj = new    
73                       Hlagh             
74         ;
75 ####
76 $obj = new   
77                                        Hlagh     (    
78                   )      ;
79 ####
80 $obj =
81               new    
82     Hlagh     (      1   
83             )     ;
84 ####
85 $obj =
86 new      
87 Hlagh    
88                    (      1        ,  
89                 2        )     ;
90 ####
91 $obj = new $x;
92 ####
93 $obj = new $x();
94 ####
95 $obj = new $x('foo');
96 ####
97 $obj = new $x qq{foo}, 1;
98 ####
99 $obj = new $x qr{foo\s+bar}, 1 .. 1;
100 ####
101 $obj = new $x(qw/bar baz/);
102 ####
103 $obj = new
104           $_;
105 ####
106 $obj = new
107              $_     (        );
108 ####
109 $obj = new $_      qr/foo/  ;
110 ####
111 $obj = new $_     qq(bar baz);
112 ####
113 meh $x;
114 ####
115 meh $x, 1, 2;
116 ####
117 new Hlagh->wut;
118 ####
119 new Hlagh->wut();
120 ####
121 new Hlagh->wut, "Wut";
122 ####
123 $obj = HlaghHlagh Hlagh;
124 ####
125 $obj = HlaghHlagh Hlagh; # HlaghHlagh Hlagh
126 ####
127 $obj = new newnew;
128 ####
129 $obj = new newnew; # new newnew
130 ####
131 new Hlagh (meh $x)
132 ####
133 Hlagh->new(meh $x)