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