Commit | Line | Data |
9f0ea43f |
1 | #!/usr/bin/perl -w |
2 | |
4f2c4fd8 |
3 | print "1..52\n"; |
af6c647e |
4 | |
5 | BEGIN { |
39234879 |
6 | if( $ENV{PERL_CORE} ) { |
7 | chdir 't' if -d 't'; |
8 | @INC = '../lib'; |
9 | } |
af6c647e |
10 | } |
11 | |
d7f97632 |
12 | # use warnings; |
af6c647e |
13 | use strict; |
14 | use ExtUtils::MakeMaker; |
15 | use ExtUtils::Constant qw (constant_types C_constant XS_constant autoload); |
16 | use Config; |
4f2c4fd8 |
17 | use File::Spec; |
18 | |
19 | my $do_utf_tests = $] > 5.006; |
20 | my $better_than_56 = $] > 5.007; |
21 | |
835f860c |
22 | # Because were are going to be changing directory before running Makefile.PL |
4f2c4fd8 |
23 | my $perl = $^X; |
24 | # 5.005 doesn't have new enough File::Spec to have rel2abs. But actually we |
25 | # only need it when $^X isn't absolute, which is going to be 5.8.0 or later |
26 | # (where ExtUtils::Constant is in the core, and tests against the uninstalled |
27 | # perl |
28 | $perl = File::Spec->rel2abs ($perl) unless $] < 5.006; |
6d79cad2 |
29 | # ExtUtils::Constant::C_constant uses $^X inside a comment, and we want to |
30 | # compare output to ensure that it is the same. We were probably run as ./perl |
31 | # whereas we will run the child with the full path in $perl. So make $^X for |
32 | # us the same as our child will see. |
33 | $^X = $perl; |
af6c647e |
34 | |
835f860c |
35 | print "# perl=$perl\n"; |
4f2c4fd8 |
36 | |
37 | my $lib = $ENV{PERL_CORE} ? '../../lib' : '../blib/lib'; |
38 | my $runperl = "$perl \"-I$lib\""; |
94b1a389 |
39 | |
af6c647e |
40 | $| = 1; |
41 | |
42 | my $dir = "ext-$$"; |
0ddb8edc |
43 | my @files; |
94b1a389 |
44 | |
45 | print "# $dir being created...\n"; |
46 | mkdir $dir, 0777 or die "mkdir: $!\n"; |
47 | |
535acd0f |
48 | my $output = "output"; |
af6c647e |
49 | |
6557ab03 |
50 | # For debugging set this to 1. |
51 | my $keep_files = 0; |
52 | |
af6c647e |
53 | END { |
94b1a389 |
54 | use File::Path; |
55 | print "# $dir being removed...\n"; |
6557ab03 |
56 | rmtree($dir) unless $keep_files; |
af6c647e |
57 | } |
58 | |
6d79cad2 |
59 | my $package = "ExtTest"; |
60 | |
8ac27563 |
61 | # Test the code that generates 1 and 2 letter name comparisons. |
62 | my %compass = ( |
d7f97632 |
63 | N => 0, 'NE' => 45, E => 90, SE => 135, S => 180, SW => 225, W => 270, NW => 315 |
8ac27563 |
64 | ); |
65 | |
cea00dc5 |
66 | my $parent_rfc1149 = |
67 | 'A Standard for the Transmission of IP Datagrams on Avian Carriers'; |
6557ab03 |
68 | # Check that 8 bit and unicode names don't cause problems. |
63e7cc8f |
69 | my $pound; |
70 | if (ord('A') == 193) { # EBCDIC platform |
71 | $pound = chr 177; # A pound sign. (Currency) |
72 | } else { # ASCII platform |
73 | $pound = chr 163; # A pound sign. (Currency) |
74 | } |
4f2c4fd8 |
75 | |
76 | my ($inf, $pound_bytes, $pound_utf8); |
77 | if ($do_utf_tests) { |
78 | $inf = chr 0x221E; |
79 | # Check that we can distiguish the pathological case of a string, and the |
80 | # utf8 representation of that string. |
81 | $pound_utf8 = $pound . '1'; |
82 | if ($better_than_56) { |
83 | $pound_bytes = $pound_utf8; |
84 | utf8::encode ($pound_bytes); |
85 | } else { |
86 | # Must have that "U*" to generate a zero length UTF string that forces |
87 | # top bit set chars (such as the pound sign) into UTF8, so that the |
88 | # unpack 'C*' then gets the byte form of the UTF8. |
89 | $pound_bytes = pack 'C*', unpack 'C*', $pound_utf8 . pack "U*"; |
90 | } |
91 | } |
cea00dc5 |
92 | |
835f860c |
93 | my @names = ("FIVE", {name=>"OK6", type=>"PV",}, |
94 | {name=>"OK7", type=>"PVN", |
95 | value=>['"not ok 7\\n\\0ok 7\\n"', 15]}, |
af6c647e |
96 | {name => "FARTHING", type=>"NV"}, |
6d79cad2 |
97 | {name => "NOT_ZERO", type=>"UV", value=>"~(UV)0"}, |
72f7b9a1 |
98 | {name => "OPEN", type=>"PV", value=>'"/*"', macro=>1}, |
6d79cad2 |
99 | {name => "CLOSE", type=>"PV", value=>'"*/"', |
100 | macro=>["#if 1\n", "#endif\n"]}, |
3414cef0 |
101 | {name => "ANSWER", default=>["UV", 42]}, "NOTDEF", |
102 | {name => "Yes", type=>"YES"}, |
103 | {name => "No", type=>"NO"}, |
19d75eda |
104 | {name => "Undef", type=>"UNDEF"}, |
cea00dc5 |
105 | # OK. It wasn't really designed to allow the creation of dual valued constants. |
106 | # It was more for INADDR_ANY INADDR_BROADCAST INADDR_LOOPBACK INADDR_NONE |
107 | {name=>"RFC1149", type=>"SV", value=>"sv_2mortal(temp_sv)", |
108 | pre=>"SV *temp_sv = newSVpv(RFC1149, 0); " |
109 | . "(void) SvUPGRADE(temp_sv,SVt_PVIV); SvIOK_on(temp_sv); " |
110 | . "SvIVX(temp_sv) = 1149;"}, |
6557ab03 |
111 | {name=>"perl", type=>"PV",}, |
3414cef0 |
112 | ); |
af6c647e |
113 | |
8ac27563 |
114 | push @names, $_ foreach keys %compass; |
115 | |
6557ab03 |
116 | # Automatically compile the list of all the macro names, and make them |
117 | # exported constants. |
af6c647e |
118 | my @names_only = map {(ref $_) ? $_->{name} : $_} @names; |
119 | |
6557ab03 |
120 | # Exporter::Heavy (currently) isn't able to export these names: |
121 | push @names, ({name=>"*/", type=>"PV", value=>'"CLOSE"', macro=>1}, |
122 | {name=>"/*", type=>"PV", value=>'"OPEN"', macro=>1}, |
123 | {name=>$pound, type=>"PV", value=>'"Sterling"', macro=>1}, |
6557ab03 |
124 | ); |
125 | |
4f2c4fd8 |
126 | if ($do_utf_tests) { |
127 | push @names, ({name=>$inf, type=>"PV", value=>'"Infinity"', macro=>1}, |
128 | {name=>$pound_utf8, type=>"PV", value=>'"1 Pound"', macro=>1}, |
129 | {name=>$pound_bytes, type=>"PV", value=>'"1 Pound (as bytes)"', |
130 | macro=>1}, |
131 | ); |
132 | } |
133 | |
6557ab03 |
134 | =pod |
135 | |
136 | The above set of names seems to produce a suitably bad set of compile |
137 | problems on a Unicode naive version of ExtUtils::Constant (ie 0.11): |
138 | |
139 | nick@thinking-cap 15439-32-utf$ PERL_CORE=1 ./perl lib/ExtUtils/t/Constant.t |
140 | 1..33 |
141 | # perl=/stuff/perl5/15439-32-utf/perl |
142 | # ext-30370 being created... |
143 | Wide character in print at lib/ExtUtils/t/Constant.t line 140. |
144 | ok 1 |
145 | ok 2 |
146 | # make = 'make' |
147 | ExtTest.xs: In function `constant_1': |
148 | ExtTest.xs:80: warning: multi-character character constant |
149 | ExtTest.xs:80: warning: case value out of range |
150 | ok 3 |
151 | |
152 | =cut |
153 | |
4f2c4fd8 |
154 | # Grr ` |
155 | |
6d79cad2 |
156 | my $types = {}; |
157 | my $constant_types = constant_types(); # macro defs |
158 | my $C_constant = join "\n", |
159 | C_constant ($package, undef, "IV", $types, undef, undef, @names); |
160 | my $XS_constant = XS_constant ($package, $types); # XS for ExtTest::constant |
161 | |
af6c647e |
162 | ################ Header |
4f2c4fd8 |
163 | my $header = File::Spec->catdir($dir, "test.h"); |
0ddb8edc |
164 | push @files, "test.h"; |
94b1a389 |
165 | open FH, ">$header" or die "open >$header: $!\n"; |
cea00dc5 |
166 | print FH <<"EOT"; |
835f860c |
167 | #define FIVE 5 |
7b6ffde5 |
168 | #define OK6 "ok 6\\n" |
835f860c |
169 | #define OK7 1 |
af6c647e |
170 | #define FARTHING 0.25 |
171 | #define NOT_ZERO 1 |
3414cef0 |
172 | #define Yes 0 |
173 | #define No 1 |
174 | #define Undef 1 |
cea00dc5 |
175 | #define RFC1149 "$parent_rfc1149" |
6d79cad2 |
176 | #undef NOTDEF |
6557ab03 |
177 | #define perl "rules" |
af6c647e |
178 | EOT |
8ac27563 |
179 | |
180 | while (my ($point, $bearing) = each %compass) { |
181 | print FH "#define $point $bearing\n" |
182 | } |
94b1a389 |
183 | close FH or die "close $header: $!\n"; |
af6c647e |
184 | |
185 | ################ XS |
4f2c4fd8 |
186 | my $xs = File::Spec->catdir($dir, "$package.xs"); |
0ddb8edc |
187 | push @files, "$package.xs"; |
94b1a389 |
188 | open FH, ">$xs" or die "open >$xs: $!\n"; |
af6c647e |
189 | |
190 | print FH <<'EOT'; |
191 | #include "EXTERN.h" |
192 | #include "perl.h" |
193 | #include "XSUB.h" |
194 | EOT |
195 | |
196 | print FH "#include \"test.h\"\n\n"; |
6d79cad2 |
197 | print FH $constant_types; |
198 | print FH $C_constant, "\n"; |
af6c647e |
199 | print FH "MODULE = $package PACKAGE = $package\n"; |
200 | print FH "PROTOTYPES: ENABLE\n"; |
6d79cad2 |
201 | print FH $XS_constant; |
94b1a389 |
202 | close FH or die "close $xs: $!\n"; |
af6c647e |
203 | |
204 | ################ PM |
4f2c4fd8 |
205 | my $pm = File::Spec->catdir($dir, "$package.pm"); |
0ddb8edc |
206 | push @files, "$package.pm"; |
94b1a389 |
207 | open FH, ">$pm" or die "open >$pm: $!\n"; |
af6c647e |
208 | print FH "package $package;\n"; |
209 | print FH "use $];\n"; |
210 | |
211 | print FH <<'EOT'; |
212 | |
213 | use strict; |
d7f97632 |
214 | EOT |
215 | printf FH "use warnings;\n" unless $] < 5.006; |
216 | print FH <<'EOT'; |
af6c647e |
217 | use Carp; |
218 | |
219 | require Exporter; |
220 | require DynaLoader; |
d7f97632 |
221 | use vars qw ($VERSION @ISA @EXPORT_OK $AUTOLOAD); |
af6c647e |
222 | |
223 | $VERSION = '0.01'; |
224 | @ISA = qw(Exporter DynaLoader); |
225 | @EXPORT_OK = qw( |
226 | EOT |
227 | |
6557ab03 |
228 | # Print the names of all our autoloaded constants |
af6c647e |
229 | print FH "\t$_\n" foreach (@names_only); |
230 | print FH ");\n"; |
6557ab03 |
231 | # Print the AUTOLOAD subroutine ExtUtils::Constant generated for us |
af6c647e |
232 | print FH autoload ($package, $]); |
233 | print FH "bootstrap $package \$VERSION;\n1;\n__END__\n"; |
94b1a389 |
234 | close FH or die "close $pm: $!\n"; |
af6c647e |
235 | |
236 | ################ test.pl |
4f2c4fd8 |
237 | my $testpl = File::Spec->catdir($dir, "test.pl"); |
0ddb8edc |
238 | push @files, "test.pl"; |
94b1a389 |
239 | open FH, ">$testpl" or die "open >$testpl: $!\n"; |
af6c647e |
240 | |
6d79cad2 |
241 | print FH "use strict;\n"; |
4f2c4fd8 |
242 | print FH "use $package qw(@names_only);\n\n"; |
243 | |
244 | print FH "use utf8\n\n" if $do_utf_tests; |
535acd0f |
245 | |
4f2c4fd8 |
246 | print FH <<"EOT"; |
6557ab03 |
247 | |
535acd0f |
248 | print "1..1\n"; |
249 | if (open OUTPUT, ">$output") { |
250 | print "ok 1\n"; |
251 | select OUTPUT; |
252 | } else { |
253 | print "not ok 1 # Failed to open '$output': $!\n"; |
254 | exit 1; |
255 | } |
256 | EOT |
af6c647e |
257 | |
535acd0f |
258 | print FH << 'EOT'; |
259 | |
4f2c4fd8 |
260 | my $better_than_56 = $] > 5.007; |
261 | |
535acd0f |
262 | # What follows goes to the temporary file. |
6d79cad2 |
263 | # IV |
835f860c |
264 | my $five = FIVE; |
265 | if ($five == 5) { |
266 | print "ok 5\n"; |
af6c647e |
267 | } else { |
835f860c |
268 | print "not ok 5 # $five\n"; |
af6c647e |
269 | } |
270 | |
6d79cad2 |
271 | # PV |
835f860c |
272 | print OK6; |
af6c647e |
273 | |
6d79cad2 |
274 | # PVN containing embedded \0s |
835f860c |
275 | $_ = OK7; |
af6c647e |
276 | s/.*\0//s; |
277 | print; |
278 | |
6d79cad2 |
279 | # NV |
af6c647e |
280 | my $farthing = FARTHING; |
281 | if ($farthing == 0.25) { |
835f860c |
282 | print "ok 8\n"; |
af6c647e |
283 | } else { |
835f860c |
284 | print "not ok 8 # $farthing\n"; |
af6c647e |
285 | } |
286 | |
6d79cad2 |
287 | # UV |
af6c647e |
288 | my $not_zero = NOT_ZERO; |
289 | if ($not_zero > 0 && $not_zero == ~0) { |
835f860c |
290 | print "ok 9\n"; |
af6c647e |
291 | } else { |
835f860c |
292 | print "not ok 9 # \$not_zero=$not_zero ~0=" . (~0) . "\n"; |
af6c647e |
293 | } |
294 | |
6d79cad2 |
295 | # Value includes a "*/" in an attempt to bust out of a C comment. |
296 | # Also tests custom cpp #if clauses |
297 | my $close = CLOSE; |
298 | if ($close eq '*/') { |
299 | print "ok 10\n"; |
300 | } else { |
301 | print "not ok 10 # \$close='$close'\n"; |
302 | } |
303 | |
304 | # Default values if macro not defined. |
305 | my $answer = ANSWER; |
306 | if ($answer == 42) { |
307 | print "ok 11\n"; |
308 | } else { |
309 | print "not ok 11 # What do you get if you multiply six by nine? '$answer'\n"; |
310 | } |
311 | |
312 | # not defined macro |
313 | my $notdef = eval { NOTDEF; }; |
314 | if (defined $notdef) { |
315 | print "not ok 12 # \$notdef='$notdef'\n"; |
316 | } elsif ($@ !~ /Your vendor has not defined ExtTest macro NOTDEF/) { |
317 | print "not ok 12 # \$@='$@'\n"; |
318 | } else { |
319 | print "ok 12\n"; |
320 | } |
321 | |
322 | # not a macro |
323 | my $notthere = eval { &ExtTest::NOTTHERE; }; |
324 | if (defined $notthere) { |
325 | print "not ok 13 # \$notthere='$notthere'\n"; |
326 | } elsif ($@ !~ /NOTTHERE is not a valid ExtTest macro/) { |
327 | chomp $@; |
328 | print "not ok 13 # \$@='$@'\n"; |
329 | } else { |
330 | print "ok 13\n"; |
331 | } |
af6c647e |
332 | |
3414cef0 |
333 | # Truth |
334 | my $yes = Yes; |
335 | if ($yes) { |
336 | print "ok 14\n"; |
337 | } else { |
338 | print "not ok 14 # $yes='\$yes'\n"; |
339 | } |
340 | |
341 | # Falsehood |
342 | my $no = No; |
343 | if (defined $no and !$no) { |
344 | print "ok 15\n"; |
345 | } else { |
346 | print "not ok 15 # \$no=" . defined ($no) ? "'$no'\n" : "undef\n"; |
347 | } |
348 | |
349 | # Undef |
350 | my $undef = Undef; |
351 | unless (defined $undef) { |
352 | print "ok 16\n"; |
353 | } else { |
354 | print "not ok 16 # \$undef='$undef'\n"; |
355 | } |
356 | |
8ac27563 |
357 | |
358 | # invalid macro (chosen to look like a mix up between No and SW) |
359 | $notdef = eval { &ExtTest::So }; |
360 | if (defined $notdef) { |
361 | print "not ok 17 # \$notdef='$notdef'\n"; |
362 | } elsif ($@ !~ /^So is not a valid ExtTest macro/) { |
363 | print "not ok 17 # \$@='$@'\n"; |
364 | } else { |
365 | print "ok 17\n"; |
366 | } |
367 | |
368 | # invalid defined macro |
369 | $notdef = eval { &ExtTest::EW }; |
370 | if (defined $notdef) { |
371 | print "not ok 18 # \$notdef='$notdef'\n"; |
372 | } elsif ($@ !~ /^EW is not a valid ExtTest macro/) { |
373 | print "not ok 18 # \$@='$@'\n"; |
374 | } else { |
375 | print "ok 18\n"; |
376 | } |
377 | |
378 | my %compass = ( |
379 | EOT |
380 | |
381 | while (my ($point, $bearing) = each %compass) { |
d7f97632 |
382 | print FH "'$point' => $bearing, " |
8ac27563 |
383 | } |
384 | |
385 | print FH <<'EOT'; |
386 | |
387 | ); |
388 | |
389 | my $fail; |
390 | while (my ($point, $bearing) = each %compass) { |
391 | my $val = eval $point; |
392 | if ($@) { |
393 | print "# $point: \$@='$@'\n"; |
394 | $fail = 1; |
395 | } elsif (!defined $bearing) { |
396 | print "# $point: \$val=undef\n"; |
397 | $fail = 1; |
398 | } elsif ($val != $bearing) { |
399 | print "# $point: \$val=$val, not $bearing\n"; |
400 | $fail = 1; |
401 | } |
402 | } |
403 | if ($fail) { |
404 | print "not ok 19\n"; |
405 | } else { |
406 | print "ok 19\n"; |
407 | } |
408 | |
af6c647e |
409 | EOT |
410 | |
cea00dc5 |
411 | print FH <<"EOT"; |
412 | my \$rfc1149 = RFC1149; |
413 | if (\$rfc1149 ne "$parent_rfc1149") { |
414 | print "not ok 20 # '\$rfc1149' ne '$parent_rfc1149'\n"; |
415 | } else { |
416 | print "ok 20\n"; |
417 | } |
418 | |
419 | if (\$rfc1149 != 1149) { |
420 | printf "not ok 21 # %d != 1149\n", \$rfc1149; |
421 | } else { |
422 | print "ok 21\n"; |
423 | } |
72f7b9a1 |
424 | |
425 | EOT |
426 | |
427 | print FH <<'EOT'; |
428 | # test macro=>1 |
429 | my $open = OPEN; |
430 | if ($open eq '/*') { |
431 | print "ok 22\n"; |
432 | } else { |
433 | print "not ok 22 # \$open='$open'\n"; |
434 | } |
cea00dc5 |
435 | EOT |
6557ab03 |
436 | |
4f2c4fd8 |
437 | if ($do_utf_tests) { |
438 | # Do this in 7 bit in case someone is testing with some settings that cause |
439 | # 8 bit files incapable of storing this character. |
440 | my @values |
441 | = map {"'" . join (",", unpack "U*", $_ . pack "U*") . "'"} |
442 | ($pound, $inf, $pound_bytes, $pound_utf8); |
443 | # Values is a list of strings, such as ('194,163,49', '163,49') |
6557ab03 |
444 | |
4f2c4fd8 |
445 | print FH <<'EOT'; |
6557ab03 |
446 | |
4f2c4fd8 |
447 | # I can see that this child test program might be about to use parts of |
448 | # Test::Builder |
6557ab03 |
449 | |
4f2c4fd8 |
450 | my $test = 23; |
451 | my ($pound, $inf, $pound_bytes, $pound_utf8) = map {eval "pack 'U*', $_"} |
6557ab03 |
452 | EOT |
453 | |
4f2c4fd8 |
454 | print FH join ",", @values; |
6557ab03 |
455 | |
4f2c4fd8 |
456 | print FH << 'EOT'; |
6557ab03 |
457 | ; |
458 | |
459 | foreach (["perl", "rules", "rules"], |
460 | ["/*", "OPEN", "OPEN"], |
461 | ["*/", "CLOSE", "CLOSE"], |
462 | [$pound, 'Sterling', []], |
463 | [$inf, 'Infinity', []], |
464 | [$pound_utf8, '1 Pound', '1 Pound (as bytes)'], |
465 | [$pound_bytes, '1 Pound (as bytes)', []], |
466 | ) { |
467 | # Flag an expected error with a reference for the expect string. |
468 | my ($string, $expect, $expect_bytes) = @$_; |
469 | (my $name = $string) =~ s/([^ -~])/sprintf '\x{%X}', ord $1/ges; |
470 | print "# \"$name\" => \'$expect\'\n"; |
471 | # Try to force this to be bytes if possible. |
4f2c4fd8 |
472 | if ($better_than_56) { |
473 | utf8::downgrade ($string, 1); |
474 | } else { |
475 | if ($string =~ tr/0-\377// == length $string) { |
476 | # No chars outside range 0-255 |
477 | $string = pack 'C*', unpack 'U*', ($string . pack 'U*'); |
478 | } |
479 | } |
6557ab03 |
480 | EOT |
481 | |
4f2c4fd8 |
482 | print FH "my (\$error, \$got) = ${package}::constant (\$string);\n"; |
6557ab03 |
483 | |
4f2c4fd8 |
484 | print FH <<'EOT'; |
6557ab03 |
485 | if ($error or $got ne $expect) { |
486 | print "not ok $test # error '$error', got '$got'\n"; |
487 | } else { |
488 | print "ok $test\n"; |
489 | } |
490 | $test++; |
491 | print "# Now upgrade '$name' to utf8\n"; |
4f2c4fd8 |
492 | if ($better_than_56) { |
493 | utf8::upgrade ($string); |
494 | } else { |
495 | $string = pack ('U*') . $string; |
496 | } |
6557ab03 |
497 | EOT |
498 | |
4f2c4fd8 |
499 | print FH "my (\$error, \$got) = ${package}::constant (\$string);\n"; |
6557ab03 |
500 | |
4f2c4fd8 |
501 | print FH <<'EOT'; |
6557ab03 |
502 | if ($error or $got ne $expect) { |
503 | print "not ok $test # error '$error', got '$got'\n"; |
504 | } else { |
505 | print "ok $test\n"; |
506 | } |
507 | $test++; |
508 | if (defined $expect_bytes) { |
509 | print "# And now with the utf8 byte sequence for name\n"; |
510 | # Try the encoded bytes. |
4f2c4fd8 |
511 | if ($better_than_56) { |
512 | utf8::encode ($string); |
513 | } else { |
514 | $string = pack 'C*', unpack 'C*', $string . pack "U*"; |
515 | } |
6557ab03 |
516 | EOT |
517 | |
4f2c4fd8 |
518 | print FH "my (\$error, \$got) = ${package}::constant (\$string);\n"; |
6557ab03 |
519 | |
4f2c4fd8 |
520 | print FH <<'EOT'; |
6557ab03 |
521 | if (ref $expect_bytes) { |
522 | # Error expected. |
523 | if ($error) { |
524 | print "ok $test # error='$error' (as expected)\n"; |
525 | } else { |
526 | print "not ok $test # expected error, got no error and '$got'\n"; |
527 | } |
528 | } elsif ($got ne $expect_bytes) { |
529 | print "not ok $test # error '$error', expect '$expect_bytes', got '$got'\n"; |
530 | } else { |
531 | print "ok $test\n"; |
532 | } |
533 | $test++; |
534 | } |
535 | } |
536 | EOT |
4f2c4fd8 |
537 | } else { |
538 | # Don't utf tests; |
539 | print FH <<'EOT'; |
540 | print "ok $_ # Skipped on non Unicode perl\n" foreach 23..43; |
541 | EOT |
542 | } |
6557ab03 |
543 | |
94b1a389 |
544 | close FH or die "close $testpl: $!\n"; |
af6c647e |
545 | |
6557ab03 |
546 | # This is where the test numbers carry on after the test number above are |
547 | # relayed |
548 | my $test = 44; |
549 | |
835f860c |
550 | ################ Makefile.PL |
6d79cad2 |
551 | # We really need a Makefile.PL because make test for a no dynamic linking perl |
552 | # will run Makefile.PL again as part of the "make perl" target. |
4f2c4fd8 |
553 | my $makefilePL = File::Spec->catdir($dir, "Makefile.PL"); |
0ddb8edc |
554 | push @files, "Makefile.PL"; |
94b1a389 |
555 | open FH, ">$makefilePL" or die "open >$makefilePL: $!\n"; |
835f860c |
556 | print FH <<"EOT"; |
6d79cad2 |
557 | #!$perl -w |
835f860c |
558 | use ExtUtils::MakeMaker; |
559 | WriteMakefile( |
560 | 'NAME' => "$package", |
561 | 'VERSION_FROM' => "$package.pm", # finds \$VERSION |
562 | (\$] >= 5.005 ? |
563 | (#ABSTRACT_FROM => "$package.pm", # XXX add this |
564 | AUTHOR => "$0") : ()) |
565 | ); |
566 | EOT |
567 | |
94b1a389 |
568 | close FH or die "close $makefilePL: $!\n"; |
af6c647e |
569 | |
ccc70a53 |
570 | ################ MANIFEST |
571 | # We really need a MANIFEST because make distclean checks it. |
4f2c4fd8 |
572 | my $manifest = File::Spec->catdir($dir, "MANIFEST"); |
ccc70a53 |
573 | push @files, "MANIFEST"; |
574 | open FH, ">$manifest" or die "open >$manifest: $!\n"; |
575 | print FH "$_\n" foreach @files; |
576 | close FH or die "close $manifest: $!\n"; |
577 | |
af6c647e |
578 | chdir $dir or die $!; push @INC, '../../lib'; |
579 | END {chdir ".." or warn $!}; |
580 | |
4f2c4fd8 |
581 | my $core = $ENV{PERL_CORE} ? ' PERL_CORE=1' : ''; |
582 | my @perlout = `$runperl Makefile.PL $core`; |
835f860c |
583 | if ($?) { |
584 | print "not ok 1 # $runperl Makefile.PL failed: $?\n"; |
585 | print "# $_" foreach @perlout; |
586 | exit($?); |
587 | } else { |
588 | print "ok 1\n"; |
589 | } |
590 | |
591 | |
24874030 |
592 | my $makefile = ($^O eq 'VMS' ? 'descrip' : 'Makefile'); |
593 | my $makefile_ext = ($^O eq 'VMS' ? '.mms' : ''); |
594 | if (-f "$makefile$makefile_ext") { |
835f860c |
595 | print "ok 2\n"; |
af6c647e |
596 | } else { |
835f860c |
597 | print "not ok 2\n"; |
af6c647e |
598 | } |
ccc70a53 |
599 | |
600 | # Renamed by make clean |
601 | my $makefile_rename = $makefile . ($^O eq 'VMS' ? '.mms' : '.old'); |
af6c647e |
602 | |
603 | my $make = $Config{make}; |
94b1a389 |
604 | |
af6c647e |
605 | $make = $ENV{MAKE} if exists $ENV{MAKE}; |
94b1a389 |
606 | |
91e5ac1f |
607 | if ($^O eq 'MSWin32' && $make eq 'nmake') { $make .= " -nologo"; } |
76f26e35 |
608 | |
535acd0f |
609 | my @makeout; |
94b1a389 |
610 | |
8b2eb6ba |
611 | if ($^O eq 'VMS') { $make .= ' all'; } |
af6c647e |
612 | print "# make = '$make'\n"; |
535acd0f |
613 | @makeout = `$make`; |
94b1a389 |
614 | if ($?) { |
835f860c |
615 | print "not ok 3 # $make failed: $?\n"; |
535acd0f |
616 | print "# $_" foreach @makeout; |
94b1a389 |
617 | exit($?); |
af6c647e |
618 | } else { |
835f860c |
619 | print "ok 3\n"; |
620 | } |
621 | |
8b2eb6ba |
622 | if ($^O eq 'VMS') { $make =~ s{ all}{}; } |
623 | |
835f860c |
624 | if ($Config{usedl}) { |
625 | print "ok 4\n"; |
626 | } else { |
835f860c |
627 | my $makeperl = "$make perl"; |
628 | print "# make = '$makeperl'\n"; |
535acd0f |
629 | @makeout = `$makeperl`; |
835f860c |
630 | if ($?) { |
631 | print "not ok 4 # $makeperl failed: $?\n"; |
535acd0f |
632 | print "# $_" foreach @makeout; |
835f860c |
633 | exit($?); |
634 | } else { |
635 | print "ok 4\n"; |
636 | } |
af6c647e |
637 | } |
638 | |
0ddb8edc |
639 | my $maketest = "$make test"; |
640 | print "# make = '$maketest'\n"; |
3414cef0 |
641 | |
535acd0f |
642 | @makeout = `$maketest`; |
94b1a389 |
643 | |
535acd0f |
644 | if (open OUTPUT, "<$output") { |
645 | print while <OUTPUT>; |
646 | close OUTPUT or print "# Close $output failed: $!\n"; |
647 | } else { |
648 | # Harness will report missing test results at this point. |
649 | print "# Open <$output failed: $!\n"; |
650 | } |
835f860c |
651 | |
3414cef0 |
652 | if ($?) { |
653 | print "not ok $test # $maketest failed: $?\n"; |
535acd0f |
654 | print "# $_" foreach @makeout; |
3414cef0 |
655 | } else { |
39234879 |
656 | print "ok $test - maketest\n"; |
6d79cad2 |
657 | } |
658 | $test++; |
659 | |
39234879 |
660 | |
661 | # -x is busted on Win32 < 5.6.1, so we emulate it. |
662 | my $regen; |
663 | if( $^O eq 'MSWin32' && $] <= 5.006001 ) { |
664 | open(REGENTMP, ">regentmp") or die $!; |
665 | open(XS, "$package.xs") or die $!; |
666 | my $saw_shebang; |
667 | while(<XS>) { |
668 | $saw_shebang++ if /^#!.*/i ; |
669 | print REGENTMP $_ if $saw_shebang; |
670 | } |
671 | close XS; close REGENTMP; |
672 | $regen = `$runperl regentmp`; |
673 | unlink 'regentmp'; |
674 | } |
675 | else { |
676 | $regen = `$runperl -x $package.xs`; |
677 | } |
6d79cad2 |
678 | if ($?) { |
39234879 |
679 | print "not ok $test # $runperl -x $package.xs failed: $?\n"; |
6d79cad2 |
680 | } else { |
39234879 |
681 | print "ok $test - regen\n"; |
af6c647e |
682 | } |
6d79cad2 |
683 | $test++; |
684 | |
685 | my $expect = $constant_types . $C_constant . |
686 | "\n#### XS Section:\n" . $XS_constant; |
687 | |
688 | if ($expect eq $regen) { |
39234879 |
689 | print "ok $test - regen worked\n"; |
6d79cad2 |
690 | } else { |
39234879 |
691 | print "not ok $test - regen worked\n"; |
6d79cad2 |
692 | # open FOO, ">expect"; print FOO $expect; |
693 | # open FOO, ">regen"; print FOO $regen; close FOO; |
694 | } |
695 | $test++; |
0ddb8edc |
696 | |
697 | my $makeclean = "$make clean"; |
698 | print "# make = '$makeclean'\n"; |
535acd0f |
699 | @makeout = `$makeclean`; |
0ddb8edc |
700 | if ($?) { |
6d79cad2 |
701 | print "not ok $test # $make failed: $?\n"; |
535acd0f |
702 | print "# $_" foreach @makeout; |
0ddb8edc |
703 | } else { |
6d79cad2 |
704 | print "ok $test\n"; |
0ddb8edc |
705 | } |
6d79cad2 |
706 | $test++; |
0ddb8edc |
707 | |
ccc70a53 |
708 | sub check_for_bonus_files { |
709 | my $dir = shift; |
67dff657 |
710 | my %expect = map {($^O eq 'VMS' ? lc($_) : $_), 1} @_; |
ccc70a53 |
711 | |
712 | my $fail; |
713 | opendir DIR, $dir or die "opendir '$dir': $!"; |
714 | while (defined (my $entry = readdir DIR)) { |
67dff657 |
715 | $entry =~ s/\.$// if $^O eq 'VMS'; # delete trailing dot that indicates no extension |
ccc70a53 |
716 | next if $expect{$entry}; |
717 | print "# Extra file '$entry'\n"; |
718 | $fail = 1; |
6557ab03 |
719 | } |
0ddb8edc |
720 | |
ccc70a53 |
721 | closedir DIR or warn "closedir '.': $!"; |
722 | if ($fail) { |
723 | print "not ok $test\n"; |
724 | } else { |
725 | print "ok $test\n"; |
726 | } |
727 | $test++; |
0ddb8edc |
728 | } |
ccc70a53 |
729 | |
730 | check_for_bonus_files ('.', @files, $output, $makefile_rename, '.', '..'); |
731 | |
732 | rename $makefile_rename, $makefile |
733 | or die "Can't rename '$makefile_rename' to '$makefile': $!"; |
734 | |
735 | unlink $output or warn "Can't unlink '$output': $!"; |
736 | |
737 | # Need to make distclean to remove ../../lib/ExtTest.pm |
738 | my $makedistclean = "$make distclean"; |
739 | print "# make = '$makedistclean'\n"; |
740 | @makeout = `$makedistclean`; |
741 | if ($?) { |
742 | print "not ok $test # $make failed: $?\n"; |
743 | print "# $_" foreach @makeout; |
0ddb8edc |
744 | } else { |
6d79cad2 |
745 | print "ok $test\n"; |
0ddb8edc |
746 | } |
ccc70a53 |
747 | $test++; |
748 | |
749 | check_for_bonus_files ('.', @files, '.', '..'); |
750 | |
751 | unless ($keep_files) { |
752 | foreach (@files) { |
753 | unlink $_ or warn "unlink $_: $!"; |
754 | } |
755 | } |
756 | |
757 | check_for_bonus_files ('.', '.', '..'); |
4f2c4fd8 |
758 | |
759 | # This was causing an assertion failure (a C<confess>ion) |
760 | C_constant ($package, undef, undef, undef, undef, undef, chr 255); |
761 | |
762 | print "ok $test\n"; $test++; |