Make expand-macro.pl accept macro expressions, i.e. macros with
[p5sagit/p5-mst-13.2.git] / ext / Devel / PPPort / parts / inc / ppphtest
CommitLineData
adfe19db 1################################################################################
2##
c1a049cb 3## $Revision: 42 $
adfe19db 4## $Author: mhx $
c1a049cb 5## $Date: 2008/01/04 10:47:42 +0100 $
adfe19db 6##
7################################################################################
8##
c1a049cb 9## Version 3.x, Copyright (C) 2004-2008, 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
aab9a3b6 18=tests plan => 229
0d0f8426 19
20BEGIN {
0c96388f 21 if ($ENV{'SKIP_SLOW_TESTS'}) {
aab9a3b6 22 for (1 .. 229) {
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);
679ad62d 279ok($o =~ /^Uses SvPV_nolen.*depends.*sv_2pv_flags/m);
280ok($o =~ /WARNING: PL_expect/m);
adfe19db 281ok($o =~ /hint for newCONSTSUB/m);
adfe19db 282ok($o =~ /^Looks good/m);
283
284$o = ppport(qw(--nochanges --nohints file1.xs));
4a582685 285ok($o =~ /^Scanning.*file1\.xs/mi);
286ok($o =~ /Analyzing.*file1\.xs/mi);
287ok($o !~ /^Scanning.*file2\.xs/mi);
adfe19db 288ok($o =~ /^Uses newCONSTSUB/m);
679ad62d 289ok($o =~ /^Uses SvPV_nolen.*depends.*sv_2pv_flags/m);
290ok($o =~ /WARNING: PL_expect/m);
adfe19db 291ok($o !~ /hint for newCONSTSUB/m);
adfe19db 292ok($o =~ /^Looks good/m);
293
294$o = ppport(qw(--nochanges --nohints --nodiag file1.xs));
4a582685 295ok($o =~ /^Scanning.*file1\.xs/mi);
296ok($o =~ /Analyzing.*file1\.xs/mi);
297ok($o !~ /^Scanning.*file2\.xs/mi);
adfe19db 298ok($o !~ /^Uses newCONSTSUB/m);
299ok($o !~ /^Uses SvPV_nolen/m);
679ad62d 300ok($o =~ /WARNING: PL_expect/m);
adfe19db 301ok($o !~ /hint for newCONSTSUB/m);
adfe19db 302ok($o =~ /^Looks good/m);
303
304$o = ppport(qw(--nochanges --quiet file1.xs));
305ok($o =~ /^\s*$/);
306
307$o = ppport(qw(--nochanges file2.xs));
4a582685 308ok($o =~ /^Scanning.*file2\.xs/mi);
309ok($o =~ /Analyzing.*file2\.xs/mi);
310ok($o !~ /^Scanning.*file1\.xs/mi);
adfe19db 311ok($o =~ /^Uses mXPUSHp/m);
312ok($o =~ /^Needs to include.*ppport\.h/m);
313ok($o !~ /^Looks good/m);
314ok($o =~ /^1 potentially required change detected/m);
315
316$o = ppport(qw(--nochanges --nohints file2.xs));
4a582685 317ok($o =~ /^Scanning.*file2\.xs/mi);
318ok($o =~ /Analyzing.*file2\.xs/mi);
319ok($o !~ /^Scanning.*file1\.xs/mi);
adfe19db 320ok($o =~ /^Uses mXPUSHp/m);
321ok($o =~ /^Needs to include.*ppport\.h/m);
322ok($o !~ /^Looks good/m);
323ok($o =~ /^1 potentially required change detected/m);
324
325$o = ppport(qw(--nochanges --nohints --nodiag file2.xs));
4a582685 326ok($o =~ /^Scanning.*file2\.xs/mi);
327ok($o =~ /Analyzing.*file2\.xs/mi);
328ok($o !~ /^Scanning.*file1\.xs/mi);
adfe19db 329ok($o !~ /^Uses mXPUSHp/m);
330ok($o !~ /^Needs to include.*ppport\.h/m);
331ok($o !~ /^Looks good/m);
332ok($o =~ /^1 potentially required change detected/m);
333
334$o = ppport(qw(--nochanges --quiet file2.xs));
335ok($o =~ /^\s*$/);
336
337---------------------------- file1.xs -----------------------------------------
338
339#define NEED_newCONSTSUB
679ad62d 340#define NEED_sv_2pv_flags
adfe19db 341#include "ppport.h"
342
343newCONSTSUB();
344SvPV_nolen();
679ad62d 345PL_expect = 0;
adfe19db 346
347---------------------------- file2.xs -----------------------------------------
348
349mXPUSHp(foo);
350
351===============================================================================
352
353my $o = ppport(qw(--nochanges));
4a582685 354ok($o =~ /^Scanning.*FooBar\.xs/mi);
355ok($o =~ /Analyzing.*FooBar\.xs/mi);
356ok(matches($o, '^Scanning', 'm'), 1);
adfe19db 357ok($o !~ /^Looks good/m);
358ok($o =~ /^Uses grok_bin/m);
359
360---------------------------- FooBar.xs ----------------------------------------
361
362newSViv();
363XPUSHs(foo);
364grok_bin();
365
366===============================================================================
367
368my $o = ppport(qw(--nochanges));
4a582685 369ok($o =~ /^Scanning.*First\.xs/mi);
370ok($o =~ /Analyzing.*First\.xs/mi);
371ok($o =~ /^Scanning.*second\.h/mi);
372ok($o =~ /Analyzing.*second\.h/mi);
373ok($o =~ /^Scanning.*sub.*third\.c/mi);
374ok($o =~ /Analyzing.*sub.*third\.c/mi);
375ok($o !~ /^Scanning.*foobar/mi);
376ok(matches($o, '^Scanning', 'm'), 3);
adfe19db 377
378---------------------------- First.xs -----------------------------------------
379
380one
381
382---------------------------- foobar.xyz ---------------------------------------
383
384two
385
386---------------------------- second.h -----------------------------------------
387
388three
389
390---------------------------- sub/third.c --------------------------------------
391
392four
393
394===============================================================================
395
396my $o = ppport(qw(--nochanges));
397ok($o =~ /Possibly wrong #define NEED_foobar in.*test.xs/i);
398
399---------------------------- test.xs ------------------------------------------
400
401#define NEED_foobar
402
403===============================================================================
404
405# And now some complex "real-world" example
406
407my $o = ppport(qw(--copy=f));
408for (qw(main.xs mod1.c mod2.c mod3.c mod4.c mod5.c)) {
4a582685 409 ok($o =~ /^Scanning.*\Q$_\E/mi);
410 ok($o =~ /Analyzing.*\Q$_\E/i);
adfe19db 411}
4a582685 412ok(matches($o, '^Scanning', 'm'), 6);
adfe19db 413
4a582685 414ok(matches($o, '^Writing copy of', 'm'), 5);
adfe19db 415ok(!-e "mod5.cf");
416
417for (qw(main.xs mod1.c mod2.c mod3.c mod4.c)) {
418 ok($o =~ /^Writing copy of.*\Q$_\E.*with changes/mi);
419 ok(-e "${_}f");
420 ok(eq_files("${_}f", "${_}r"));
421 unlink "${_}f";
422}
423
424---------------------------- main.xs ------------------------------------------
425
426#include "EXTERN.h"
427#include "perl.h"
428#include "XSUB.h"
429
430#define NEED_newCONSTSUB
431#define NEED_grok_hex_GLOBAL
432#include "ppport.h"
433
434newCONSTSUB();
435grok_hex();
436Perl_grok_bin(aTHX_ foo, bar);
437
438/* some comment */
439
440perl_eval_pv();
441grok_bin();
442Perl_grok_bin(bar, sv_no);
443
444---------------------------- mod1.c -------------------------------------------
445
446#include "EXTERN.h"
447#include "perl.h"
448#include "XSUB.h"
449
450#define NEED_grok_bin_GLOBAL
451#define NEED_newCONSTSUB
452#include "ppport.h"
453
454newCONSTSUB();
455grok_bin();
456{
457 Perl_croak ("foo");
458 Perl_sv_catpvf(); /* I know it's wrong ;-) */
459}
460
461---------------------------- mod2.c -------------------------------------------
462
463#include "EXTERN.h"
464#include "perl.h"
465#include "XSUB.h"
466
467#define NEED_eval_pv
468#include "ppport.h"
469
470newSViv();
471
472/*
473 eval_pv();
474*/
475
476---------------------------- mod3.c -------------------------------------------
477
478#include "EXTERN.h"
479#include "perl.h"
480#include "XSUB.h"
481
482grok_oct();
483eval_pv();
484
485---------------------------- mod4.c -------------------------------------------
486
487#include "EXTERN.h"
488#include "perl.h"
489#include "XSUB.h"
490
491START_MY_CXT;
492
493---------------------------- mod5.c -------------------------------------------
494
495#include "EXTERN.h"
496#include "perl.h"
497#include "XSUB.h"
498
499#include "ppport.h"
500call_pv();
501
502---------------------------- main.xsr -----------------------------------------
503
504#include "EXTERN.h"
505#include "perl.h"
506#include "XSUB.h"
507
508#define NEED_eval_pv_GLOBAL
509#define NEED_grok_hex
510#define NEED_newCONSTSUB_GLOBAL
511#include "ppport.h"
512
513newCONSTSUB();
514grok_hex();
515grok_bin(foo, bar);
516
517/* some comment */
518
519eval_pv();
520grok_bin();
521grok_bin(bar, PL_sv_no);
522
523---------------------------- mod1.cr ------------------------------------------
524
525#include "EXTERN.h"
526#include "perl.h"
527#include "XSUB.h"
528
529#define NEED_grok_bin_GLOBAL
530#include "ppport.h"
531
532newCONSTSUB();
533grok_bin();
534{
535 Perl_croak (aTHX_ "foo");
536 Perl_sv_catpvf(aTHX); /* I know it's wrong ;-) */
537}
538
539---------------------------- mod2.cr ------------------------------------------
540
541#include "EXTERN.h"
542#include "perl.h"
543#include "XSUB.h"
544
545
546newSViv();
547
548/*
549 eval_pv();
550*/
551
552---------------------------- mod3.cr ------------------------------------------
553
554#include "EXTERN.h"
555#include "perl.h"
556#include "XSUB.h"
557#define NEED_grok_oct
558#include "ppport.h"
559
560grok_oct();
561eval_pv();
562
563---------------------------- mod4.cr ------------------------------------------
564
565#include "EXTERN.h"
566#include "perl.h"
567#include "XSUB.h"
568#include "ppport.h"
569
570START_MY_CXT;
571
572===============================================================================
573
574my $o = ppport(qw(--nochanges));
575ok($o =~ /Uses grok_hex/m);
576ok($o !~ /Looks good/m);
577
578$o = ppport(qw(--nochanges --compat-version=5.8.0));
579ok($o !~ /Uses grok_hex/m);
580ok($o =~ /Looks good/m);
581
582---------------------------- FooBar.xs ----------------------------------------
583
584grok_hex();
585
586===============================================================================
587
588my $o = ppport(qw(--nochanges));
589ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
590
4a582685 591$o = ppport(qw(--nochanges --compat-version=5.5.3));
592ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
593
594$o = ppport(qw(--nochanges --compat-version=5.005_03));
595ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
596
adfe19db 597$o = ppport(qw(--nochanges --compat-version=5.6.0));
598ok($o !~ /Uses SvPVutf8_force/m);
599
4a582685 600$o = ppport(qw(--nochanges --compat-version=5.006));
601ok($o !~ /Uses SvPVutf8_force/m);
602
603$o = ppport(qw(--nochanges --compat-version=5.999.999));
604ok($o !~ /Uses SvPVutf8_force/m);
605
606$o = ppport(qw(--nochanges --compat-version=6.0.0));
607ok($o =~ /Only Perl 5 is supported/m);
608
609$o = ppport(qw(--nochanges --compat-version=5.1000.999));
610ok($o =~ /Invalid version number: 5.1000.999/m);
611
612$o = ppport(qw(--nochanges --compat-version=5.999.1000));
613ok($o =~ /Invalid version number: 5.999.1000/m);
614
adfe19db 615---------------------------- FooBar.xs ----------------------------------------
616
617SvPVutf8_force();
618
96ad942f 619===============================================================================
620
621my $o = ppport(qw(--nochanges));
622ok($o !~ /potentially required change/);
4a582685 623ok(matches($o, '^Looks good', 'm'), 2);
96ad942f 624
625---------------------------- FooBar.xs ----------------------------------------
626
627#define NEED_grok_numeric_radix
628#define NEED_grok_number
629#include "ppport.h"
630
631GROK_NUMERIC_RADIX();
632grok_number();
633
634---------------------------- foo.c --------------------------------------------
635
636#include "ppport.h"
637
638call_pv();
639
4a582685 640===============================================================================
641
642# check --api-info option
643
644my $o = ppport(qw(--api-info=INT2PTR));
645my %found = map {($_ => 1)} $o =~ /^===\s+(\w+)\s+===/mg;
646ok(scalar keys %found, 1);
647ok(exists $found{INT2PTR});
648ok(matches($o, '^Supported at least starting from perl-5\.6\.0\.', 'm'), 1);
649ok(matches($o, '^Support by .*ppport.* provided back to perl-5\.003\.', 'm'), 1);
650
651$o = ppport(qw(--api-info=Zero));
652%found = map {($_ => 1)} $o =~ /^===\s+(\w+)\s+===/mg;
653ok(scalar keys %found, 1);
654ok(exists $found{Zero});
655ok(matches($o, '^No portability information available\.', 'm'), 1);
656
657$o = ppport(qw(--api-info=/Zero/));
658%found = map {($_ => 1)} $o =~ /^===\s+(\w+)\s+===/mg;
659ok(scalar keys %found, 2);
660ok(exists $found{Zero});
661ok(exists $found{ZeroD});
662
663===============================================================================
664
665# check --list-provided option
666
667my @o = ppport(qw(--list-provided));
668my %p;
669my $fail = 0;
670for (@o) {
671 my($name, $flags) = /^(\w+)(?:\s+\[(\w+(?:,\s+\w+)*)\])?$/ or $fail++;
672 exists $p{$name} and $fail++;
673 $p{$name} = defined $flags ? { map { ($_ => 1) } $flags =~ /(\w+)/g } : '';
674}
675ok(@o > 100);
676ok($fail, 0);
677
678ok(exists $p{call_sv});
679ok(not ref $p{call_sv});
680
681ok(exists $p{grok_bin});
682ok(ref $p{grok_bin}, 'HASH');
679ad62d 683ok(scalar keys %{$p{grok_bin}}, 2);
4a582685 684ok($p{grok_bin}{explicit});
679ad62d 685ok($p{grok_bin}{depend});
4a582685 686
687ok(exists $p{gv_stashpvn});
688ok(ref $p{gv_stashpvn}, 'HASH');
679ad62d 689ok(scalar keys %{$p{gv_stashpvn}}, 2);
690ok($p{gv_stashpvn}{depend});
4a582685 691ok($p{gv_stashpvn}{hint});
692
693ok(exists $p{sv_catpvf_mg});
694ok(ref $p{sv_catpvf_mg}, 'HASH');
695ok(scalar keys %{$p{sv_catpvf_mg}}, 2);
696ok($p{sv_catpvf_mg}{explicit});
697ok($p{sv_catpvf_mg}{depend});
698
679ad62d 699ok(exists $p{PL_signals});
700ok(ref $p{PL_signals}, 'HASH');
701ok(scalar keys %{$p{PL_signals}}, 1);
702ok($p{PL_signals}{explicit});
703
4a582685 704===============================================================================
705
706# check --list-unsupported option
707
708my @o = ppport(qw(--list-unsupported));
709my %p;
710my $fail = 0;
711for (@o) {
712 my($name, $ver) = /^(\w+)\s*\.+\s*([\d._]+)$/ or $fail++;
713 exists $p{$name} and $fail++;
714 $p{$name} = $ver;
715}
716ok(@o > 100);
717ok($fail, 0);
718
719ok(exists $p{utf8_distance});
720ok($p{utf8_distance}, '5.6.0');
721
722ok(exists $p{save_generic_svref});
723ok($p{save_generic_svref}, '5.005_03');
724
725===============================================================================
726
727# check --nofilter option
728
729my $o = ppport(qw(--nochanges));
730ok($o =~ /^Scanning.*foo\.cpp/mi);
731ok($o =~ /Analyzing.*foo\.cpp/mi);
732ok(matches($o, '^Scanning', 'm'), 1);
733ok(matches($o, 'Analyzing', 'm'), 1);
734
735$o = ppport(qw(--nochanges foo.cpp foo.o Makefile.PL));
736ok($o =~ /Skipping the following files \(use --nofilter to avoid this\):/m);
737ok(matches($o, '^\|\s+foo\.o', 'mi'), 1);
738ok(matches($o, '^\|\s+Makefile\.PL', 'mi'), 1);
739ok($o =~ /^Scanning.*foo\.cpp/mi);
740ok($o =~ /Analyzing.*foo\.cpp/mi);
741ok(matches($o, '^Scanning', 'm'), 1);
742ok(matches($o, 'Analyzing', 'm'), 1);
743
744$o = ppport(qw(--nochanges --nofilter foo.cpp foo.o Makefile.PL));
745ok($o =~ /^Scanning.*foo\.cpp/mi);
746ok($o =~ /Analyzing.*foo\.cpp/mi);
747ok($o =~ /^Scanning.*foo\.o/mi);
748ok($o =~ /Analyzing.*foo\.o/mi);
749ok($o =~ /^Scanning.*Makefile/mi);
750ok($o =~ /Analyzing.*Makefile/mi);
751ok(matches($o, '^Scanning', 'm'), 3);
752ok(matches($o, 'Analyzing', 'm'), 3);
753
754---------------------------- foo.cpp ------------------------------------------
755
756newSViv();
757
758---------------------------- foo.o --------------------------------------------
759
760newSViv();
761
762---------------------------- Makefile.PL --------------------------------------
763
764newSViv();
765
0d0f8426 766===============================================================================
767
768# check if explicit variables are handled propery
769
770my $o = ppport(qw(--copy=a));
771ok($o =~ /^Needs to include.*ppport\.h/m);
772ok($o =~ /^Uses PL_signals/m);
773ok($o =~ /^File needs PL_signals, adding static request/m);
774ok(eq_files('MyExt.xsa', 'MyExt.ra'));
775
776unlink qw(MyExt.xsa);
777
778---------------------------- MyExt.xs -----------------------------------------
779
780PL_signals = 123;
781if (PL_signals == 42)
782 foo();
783
784---------------------------- MyExt.ra -----------------------------------------
785
786#define NEED_PL_signals
787#include "ppport.h"
788PL_signals = 123;
789if (PL_signals == 42)
790 foo();
791
679ad62d 792===============================================================================
793
794my $o = ppport(qw(--nochanges file.xs));
795ok($o =~ /^Uses PL_copline/m);
796ok($o =~ /WARNING: PL_copline/m);
797ok($o =~ /^Uses SvUOK/m);
798ok($o =~ /WARNING: Uses SvUOK, which may not be portable/m);
799ok($o =~ /^Analysis completed \(2 warnings\)/m);
800ok($o =~ /^Looks good/m);
801
802$o = ppport(qw(--nochanges --compat-version=5.8.0 file.xs));
803ok($o =~ /^Uses PL_copline/m);
804ok($o =~ /WARNING: PL_copline/m);
805ok($o !~ /WARNING: Uses SvUOK, which may not be portable/m);
806ok($o =~ /^Analysis completed \(1 warning\)/m);
807ok($o =~ /^Looks good/m);
808
809---------------------------- file.xs -----------------------------------------
810
811#include "ppport.h"
812SvUOK
813PL_copline
814
c83e6f19 815===============================================================================
816
817my $o = ppport(qw(--copy=f));
818
819for (qw(file.xs)) {
820 ok($o =~ /^Writing copy of.*\Q$_\E.*with changes/mi);
821 ok(-e "${_}f");
822 ok(eq_files("${_}f", "${_}r"));
823 unlink "${_}f";
824}
825
826---------------------------- file.xs -----------------------------------------
827
828a_string = "sv_undef"
829a_char = 'sv_yes'
830#define SOMETHING defgv
831/* C-comment: sv_tainted */
832#
833# This is just a big XS comment using sv_no
834#
835/* The following, is NOT an XS comment! */
836# define SOMETHING_ELSE defgv + \
837 sv_undef
838
839---------------------------- file.xsr -----------------------------------------
840
841#include "ppport.h"
842a_string = "sv_undef"
843a_char = 'sv_yes'
844#define SOMETHING PL_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 PL_defgv + \
851 PL_sv_undef
852
aab9a3b6 853===============================================================================
854
855my $o = ppport(qw(--copy=f));
856
857for (qw(file.xs)) {
858 ok($o =~ /^Writing copy of.*\Q$_\E.*with changes/mi);
859 ok(-e "${_}f");
860 ok(eq_files("${_}f", "${_}r"));
861 unlink "${_}f";
862}
863
864---------------------------- file.xs -----------------------------------------
865
866#define NEED_sv_2pv_flags
867#define NEED_vnewSVpvf
868#define NEED_warner
869#include "ppport.h"
870Perl_croak_nocontext("foo");
871Perl_croak("bar");
872croak("foo");
873croak_nocontext("foo");
874Perl_warner_nocontext("foo");
875Perl_warner("foo");
876warner_nocontext("foo");
877warner("foo");
878
879---------------------------- file.xsr -----------------------------------------
880
881#define NEED_sv_2pv_flags
882#define NEED_vnewSVpvf
883#define NEED_warner
884#include "ppport.h"
885Perl_croak_nocontext("foo");
886Perl_croak(aTHX_ "bar");
887croak("foo");
888croak_nocontext("foo");
889Perl_warner_nocontext("foo");
890Perl_warner(aTHX_ "foo");
891warner_nocontext("foo");
892warner("foo");
893