]> git.vpit.fr Git - perl/modules/indirect.git/blob - t/20-bad.t
Really test that no indirect 'hlagh' does not croak
[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 => 50 * 6 + 2;
13
14 use feature 'state';
15
16 my ($obj, $x);
17 our ($y, $bloop);
18 state $z;
19
20 sub expect {
21  my ($pkg) = @_;
22  return qr/^warn:Indirect call of method "(?:new|meh|$pkg$pkg)" on object "(?:$pkg|newnew|\$(?:[xyz_\$]|(?:sploosh::)?sploosh|(?:main::)?bloop))"/
23 }
24
25 {
26  local $/ = "####\n";
27  while (<DATA>) {
28   chomp;
29   s/\s*$//;
30   local $SIG{__WARN__} = sub { die 'warn:' . join(' ', @_) };
31   {
32    use indirect;
33    eval "die qq{ok\\n}; $_";
34   }
35   is($@, "ok\n", "use indirect: $_");
36   {
37    no indirect;
38    eval "die qq{the code compiled but it shouldn't have\n}; $_";
39   }
40   like($@, expect('Hlagh'), "no indirect: $_");
41   s/Hlagh/Dongs/g;
42   {
43    use indirect;
44    eval "die qq{ok\\n}; $_";
45   }
46   is($@, "ok\n", "use indirect, defined: $_");
47   {
48    no indirect;
49    eval "die qq{the code compiled but it shouldn't have\n}; $_";
50   }
51   like($@, expect('Dongs'), "no indirect, defined: $_");
52   s/\$/\$ \n\t /g;
53   s/Dongs/Hlagh/g;
54   {
55    use indirect;
56    eval "die qq{ok\\n}; $_";
57   }
58   is($@, "ok\n", "use indirect, spaces: $_");
59   {
60    no indirect;
61    eval "die qq{the code compiled but it shouldn't have\n}; $_";
62   }
63   like($@, expect('Hlagh'), "no indirect, spaces: $_");
64  }
65 }
66
67 eval {
68  no indirect 'hlagh';
69  my $warn;
70  local $SIG{__WARN__} = sub { $warn = join ' ', @_ };
71  eval "die qq{ok\n}; \$obj = new Hlagh1;";
72  is($@, "ok\n", 'no indirect "hlagh" didn\'t croak');
73  like($warn, qr/^Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"Hlagh1"/, 'no indirect "hlagh" enables the pragma');
74 }
75
76 __DATA__
77 $obj = new Hlagh;
78 ####
79 $obj = new Hlagh();
80 ####
81 $obj = new Hlagh(1);
82 ####
83 $obj = new Hlagh(1, 2);
84 ####
85 $obj = new        Hlagh            ;
86 ####
87 $obj = new        Hlagh     (      )      ;
88 ####
89 $obj = new        Hlagh     (      1        )     ;
90 ####
91 $obj = new        Hlagh     (      1        ,       2        )     ;
92 ####
93 $obj = new    
94                       Hlagh             
95         ;
96 ####
97 $obj = new   
98                                        Hlagh     (    
99                   )      ;
100 ####
101 $obj =
102               new    
103     Hlagh     (      1   
104             )     ;
105 ####
106 $obj =
107 new      
108 Hlagh    
109                    (      1        ,  
110                 2        )     ;
111 ####
112 $obj = new $x;
113 ####
114 $obj = new $x();
115 ####
116 $obj = new $x('foo');
117 ####
118 $obj = new $x qq{foo}, 1;
119 ####
120 $obj = new $x qr{foo\s+bar}, 1 .. 1;
121 ####
122 $obj = new $x(qw/bar baz/);
123 ####
124 $obj = new
125           $_;
126 ####
127 $obj = new
128              $_     (        );
129 ####
130 $obj = new $_      qr/foo/  ;
131 ####
132 $obj = new $_     qq(bar baz);
133 ####
134 meh $_;
135 ####
136 meh $_ 1, 2;
137 ####
138 meh $$;
139 ####
140 meh $$ 1, 2;
141 ####
142 meh $x;
143 ####
144 meh $x 1, 2;
145 ####
146 meh $x, 1, 2;
147 ####
148 meh $y;
149 ####
150 meh $y 1, 2;
151 ####
152 meh $y, 1, 2;
153 ####
154 meh $z;
155 ####
156 meh $z 1, 2;
157 ####
158 meh $z, 1, 2;
159 ####
160 package sploosh;
161 our $sploosh;
162 meh $sploosh::sploosh;
163 ####
164 package sploosh;
165 our $sploosh;
166 meh $sploosh;
167 ####
168 package sploosh;
169 meh $main::bloop;
170 ####
171 package sploosh;
172 meh $bloop;
173 ####
174 package ma;
175 meh $bloop;
176 ####
177 package sploosh;
178 our $sploosh;
179 package main;
180 meh $sploosh::sploosh;
181 ####
182 new Hlagh->wut;
183 ####
184 new Hlagh->wut();
185 ####
186 new Hlagh->wut, "Wut";
187 ####
188 $obj = HlaghHlagh Hlagh;
189 ####
190 $obj = HlaghHlagh Hlagh; # HlaghHlagh Hlagh
191 ####
192 $obj = new newnew;
193 ####
194 $obj = new newnew; # new newnew
195 ####
196 new Hlagh (meh $x)
197 ####
198 Hlagh->new(meh $x)