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