Upgrade to Devel::PPPort 3.11_05
[p5sagit/p5-mst-13.2.git] / ext / Devel / PPPort / t / ppphtest.t
1 ################################################################################
2 #
3 #            !!!!!   Do NOT edit this file directly!   !!!!!
4 #
5 #            Edit mktests.PL and/or parts/inc/ppphtest instead.
6 #
7 #  This file was automatically generated from the definition files in the
8 #  parts/inc/ subdirectory by mktests.PL. To learn more about how all this
9 #  works, please read the F<HACKERS> file that came with this distribution.
10 #
11 ################################################################################
12
13 BEGIN {
14   if ($ENV{'PERL_CORE'}) {
15     chdir 't' if -d 't';
16     @INC = ('../lib', '../ext/Devel/PPPort/t') if -d '../lib' && -d '../ext';
17     require Config; import Config;
18     use vars '%Config';
19     if (" $Config{'extensions'} " !~ m[ Devel/PPPort ]) {
20       print "1..0 # Skip -- Perl configured without Devel::PPPort module\n";
21       exit 0;
22     }
23   }
24   else {
25     unshift @INC, 't';
26   }
27
28   sub load {
29     eval "use Test";
30     require 'testutil.pl' if $@;
31   }
32
33   if (225) {
34     load();
35     plan(tests => 225);
36   }
37 }
38
39 use Devel::PPPort;
40 use strict;
41 $^W = 1;
42
43 package Devel::PPPort;
44 use vars '@ISA';
45 require DynaLoader;
46 @ISA = qw(DynaLoader);
47 bootstrap Devel::PPPort;
48
49 package main;
50
51 BEGIN {
52   if ($ENV{'SKIP_SLOW_TESTS'}) {
53     for (1 .. 225) {
54       skip("skip: SKIP_SLOW_TESTS", 0);
55     }
56     exit 0;
57   }
58 }
59
60 use File::Path qw/rmtree mkpath/;
61 use Config;
62
63 my $tmp = 'ppptmp';
64 my $inc = '';
65 my $isVMS = $^O eq 'VMS';
66 my $isMAC = $^O eq 'MacOS';
67 my $perl = find_perl();
68
69 rmtree($tmp) if -d $tmp;
70 mkpath($tmp) or die "mkpath $tmp: $!\n";
71 chdir($tmp) or die "chdir $tmp: $!\n";
72
73 if ($ENV{'PERL_CORE'}) {
74   if (-d '../../lib') {
75     if ($isVMS) {
76       $inc = '"-I../../lib"';
77     }
78     elsif ($isMAC) {
79       $inc = '-I:::lib';
80     }
81     else {
82       $inc = '-I../../lib';
83     }
84     unshift @INC, '../../lib';
85   }
86 }
87 if ($perl =~ m!^\./!) {
88   $perl = ".$perl";
89 }
90
91 END {
92   chdir('..') if !-d $tmp && -d "../$tmp";
93   rmtree($tmp) if -d $tmp;
94 }
95
96 ok(&Devel::PPPort::WriteFile("ppport.h"));
97
98 sub comment
99 {
100   my $c = shift;
101   $c =~ s/^/# | /mg;
102   $c .= "\n" unless $c =~ /[\r\n]$/;
103   print $c;
104 }
105
106 sub ppport
107 {
108   my @args = ('ppport.h', @_);
109   unshift @args, $inc if $inc;
110   my $run = $perl =~ m/\s/ ? qq("$perl") : $perl;
111   $run .= ' -MMac::err=unix' if $isMAC;
112   for (@args) {
113     $_ = qq("$_") if $isVMS && /^[^"]/;
114     $run .= " $_";
115   }
116   print "# *** running $run ***\n";
117   $run .= ' 2>&1' unless $isMAC;
118   my @out = `$run`;
119   my $out = join '', @out;
120   comment($out);
121   return wantarray ? @out : $out;
122 }
123
124 sub matches
125 {
126   my($str, $re, $mod) = @_;
127   my @n;
128   eval "\@n = \$str =~ /$re/g$mod;";
129   if ($@) {
130     my $err = $@;
131     $err =~ s/^/# *** /mg;
132     print "# *** ERROR ***\n$err\n";
133   }
134   return $@ ? -42 : scalar @n;
135 }
136
137 sub eq_files
138 {
139   my($f1, $f2) = @_;
140   return 0 unless -e $f1 && -e $f2;
141   local *F;
142   for ($f1, $f2) {
143     print "# File: $_\n";
144     unless (open F, $_) {
145       print "# couldn't open $_: $!\n";
146       return 0;
147     }
148     $_ = do { local $/; <F> };
149     close F;
150     comment($_);
151   }
152   return $f1 eq $f2;
153 }
154
155 my @tests;
156
157 for (split /\s*={70,}\s*/, do { local $/; <DATA> }) {
158   s/^\s+//; s/\s+$//;
159   my($c, %f);
160   ($c, @f{m/-{20,}\s+(\S+)\s+-{20,}/g}) = split /\s*-{20,}\s+\S+\s+-{20,}\s*/;
161   push @tests, { code => $c, files => \%f };
162 }
163
164 my $t;
165 for $t (@tests) {
166   print "#\n", ('# ', '-'x70, "\n")x3, "#\n";
167   my $f;
168   for $f (keys %{$t->{files}}) {
169     my @f = split /\//, $f;
170     if (@f > 1) {
171       pop @f;
172       my $path = join '/', @f;
173       mkpath($path) or die "mkpath('$path'): $!\n";
174     }
175     my $txt = $t->{files}{$f};
176     local *F;
177     open F, ">$f" or die "open $f: $!\n";
178     print F "$txt\n";
179     close F;
180     $txt =~ s/^/# | /mg;
181     print "# *** writing $f ***\n$txt\n";
182   }
183
184   my $code = $t->{code};
185   $code =~ s/^/# | /mg;
186
187   print "# *** evaluating test code ***\n$code\n";
188
189   eval $t->{code};
190   if ($@) {
191     my $err = $@;
192     $err =~ s/^/# *** /mg;
193     print "# *** ERROR ***\n$err\n";
194   }
195   ok($@, '');
196
197   for (keys %{$t->{files}}) {
198     unlink $_ or die "unlink('$_'): $!\n";
199   }
200 }
201
202 sub find_perl
203 {
204   my $perl = $^X;
205
206   return $perl if $isVMS;
207
208   my $exe = $Config{'_exe'} || '';
209
210   if ($perl =~ /^perl\Q$exe\E$/i) {
211     $perl = "perl$exe";
212     eval "require File::Spec";
213     if ($@) {
214       $perl = "./$perl";
215     } else {
216       $perl = File::Spec->catfile(File::Spec->curdir(), $perl);
217     }
218   }
219
220   if ($perl !~ /\Q$exe\E$/i) {
221     $perl .= $exe;
222   }
223
224   warn "find_perl: cannot find $perl from $^X" unless -f $perl;
225
226   return $perl;
227 }
228
229 __DATA__
230
231 my $o = ppport(qw(--help));
232 ok($o =~ /^Usage:.*ppport\.h/m);
233 ok($o =~ /--help/m);
234
235 $o = ppport(qw(--version));
236 ok($o =~ /^This is.*ppport.*\d+\.\d+(?:_?\d+)?\.$/);
237
238 $o = ppport(qw(--nochanges));
239 ok($o =~ /^Scanning.*test\.xs/mi);
240 ok($o =~ /Analyzing.*test\.xs/mi);
241 ok(matches($o, '^Scanning', 'm'), 1);
242 ok(matches($o, 'Analyzing', 'm'), 1);
243 ok($o =~ /Uses Perl_newSViv instead of newSViv/);
244
245 $o = ppport(qw(--quiet --nochanges));
246 ok($o =~ /^\s*$/);
247
248 ---------------------------- test.xs ------------------------------------------
249
250 Perl_newSViv();
251
252 ===============================================================================
253
254 # check if C and C++ comments are filtered correctly
255
256 my $o = ppport(qw(--copy=a));
257 ok($o =~ /^Scanning.*MyExt\.xs/mi);
258 ok($o =~ /Analyzing.*MyExt\.xs/mi);
259 ok(matches($o, '^Scanning', 'm'), 1);
260 ok($o =~ /^Needs to include.*ppport\.h/m);
261 ok($o !~ /^Uses grok_bin/m);
262 ok($o !~ /^Uses newSVpv/m);
263 ok($o =~ /Uses 1 C\+\+ style comment/m);
264 ok(eq_files('MyExt.xsa', 'MyExt.ra'));
265
266 # check if C++ are left untouched with --cplusplus
267
268 $o = ppport(qw(--copy=b --cplusplus));
269 ok($o =~ /^Scanning.*MyExt\.xs/mi);
270 ok($o =~ /Analyzing.*MyExt\.xs/mi);
271 ok(matches($o, '^Scanning', 'm'), 1);
272 ok($o =~ /^Needs to include.*ppport\.h/m);
273 ok($o !~ /^Uses grok_bin/m);
274 ok($o !~ /^Uses newSVpv/m);
275 ok($o !~ /Uses \d+ C\+\+ style comment/m);
276 ok(eq_files('MyExt.xsb', 'MyExt.rb'));
277
278 unlink qw(MyExt.xsa MyExt.xsb);
279
280 ---------------------------- MyExt.xs -----------------------------------------
281
282 newSVuv();
283     // newSVpv();
284   XPUSHs(foo);
285 /* grok_bin(); */
286
287 ---------------------------- MyExt.ra -----------------------------------------
288
289 #include "ppport.h"
290 newSVuv();
291     /* newSVpv(); */
292   XPUSHs(foo);
293 /* grok_bin(); */
294
295 ---------------------------- MyExt.rb -----------------------------------------
296
297 #include "ppport.h"
298 newSVuv();
299     // newSVpv();
300   XPUSHs(foo);
301 /* grok_bin(); */
302
303 ===============================================================================
304
305 my $o = ppport(qw(--nochanges file1.xs));
306 ok($o =~ /^Scanning.*file1\.xs/mi);
307 ok($o =~ /Analyzing.*file1\.xs/mi);
308 ok($o !~ /^Scanning.*file2\.xs/mi);
309 ok($o =~ /^Uses newCONSTSUB/m);
310 ok($o =~ /^Uses SvPV_nolen.*depends.*sv_2pv_flags/m);
311 ok($o =~ /WARNING: PL_expect/m);
312 ok($o =~ /hint for newCONSTSUB/m);
313 ok($o =~ /^Looks good/m);
314
315 $o = ppport(qw(--nochanges --nohints file1.xs));
316 ok($o =~ /^Scanning.*file1\.xs/mi);
317 ok($o =~ /Analyzing.*file1\.xs/mi);
318 ok($o !~ /^Scanning.*file2\.xs/mi);
319 ok($o =~ /^Uses newCONSTSUB/m);
320 ok($o =~ /^Uses SvPV_nolen.*depends.*sv_2pv_flags/m);
321 ok($o =~ /WARNING: PL_expect/m);
322 ok($o !~ /hint for newCONSTSUB/m);
323 ok($o =~ /^Looks good/m);
324
325 $o = ppport(qw(--nochanges --nohints --nodiag file1.xs));
326 ok($o =~ /^Scanning.*file1\.xs/mi);
327 ok($o =~ /Analyzing.*file1\.xs/mi);
328 ok($o !~ /^Scanning.*file2\.xs/mi);
329 ok($o !~ /^Uses newCONSTSUB/m);
330 ok($o !~ /^Uses SvPV_nolen/m);
331 ok($o =~ /WARNING: PL_expect/m);
332 ok($o !~ /hint for newCONSTSUB/m);
333 ok($o =~ /^Looks good/m);
334
335 $o = ppport(qw(--nochanges --quiet file1.xs));
336 ok($o =~ /^\s*$/);
337
338 $o = ppport(qw(--nochanges file2.xs));
339 ok($o =~ /^Scanning.*file2\.xs/mi);
340 ok($o =~ /Analyzing.*file2\.xs/mi);
341 ok($o !~ /^Scanning.*file1\.xs/mi);
342 ok($o =~ /^Uses mXPUSHp/m);
343 ok($o =~ /^Needs to include.*ppport\.h/m);
344 ok($o !~ /^Looks good/m);
345 ok($o =~ /^1 potentially required change detected/m);
346
347 $o = ppport(qw(--nochanges --nohints file2.xs));
348 ok($o =~ /^Scanning.*file2\.xs/mi);
349 ok($o =~ /Analyzing.*file2\.xs/mi);
350 ok($o !~ /^Scanning.*file1\.xs/mi);
351 ok($o =~ /^Uses mXPUSHp/m);
352 ok($o =~ /^Needs to include.*ppport\.h/m);
353 ok($o !~ /^Looks good/m);
354 ok($o =~ /^1 potentially required change detected/m);
355
356 $o = ppport(qw(--nochanges --nohints --nodiag file2.xs));
357 ok($o =~ /^Scanning.*file2\.xs/mi);
358 ok($o =~ /Analyzing.*file2\.xs/mi);
359 ok($o !~ /^Scanning.*file1\.xs/mi);
360 ok($o !~ /^Uses mXPUSHp/m);
361 ok($o !~ /^Needs to include.*ppport\.h/m);
362 ok($o !~ /^Looks good/m);
363 ok($o =~ /^1 potentially required change detected/m);
364
365 $o = ppport(qw(--nochanges --quiet file2.xs));
366 ok($o =~ /^\s*$/);
367
368 ---------------------------- file1.xs -----------------------------------------
369
370 #define NEED_newCONSTSUB
371 #define NEED_sv_2pv_flags
372 #include "ppport.h"
373
374 newCONSTSUB();
375 SvPV_nolen();
376 PL_expect = 0;
377
378 ---------------------------- file2.xs -----------------------------------------
379
380 mXPUSHp(foo);
381
382 ===============================================================================
383
384 my $o = ppport(qw(--nochanges));
385 ok($o =~ /^Scanning.*FooBar\.xs/mi);
386 ok($o =~ /Analyzing.*FooBar\.xs/mi);
387 ok(matches($o, '^Scanning', 'm'), 1);
388 ok($o !~ /^Looks good/m);
389 ok($o =~ /^Uses grok_bin/m);
390
391 ---------------------------- FooBar.xs ----------------------------------------
392
393 newSViv();
394 XPUSHs(foo);
395 grok_bin();
396
397 ===============================================================================
398
399 my $o = ppport(qw(--nochanges));
400 ok($o =~ /^Scanning.*First\.xs/mi);
401 ok($o =~ /Analyzing.*First\.xs/mi);
402 ok($o =~ /^Scanning.*second\.h/mi);
403 ok($o =~ /Analyzing.*second\.h/mi);
404 ok($o =~ /^Scanning.*sub.*third\.c/mi);
405 ok($o =~ /Analyzing.*sub.*third\.c/mi);
406 ok($o !~ /^Scanning.*foobar/mi);
407 ok(matches($o, '^Scanning', 'm'), 3);
408
409 ---------------------------- First.xs -----------------------------------------
410
411 one
412
413 ---------------------------- foobar.xyz ---------------------------------------
414
415 two
416
417 ---------------------------- second.h -----------------------------------------
418
419 three
420
421 ---------------------------- sub/third.c --------------------------------------
422
423 four
424
425 ===============================================================================
426
427 my $o = ppport(qw(--nochanges));
428 ok($o =~ /Possibly wrong #define NEED_foobar in.*test.xs/i);
429
430 ---------------------------- test.xs ------------------------------------------
431
432 #define NEED_foobar
433
434 ===============================================================================
435
436 # And now some complex "real-world" example
437
438 my $o = ppport(qw(--copy=f));
439 for (qw(main.xs mod1.c mod2.c mod3.c mod4.c mod5.c)) {
440   ok($o =~ /^Scanning.*\Q$_\E/mi);
441   ok($o =~ /Analyzing.*\Q$_\E/i);
442 }
443 ok(matches($o, '^Scanning', 'm'), 6);
444
445 ok(matches($o, '^Writing copy of', 'm'), 5);
446 ok(!-e "mod5.cf");
447
448 for (qw(main.xs mod1.c mod2.c mod3.c mod4.c)) {
449   ok($o =~ /^Writing copy of.*\Q$_\E.*with changes/mi);
450   ok(-e "${_}f");
451   ok(eq_files("${_}f", "${_}r"));
452   unlink "${_}f";
453 }
454
455 ---------------------------- main.xs ------------------------------------------
456
457 #include "EXTERN.h"
458 #include "perl.h"
459 #include "XSUB.h"
460
461 #define NEED_newCONSTSUB
462 #define NEED_grok_hex_GLOBAL
463 #include "ppport.h"
464
465 newCONSTSUB();
466 grok_hex();
467 Perl_grok_bin(aTHX_ foo, bar);
468
469 /* some comment */
470
471 perl_eval_pv();
472 grok_bin();
473 Perl_grok_bin(bar, sv_no);
474
475 ---------------------------- mod1.c -------------------------------------------
476
477 #include "EXTERN.h"
478 #include "perl.h"
479 #include "XSUB.h"
480
481 #define NEED_grok_bin_GLOBAL
482 #define NEED_newCONSTSUB
483 #include "ppport.h"
484
485 newCONSTSUB();
486 grok_bin();
487 {
488   Perl_croak ("foo");
489   Perl_sv_catpvf();  /* I know it's wrong ;-) */
490 }
491
492 ---------------------------- mod2.c -------------------------------------------
493
494 #include "EXTERN.h"
495 #include "perl.h"
496 #include "XSUB.h"
497
498 #define NEED_eval_pv
499 #include "ppport.h"
500
501 newSViv();
502
503 /*
504    eval_pv();
505 */
506
507 ---------------------------- mod3.c -------------------------------------------
508
509 #include "EXTERN.h"
510 #include "perl.h"
511 #include "XSUB.h"
512
513 grok_oct();
514 eval_pv();
515
516 ---------------------------- mod4.c -------------------------------------------
517
518 #include "EXTERN.h"
519 #include "perl.h"
520 #include "XSUB.h"
521
522 START_MY_CXT;
523
524 ---------------------------- mod5.c -------------------------------------------
525
526 #include "EXTERN.h"
527 #include "perl.h"
528 #include "XSUB.h"
529
530 #include "ppport.h"
531 call_pv();
532
533 ---------------------------- main.xsr -----------------------------------------
534
535 #include "EXTERN.h"
536 #include "perl.h"
537 #include "XSUB.h"
538
539 #define NEED_eval_pv_GLOBAL
540 #define NEED_grok_hex
541 #define NEED_newCONSTSUB_GLOBAL
542 #include "ppport.h"
543
544 newCONSTSUB();
545 grok_hex();
546 grok_bin(foo, bar);
547
548 /* some comment */
549
550 eval_pv();
551 grok_bin();
552 grok_bin(bar, PL_sv_no);
553
554 ---------------------------- mod1.cr ------------------------------------------
555
556 #include "EXTERN.h"
557 #include "perl.h"
558 #include "XSUB.h"
559
560 #define NEED_grok_bin_GLOBAL
561 #include "ppport.h"
562
563 newCONSTSUB();
564 grok_bin();
565 {
566   Perl_croak (aTHX_ "foo");
567   Perl_sv_catpvf(aTHX);  /* I know it's wrong ;-) */
568 }
569
570 ---------------------------- mod2.cr ------------------------------------------
571
572 #include "EXTERN.h"
573 #include "perl.h"
574 #include "XSUB.h"
575
576
577 newSViv();
578
579 /*
580    eval_pv();
581 */
582
583 ---------------------------- mod3.cr ------------------------------------------
584
585 #include "EXTERN.h"
586 #include "perl.h"
587 #include "XSUB.h"
588 #define NEED_grok_oct
589 #include "ppport.h"
590
591 grok_oct();
592 eval_pv();
593
594 ---------------------------- mod4.cr ------------------------------------------
595
596 #include "EXTERN.h"
597 #include "perl.h"
598 #include "XSUB.h"
599 #include "ppport.h"
600
601 START_MY_CXT;
602
603 ===============================================================================
604
605 my $o = ppport(qw(--nochanges));
606 ok($o =~ /Uses grok_hex/m);
607 ok($o !~ /Looks good/m);
608
609 $o = ppport(qw(--nochanges --compat-version=5.8.0));
610 ok($o !~ /Uses grok_hex/m);
611 ok($o =~ /Looks good/m);
612
613 ---------------------------- FooBar.xs ----------------------------------------
614
615 grok_hex();
616
617 ===============================================================================
618
619 my $o = ppport(qw(--nochanges));
620 ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
621
622 $o = ppport(qw(--nochanges --compat-version=5.5.3));
623 ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
624
625 $o = ppport(qw(--nochanges --compat-version=5.005_03));
626 ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
627
628 $o = ppport(qw(--nochanges --compat-version=5.6.0));
629 ok($o !~ /Uses SvPVutf8_force/m);
630
631 $o = ppport(qw(--nochanges --compat-version=5.006));
632 ok($o !~ /Uses SvPVutf8_force/m);
633
634 $o = ppport(qw(--nochanges --compat-version=5.999.999));
635 ok($o !~ /Uses SvPVutf8_force/m);
636
637 $o = ppport(qw(--nochanges --compat-version=6.0.0));
638 ok($o =~ /Only Perl 5 is supported/m);
639
640 $o = ppport(qw(--nochanges --compat-version=5.1000.999));
641 ok($o =~ /Invalid version number: 5.1000.999/m);
642
643 $o = ppport(qw(--nochanges --compat-version=5.999.1000));
644 ok($o =~ /Invalid version number: 5.999.1000/m);
645
646 ---------------------------- FooBar.xs ----------------------------------------
647
648 SvPVutf8_force();
649
650 ===============================================================================
651
652 my $o = ppport(qw(--nochanges));
653 ok($o !~ /potentially required change/);
654 ok(matches($o, '^Looks good', 'm'), 2);
655
656 ---------------------------- FooBar.xs ----------------------------------------
657
658 #define NEED_grok_numeric_radix
659 #define NEED_grok_number
660 #include "ppport.h"
661
662 GROK_NUMERIC_RADIX();
663 grok_number();
664
665 ---------------------------- foo.c --------------------------------------------
666
667 #include "ppport.h"
668
669 call_pv();
670
671 ===============================================================================
672
673 # check --api-info option
674
675 my $o = ppport(qw(--api-info=INT2PTR));
676 my %found = map {($_ => 1)} $o =~ /^===\s+(\w+)\s+===/mg;
677 ok(scalar keys %found, 1);
678 ok(exists $found{INT2PTR});
679 ok(matches($o, '^Supported at least starting from perl-5\.6\.0\.', 'm'), 1);
680 ok(matches($o, '^Support by .*ppport.* provided back to perl-5\.003\.', 'm'), 1);
681
682 $o = ppport(qw(--api-info=Zero));
683 %found = map {($_ => 1)} $o =~ /^===\s+(\w+)\s+===/mg;
684 ok(scalar keys %found, 1);
685 ok(exists $found{Zero});
686 ok(matches($o, '^No portability information available\.', 'm'), 1);
687
688 $o = ppport(qw(--api-info=/Zero/));
689 %found = map {($_ => 1)} $o =~ /^===\s+(\w+)\s+===/mg;
690 ok(scalar keys %found, 2);
691 ok(exists $found{Zero});
692 ok(exists $found{ZeroD});
693
694 ===============================================================================
695
696 # check --list-provided option
697
698 my @o = ppport(qw(--list-provided));
699 my %p;
700 my $fail = 0;
701 for (@o) {
702   my($name, $flags) = /^(\w+)(?:\s+\[(\w+(?:,\s+\w+)*)\])?$/ or $fail++;
703   exists $p{$name} and $fail++;
704   $p{$name} = defined $flags ? { map { ($_ => 1) } $flags =~ /(\w+)/g } : '';
705 }
706 ok(@o > 100);
707 ok($fail, 0);
708
709 ok(exists $p{call_sv});
710 ok(not ref $p{call_sv});
711
712 ok(exists $p{grok_bin});
713 ok(ref $p{grok_bin}, 'HASH');
714 ok(scalar keys %{$p{grok_bin}}, 2);
715 ok($p{grok_bin}{explicit});
716 ok($p{grok_bin}{depend});
717
718 ok(exists $p{gv_stashpvn});
719 ok(ref $p{gv_stashpvn}, 'HASH');
720 ok(scalar keys %{$p{gv_stashpvn}}, 2);
721 ok($p{gv_stashpvn}{depend});
722 ok($p{gv_stashpvn}{hint});
723
724 ok(exists $p{sv_catpvf_mg});
725 ok(ref $p{sv_catpvf_mg}, 'HASH');
726 ok(scalar keys %{$p{sv_catpvf_mg}}, 2);
727 ok($p{sv_catpvf_mg}{explicit});
728 ok($p{sv_catpvf_mg}{depend});
729
730 ok(exists $p{PL_signals});
731 ok(ref $p{PL_signals}, 'HASH');
732 ok(scalar keys %{$p{PL_signals}}, 1);
733 ok($p{PL_signals}{explicit});
734
735 ===============================================================================
736
737 # check --list-unsupported option
738
739 my @o = ppport(qw(--list-unsupported));
740 my %p;
741 my $fail = 0;
742 for (@o) {
743   my($name, $ver) = /^(\w+)\s*\.+\s*([\d._]+)$/ or $fail++;
744   exists $p{$name} and $fail++;
745   $p{$name} = $ver;
746 }
747 ok(@o > 100);
748 ok($fail, 0);
749
750 ok(exists $p{utf8_distance});
751 ok($p{utf8_distance}, '5.6.0');
752
753 ok(exists $p{save_generic_svref});
754 ok($p{save_generic_svref}, '5.005_03');
755
756 ===============================================================================
757
758 # check --nofilter option
759
760 my $o = ppport(qw(--nochanges));
761 ok($o =~ /^Scanning.*foo\.cpp/mi);
762 ok($o =~ /Analyzing.*foo\.cpp/mi);
763 ok(matches($o, '^Scanning', 'm'), 1);
764 ok(matches($o, 'Analyzing', 'm'), 1);
765
766 $o = ppport(qw(--nochanges foo.cpp foo.o Makefile.PL));
767 ok($o =~ /Skipping the following files \(use --nofilter to avoid this\):/m);
768 ok(matches($o, '^\|\s+foo\.o', 'mi'), 1);
769 ok(matches($o, '^\|\s+Makefile\.PL', 'mi'), 1);
770 ok($o =~ /^Scanning.*foo\.cpp/mi);
771 ok($o =~ /Analyzing.*foo\.cpp/mi);
772 ok(matches($o, '^Scanning', 'm'), 1);
773 ok(matches($o, 'Analyzing', 'm'), 1);
774
775 $o = ppport(qw(--nochanges --nofilter foo.cpp foo.o Makefile.PL));
776 ok($o =~ /^Scanning.*foo\.cpp/mi);
777 ok($o =~ /Analyzing.*foo\.cpp/mi);
778 ok($o =~ /^Scanning.*foo\.o/mi);
779 ok($o =~ /Analyzing.*foo\.o/mi);
780 ok($o =~ /^Scanning.*Makefile/mi);
781 ok($o =~ /Analyzing.*Makefile/mi);
782 ok(matches($o, '^Scanning', 'm'), 3);
783 ok(matches($o, 'Analyzing', 'm'), 3);
784
785 ---------------------------- foo.cpp ------------------------------------------
786
787 newSViv();
788
789 ---------------------------- foo.o --------------------------------------------
790
791 newSViv();
792
793 ---------------------------- Makefile.PL --------------------------------------
794
795 newSViv();
796
797 ===============================================================================
798
799 # check if explicit variables are handled propery
800
801 my $o = ppport(qw(--copy=a));
802 ok($o =~ /^Needs to include.*ppport\.h/m);
803 ok($o =~ /^Uses PL_signals/m);
804 ok($o =~ /^File needs PL_signals, adding static request/m);
805 ok(eq_files('MyExt.xsa', 'MyExt.ra'));
806
807 unlink qw(MyExt.xsa);
808
809 ---------------------------- MyExt.xs -----------------------------------------
810
811 PL_signals = 123;
812 if (PL_signals == 42)
813   foo();
814
815 ---------------------------- MyExt.ra -----------------------------------------
816
817 #define NEED_PL_signals
818 #include "ppport.h"
819 PL_signals = 123;
820 if (PL_signals == 42)
821   foo();
822
823 ===============================================================================
824
825 my $o = ppport(qw(--nochanges file.xs));
826 ok($o =~ /^Uses PL_copline/m);
827 ok($o =~ /WARNING: PL_copline/m);
828 ok($o =~ /^Uses SvUOK/m);
829 ok($o =~ /WARNING: Uses SvUOK, which may not be portable/m);
830 ok($o =~ /^Analysis completed \(2 warnings\)/m);
831 ok($o =~ /^Looks good/m);
832
833 $o = ppport(qw(--nochanges --compat-version=5.8.0 file.xs));
834 ok($o =~ /^Uses PL_copline/m);
835 ok($o =~ /WARNING: PL_copline/m);
836 ok($o !~ /WARNING: Uses SvUOK, which may not be portable/m);
837 ok($o =~ /^Analysis completed \(1 warning\)/m);
838 ok($o =~ /^Looks good/m);
839
840 ---------------------------- file.xs -----------------------------------------
841
842 #include "ppport.h"
843 SvUOK
844 PL_copline
845
846 ===============================================================================
847
848 my $o = ppport(qw(--copy=f));
849
850 for (qw(file.xs)) {
851   ok($o =~ /^Writing copy of.*\Q$_\E.*with changes/mi);
852   ok(-e "${_}f");
853   ok(eq_files("${_}f", "${_}r"));
854   unlink "${_}f";
855 }
856
857 ---------------------------- file.xs -----------------------------------------
858
859 a_string = "sv_undef"
860 a_char = 'sv_yes'
861 #define SOMETHING defgv
862 /* C-comment: sv_tainted */
863 #
864 # This is just a big XS comment using sv_no
865 #
866 /* The following, is NOT an XS comment! */
867 #  define SOMETHING_ELSE defgv + \
868                          sv_undef
869
870 ---------------------------- file.xsr -----------------------------------------
871
872 #include "ppport.h"
873 a_string = "sv_undef"
874 a_char = 'sv_yes'
875 #define SOMETHING PL_defgv
876 /* C-comment: sv_tainted */
877 #
878 # This is just a big XS comment using sv_no
879 #
880 /* The following, is NOT an XS comment! */
881 #  define SOMETHING_ELSE PL_defgv + \
882                          PL_sv_undef
883