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