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