1 ################################################################################
3 # !!!!! Do NOT edit this file directly! !!!!!
5 # Edit mktests.PL and/or parts/inc/ppphtest instead.
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.
11 ################################################################################
14 if ($ENV{'PERL_CORE'}) {
16 @INC = ('../lib', '../ext/Devel/PPPort/t') if -d '../lib' && -d '../ext';
17 require Config; import Config;
19 if (" $Config{'extensions'} " !~ m[ Devel/PPPort ]) {
20 print "1..0 # Skip -- Perl configured without Devel::PPPort module\n";
30 require 'testutil.pl' if $@;
43 package Devel::PPPort;
46 @ISA = qw(DynaLoader);
47 bootstrap Devel::PPPort;
52 if ($ENV{'SKIP_SLOW_TESTS'}) {
54 skip("skip: SKIP_SLOW_TESTS", 0);
60 use File::Path qw/rmtree mkpath/;
65 my $isVMS = $^O eq 'VMS';
66 my $isMAC = $^O eq 'MacOS';
67 my $perl = find_perl();
69 rmtree($tmp) if -d $tmp;
70 mkpath($tmp) or die "mkpath $tmp: $!\n";
71 chdir($tmp) or die "chdir $tmp: $!\n";
73 if ($ENV{'PERL_CORE'}) {
76 $inc = '"-I../../lib"';
84 unshift @INC, '../../lib';
87 if ($perl =~ m!^\./!) {
92 chdir('..') if !-d $tmp && -d "../$tmp";
93 rmtree($tmp) if -d $tmp;
96 ok(&Devel::PPPort::WriteFile("ppport.h"));
102 $c .= "\n" unless $c =~ /[\r\n]$/;
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;
113 $_ = qq("$_") if $isVMS && /^[^"]/;
116 print "# *** running $run ***\n";
117 $run .= ' 2>&1' unless $isMAC;
119 my $out = join '', @out;
121 return wantarray ? @out : $out;
126 my($str, $re, $mod) = @_;
128 eval "\@n = \$str =~ /$re/g$mod;";
131 $err =~ s/^/# *** /mg;
132 print "# *** ERROR ***\n$err\n";
134 return $@ ? -42 : scalar @n;
140 return 0 unless -e $f1 && -e $f2;
143 print "# File: $_\n";
144 unless (open F, $_) {
145 print "# couldn't open $_: $!\n";
148 $_ = do { local $/; <F> };
157 for (split /\s*={70,}\s*/, do { local $/; <DATA> }) {
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 };
166 print "#\n", ('# ', '-'x70, "\n")x3, "#\n";
168 for $f (keys %{$t->{files}}) {
169 my @f = split /\//, $f;
172 my $path = join '/', @f;
173 mkpath($path) or die "mkpath('$path'): $!\n";
175 my $txt = $t->{files}{$f};
177 open F, ">$f" or die "open $f: $!\n";
181 print "# *** writing $f ***\n$txt\n";
184 my $code = $t->{code};
185 $code =~ s/^/# | /mg;
187 print "# *** evaluating test code ***\n$code\n";
192 $err =~ s/^/# *** /mg;
193 print "# *** ERROR ***\n$err\n";
197 for (keys %{$t->{files}}) {
198 unlink $_ or die "unlink('$_'): $!\n";
206 return $perl if $isVMS;
208 my $exe = $Config{'_exe'} || '';
210 if ($perl =~ /^perl\Q$exe\E$/i) {
212 eval "require File::Spec";
216 $perl = File::Spec->catfile(File::Spec->curdir(), $perl);
220 if ($perl !~ /\Q$exe\E$/i) {
224 warn "find_perl: cannot find $perl from $^X" unless -f $perl;
231 my $o = ppport(qw(--help));
232 ok($o =~ /^Usage:.*ppport\.h/m);
235 $o = ppport(qw(--version));
236 ok($o =~ /^This is.*ppport.*\d+\.\d+(?:_?\d+)?\.$/);
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/);
245 $o = ppport(qw(--quiet --nochanges));
248 ---------------------------- test.xs ------------------------------------------
252 ===============================================================================
254 # check if C and C++ comments are filtered correctly
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'));
266 # check if C++ are left untouched with --cplusplus
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'));
278 unlink qw(MyExt.xsa MyExt.xsb);
280 ---------------------------- MyExt.xs -----------------------------------------
287 ---------------------------- MyExt.ra -----------------------------------------
295 ---------------------------- MyExt.rb -----------------------------------------
303 ===============================================================================
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);
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);
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);
335 $o = ppport(qw(--nochanges --quiet file1.xs));
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);
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);
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);
365 $o = ppport(qw(--nochanges --quiet file2.xs));
368 ---------------------------- file1.xs -----------------------------------------
370 #define NEED_newCONSTSUB
371 #define NEED_sv_2pv_flags
378 ---------------------------- file2.xs -----------------------------------------
382 ===============================================================================
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);
391 ---------------------------- FooBar.xs ----------------------------------------
397 ===============================================================================
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);
409 ---------------------------- First.xs -----------------------------------------
413 ---------------------------- foobar.xyz ---------------------------------------
417 ---------------------------- second.h -----------------------------------------
421 ---------------------------- sub/third.c --------------------------------------
425 ===============================================================================
427 my $o = ppport(qw(--nochanges));
428 ok($o =~ /Possibly wrong #define NEED_foobar in.*test.xs/i);
430 ---------------------------- test.xs ------------------------------------------
434 ===============================================================================
436 # And now some complex "real-world" example
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);
443 ok(matches($o, '^Scanning', 'm'), 6);
445 ok(matches($o, '^Writing copy of', 'm'), 5);
448 for (qw(main.xs mod1.c mod2.c mod3.c mod4.c)) {
449 ok($o =~ /^Writing copy of.*\Q$_\E.*with changes/mi);
451 ok(eq_files("${_}f", "${_}r"));
455 ---------------------------- main.xs ------------------------------------------
461 #define NEED_newCONSTSUB
462 #define NEED_grok_hex_GLOBAL
467 Perl_grok_bin(aTHX_ foo, bar);
473 Perl_grok_bin(bar, sv_no);
475 ---------------------------- mod1.c -------------------------------------------
481 #define NEED_grok_bin_GLOBAL
482 #define NEED_newCONSTSUB
489 Perl_sv_catpvf(); /* I know it's wrong ;-) */
492 ---------------------------- mod2.c -------------------------------------------
507 ---------------------------- mod3.c -------------------------------------------
516 ---------------------------- mod4.c -------------------------------------------
524 ---------------------------- mod5.c -------------------------------------------
533 ---------------------------- main.xsr -----------------------------------------
539 #define NEED_eval_pv_GLOBAL
540 #define NEED_grok_hex
541 #define NEED_newCONSTSUB_GLOBAL
552 grok_bin(bar, PL_sv_no);
554 ---------------------------- mod1.cr ------------------------------------------
560 #define NEED_grok_bin_GLOBAL
566 Perl_croak (aTHX_ "foo");
567 Perl_sv_catpvf(aTHX); /* I know it's wrong ;-) */
570 ---------------------------- mod2.cr ------------------------------------------
583 ---------------------------- mod3.cr ------------------------------------------
588 #define NEED_grok_oct
594 ---------------------------- mod4.cr ------------------------------------------
603 ===============================================================================
605 my $o = ppport(qw(--nochanges));
606 ok($o =~ /Uses grok_hex/m);
607 ok($o !~ /Looks good/m);
609 $o = ppport(qw(--nochanges --compat-version=5.8.0));
610 ok($o !~ /Uses grok_hex/m);
611 ok($o =~ /Looks good/m);
613 ---------------------------- FooBar.xs ----------------------------------------
617 ===============================================================================
619 my $o = ppport(qw(--nochanges));
620 ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
622 $o = ppport(qw(--nochanges --compat-version=5.5.3));
623 ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
625 $o = ppport(qw(--nochanges --compat-version=5.005_03));
626 ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
628 $o = ppport(qw(--nochanges --compat-version=5.6.0));
629 ok($o !~ /Uses SvPVutf8_force/m);
631 $o = ppport(qw(--nochanges --compat-version=5.006));
632 ok($o !~ /Uses SvPVutf8_force/m);
634 $o = ppport(qw(--nochanges --compat-version=5.999.999));
635 ok($o !~ /Uses SvPVutf8_force/m);
637 $o = ppport(qw(--nochanges --compat-version=6.0.0));
638 ok($o =~ /Only Perl 5 is supported/m);
640 $o = ppport(qw(--nochanges --compat-version=5.1000.999));
641 ok($o =~ /Invalid version number: 5.1000.999/m);
643 $o = ppport(qw(--nochanges --compat-version=5.999.1000));
644 ok($o =~ /Invalid version number: 5.999.1000/m);
646 ---------------------------- FooBar.xs ----------------------------------------
650 ===============================================================================
652 my $o = ppport(qw(--nochanges));
653 ok($o !~ /potentially required change/);
654 ok(matches($o, '^Looks good', 'm'), 2);
656 ---------------------------- FooBar.xs ----------------------------------------
658 #define NEED_grok_numeric_radix
659 #define NEED_grok_number
662 GROK_NUMERIC_RADIX();
665 ---------------------------- foo.c --------------------------------------------
671 ===============================================================================
673 # check --api-info option
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);
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);
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});
694 ===============================================================================
696 # check --list-provided option
698 my @o = ppport(qw(--list-provided));
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 } : '';
709 ok(exists $p{call_sv});
710 ok(not ref $p{call_sv});
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});
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});
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});
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});
735 ===============================================================================
737 # check --list-unsupported option
739 my @o = ppport(qw(--list-unsupported));
743 my($name, $ver) = /^(\w+)\s*\.+\s*([\d._]+)$/ or $fail++;
744 exists $p{$name} and $fail++;
750 ok(exists $p{utf8_distance});
751 ok($p{utf8_distance}, '5.6.0');
753 ok(exists $p{save_generic_svref});
754 ok($p{save_generic_svref}, '5.005_03');
756 ===============================================================================
758 # check --nofilter option
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);
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);
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);
785 ---------------------------- foo.cpp ------------------------------------------
789 ---------------------------- foo.o --------------------------------------------
793 ---------------------------- Makefile.PL --------------------------------------
797 ===============================================================================
799 # check if explicit variables are handled propery
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'));
807 unlink qw(MyExt.xsa);
809 ---------------------------- MyExt.xs -----------------------------------------
812 if (PL_signals == 42)
815 ---------------------------- MyExt.ra -----------------------------------------
817 #define NEED_PL_signals
820 if (PL_signals == 42)
823 ===============================================================================
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);
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);
840 ---------------------------- file.xs -----------------------------------------
846 ===============================================================================
848 my $o = ppport(qw(--copy=f));
851 ok($o =~ /^Writing copy of.*\Q$_\E.*with changes/mi);
853 ok(eq_files("${_}f", "${_}r"));
857 ---------------------------- file.xs -----------------------------------------
859 a_string = "sv_undef"
861 #define SOMETHING defgv
862 /* C-comment: sv_tainted */
864 # This is just a big XS comment using sv_no
866 /* The following, is NOT an XS comment! */
867 # define SOMETHING_ELSE defgv + \
870 ---------------------------- file.xsr -----------------------------------------
873 a_string = "sv_undef"
875 #define SOMETHING PL_defgv
876 /* C-comment: sv_tainted */
878 # This is just a big XS comment using sv_no
880 /* The following, is NOT an XS comment! */
881 # define SOMETHING_ELSE PL_defgv + \