3 # Contributed by Graham Barr <Graham.Barr@tiuk.ti.com>
5 # So far there are tests for the following prototypes.
6 # none, () ($) ($@) ($%) ($;$) (&) (&\@) (&@) (%) (\%) (\@)
8 # It is impossible to test every prototype that can be specified, but
9 # we should test as many as we can.
16 ## Something really weird is happening here. Try changing the order
17 ## of the next three lines, and try moving them to after the definition
18 ## of testing, some combinations cause the script to fail while
19 ## running tests on (&\@)
29 my $p = prototype(shift);
31 my $what = defined $c ? '(' . $p . ')' : 'no prototype';
33 print '# Testing ',$what,"\n";
36 if((defined($p) && defined($c) && $p ne $c)
37 || (defined($p) != defined($c)));
38 printf "ok %d\n",$i++;
46 testing \&no_proto, undef;
49 print "# \@_ = (",join(",",@_),")\n";
53 print "not " unless 0 == no_proto();
54 printf "ok %d\n",$i++;
56 print "not " unless 1 == no_proto(5);
57 printf "ok %d\n",$i++;
59 print "not " unless 4 == &no_proto;
60 printf "ok %d\n",$i++;
62 print "not " unless 1 == no_proto +6;
63 printf "ok %d\n",$i++;
65 print "not " unless 4 == no_proto(@_);
66 printf "ok %d\n",$i++;
73 testing \&no_args, '';
76 print "# \@_ = (",join(",",@_),")\n";
80 print "not " unless 0 == no_args();
81 printf "ok %d\n",$i++;
83 print "not " unless 0 == no_args;
84 printf "ok %d\n",$i++;
86 print "not " unless 5 == no_args +5;
87 printf "ok %d\n",$i++;
89 print "not " unless 4 == &no_args;
90 printf "ok %d\n",$i++;
92 print "not " unless 2 == &no_args(1,2);
93 printf "ok %d\n",$i++;
96 print "not " unless $@;
97 printf "ok %d\n",$i++;
103 testing \&one_args, '$';
106 print "# \@_ = (",join(",",@_),")\n";
110 print "not " unless 1 == one_args(1);
111 printf "ok %d\n",$i++;
113 print "not " unless 1 == one_args +5;
114 printf "ok %d\n",$i++;
116 print "not " unless 4 == &one_args;
117 printf "ok %d\n",$i++;
119 print "not " unless 2 == &one_args(1,2);
120 printf "ok %d\n",$i++;
122 eval "one_args(1,2)";
123 print "not " unless $@;
124 printf "ok %d\n",$i++;
127 print "not " unless $@;
128 printf "ok %d\n",$i++;
131 print "# \@_ = (",join(",",@_),")\n";
132 print "not " unless @_ == 1 && $_[0] == 4;
133 printf "ok %d\n",$i++;
142 testing \&over_one_args, '$@';
144 sub over_one_args ($@) {
145 print "# \@_ = (",join(",",@_),")\n";
149 print "not " unless 1 == over_one_args(1);
150 printf "ok %d\n",$i++;
152 print "not " unless 2 == over_one_args(1,2);
153 printf "ok %d\n",$i++;
155 print "not " unless 1 == over_one_args +5;
156 printf "ok %d\n",$i++;
158 print "not " unless 4 == &over_one_args;
159 printf "ok %d\n",$i++;
161 print "not " unless 2 == &over_one_args(1,2);
162 printf "ok %d\n",$i++;
164 print "not " unless 5 == &over_one_args(1,@_);
165 printf "ok %d\n",$i++;
167 eval "over_one_args()";
168 print "not " unless $@;
169 printf "ok %d\n",$i++;
171 sub over_one_a_args ($@) {
172 print "# \@_ = (",join(",",@_),")\n";
173 print "not " unless @_ >= 1 && $_[0] == 4;
174 printf "ok %d\n",$i++;
178 over_one_a_args(@_,1);
179 over_one_a_args(@_,1,2);
180 over_one_a_args(@_,@_);
186 testing \&scalar_and_hash, '$%';
188 sub scalar_and_hash ($%) {
189 print "# \@_ = (",join(",",@_),")\n";
193 print "not " unless 1 == scalar_and_hash(1);
194 printf "ok %d\n",$i++;
196 print "not " unless 3 == scalar_and_hash(1,2,3);
197 printf "ok %d\n",$i++;
199 print "not " unless 1 == scalar_and_hash +5;
200 printf "ok %d\n",$i++;
202 print "not " unless 4 == &scalar_and_hash;
203 printf "ok %d\n",$i++;
205 print "not " unless 2 == &scalar_and_hash(1,2);
206 printf "ok %d\n",$i++;
208 print "not " unless 5 == &scalar_and_hash(1,@_);
209 printf "ok %d\n",$i++;
211 eval "scalar_and_hash()";
212 print "not " unless $@;
213 printf "ok %d\n",$i++;
215 sub scalar_and_hash_a ($@) {
216 print "# \@_ = (",join(",",@_),")\n";
217 print "not " unless @_ >= 1 && $_[0] == 4;
218 printf "ok %d\n",$i++;
221 scalar_and_hash_a(@_);
222 scalar_and_hash_a(@_,1);
223 scalar_and_hash_a(@_,1,2);
224 scalar_and_hash_a(@_,@_);
230 testing \&one_or_two, '$;$';
232 sub one_or_two ($;$) {
233 print "# \@_ = (",join(",",@_),")\n";
237 print "not " unless 1 == one_or_two(1);
238 printf "ok %d\n",$i++;
240 print "not " unless 2 == one_or_two(1,3);
241 printf "ok %d\n",$i++;
243 print "not " unless 1 == one_or_two +5;
244 printf "ok %d\n",$i++;
246 print "not " unless 4 == &one_or_two;
247 printf "ok %d\n",$i++;
249 print "not " unless 3 == &one_or_two(1,2,3);
250 printf "ok %d\n",$i++;
252 print "not " unless 5 == &one_or_two(1,@_);
253 printf "ok %d\n",$i++;
256 print "not " unless $@;
257 printf "ok %d\n",$i++;
259 eval "one_or_two(1,2,3)";
260 print "not " unless $@;
261 printf "ok %d\n",$i++;
263 sub one_or_two_a ($;$) {
264 print "# \@_ = (",join(",",@_),")\n";
265 print "not " unless @_ >= 1 && $_[0] == 4;
266 printf "ok %d\n",$i++;
277 testing \&a_sub, '&';
280 print "# \@_ = (",join(",",@_),")\n";
284 sub tmp_sub_1 { printf "ok %d\n",$i++ }
286 a_sub { printf "ok %d\n",$i++ };
289 @array = ( \&tmp_sub_1 );
291 print "not " unless $@;
292 printf "ok %d\n",$i++;
298 testing \&sub_aref, '&\@';
301 print "# \@_ = (",join(",",@_),")\n";
302 my($sub,$array) = @_;
303 print "not " unless @_ == 2 && @{$array} == 4;
304 print map { &{$sub}($_) } @{$array}
307 @array = (qw(O K)," ", $i++);
308 sub_aref { lc shift } @array;
315 testing \&sub_array, '&@';
318 print "# \@_ = (",join(",",@_),")\n";
319 print "not " unless @_ == 5;
321 print map { &{$sub}($_) } @_
324 @array = (qw(O K)," ", $i++);
325 sub_array { lc shift } @array;
332 testing \&a_hash, '%';
335 print "# \@_ = (",join(",",@_),")\n";
339 print "not " unless 1 == a_hash 'a';
340 printf "ok %d\n",$i++;
342 print "not " unless 2 == a_hash 'a','b';
343 printf "ok %d\n",$i++;
349 testing \&a_hash_ref, '\%';
351 sub a_hash_ref (\%) {
352 print "# \@_ = (",join(",",@_),")\n";
353 print "not " unless ref($_[0]) && $_[0]->{'a'};
354 printf "ok %d\n",$i++;
360 print "not " unless $hash{'b'} == 2;
361 printf "ok %d\n",$i++;
367 testing \&an_array_ref, '\@';
369 sub an_array_ref (\@) {
370 print "# \@_ = (",join(",",@_),")\n";
371 print "not " unless ref($_[0]) && 1 == @{$_[0]};
372 printf "ok %d\n",$i++;
373 @{$_[0]} = (qw(ok)," ",$i++,"\n");
378 print "not " unless @array == 4;