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 PL_expect/m);
311 ok($o =~ /^Uses SvPV_nolen.*depends.*sv_2pv_flags/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);
317 $o = ppport(qw(--nochanges --nohints file1.xs));
318 ok($o =~ /^Scanning.*file1\.xs/mi);
319 ok($o =~ /Analyzing.*file1\.xs/mi);
320 ok($o !~ /^Scanning.*file2\.xs/mi);
321 ok($o =~ /^Uses newCONSTSUB/m);
322 ok($o =~ /^Uses PL_expect/m);
323 ok($o =~ /^Uses SvPV_nolen.*depends.*sv_2pv_flags/m);
324 ok($o =~ /WARNING: PL_expect/m);
325 ok($o !~ /hint for newCONSTSUB/m);
326 ok($o =~ /^Analysis completed \(1 warning\)/m);
327 ok($o =~ /^Looks good/m);
329 $o = ppport(qw(--nochanges --nohints --nodiag file1.xs));
330 ok($o =~ /^Scanning.*file1\.xs/mi);
331 ok($o =~ /Analyzing.*file1\.xs/mi);
332 ok($o !~ /^Scanning.*file2\.xs/mi);
333 ok($o !~ /^Uses newCONSTSUB/m);
334 ok($o !~ /^Uses PL_expect/m);
335 ok($o !~ /^Uses SvPV_nolen/m);
336 ok($o =~ /WARNING: PL_expect/m);
337 ok($o !~ /hint for newCONSTSUB/m);
338 ok($o =~ /^Analysis completed \(1 warning\)/m);
339 ok($o =~ /^Looks good/m);
341 $o = ppport(qw(--nochanges --quiet file1.xs));
344 $o = ppport(qw(--nochanges file2.xs));
345 ok($o =~ /^Scanning.*file2\.xs/mi);
346 ok($o =~ /Analyzing.*file2\.xs/mi);
347 ok($o !~ /^Scanning.*file1\.xs/mi);
348 ok($o =~ /^Uses mXPUSHp/m);
349 ok($o =~ /^Needs to include.*ppport\.h/m);
350 ok($o !~ /^Looks good/m);
351 ok($o =~ /^1 potentially required change detected/m);
353 $o = ppport(qw(--nochanges --nohints file2.xs));
354 ok($o =~ /^Scanning.*file2\.xs/mi);
355 ok($o =~ /Analyzing.*file2\.xs/mi);
356 ok($o !~ /^Scanning.*file1\.xs/mi);
357 ok($o =~ /^Uses mXPUSHp/m);
358 ok($o =~ /^Needs to include.*ppport\.h/m);
359 ok($o !~ /^Looks good/m);
360 ok($o =~ /^1 potentially required change detected/m);
362 $o = ppport(qw(--nochanges --nohints --nodiag file2.xs));
363 ok($o =~ /^Scanning.*file2\.xs/mi);
364 ok($o =~ /Analyzing.*file2\.xs/mi);
365 ok($o !~ /^Scanning.*file1\.xs/mi);
366 ok($o !~ /^Uses mXPUSHp/m);
367 ok($o !~ /^Needs to include.*ppport\.h/m);
368 ok($o !~ /^Looks good/m);
369 ok($o =~ /^1 potentially required change detected/m);
371 $o = ppport(qw(--nochanges --quiet file2.xs));
374 ---------------------------- file1.xs -----------------------------------------
376 #define NEED_newCONSTSUB
377 #define NEED_sv_2pv_flags
378 #define NEED_PL_parser
385 ---------------------------- file2.xs -----------------------------------------
389 ===============================================================================
391 my $o = ppport(qw(--nochanges));
392 ok($o =~ /^Scanning.*FooBar\.xs/mi);
393 ok($o =~ /Analyzing.*FooBar\.xs/mi);
394 ok(matches($o, '^Scanning', 'm'), 1);
395 ok($o !~ /^Looks good/m);
396 ok($o =~ /^Uses grok_bin/m);
398 ---------------------------- FooBar.xs ----------------------------------------
404 ===============================================================================
406 my $o = ppport(qw(--nochanges));
407 ok($o =~ /^Scanning.*First\.xs/mi);
408 ok($o =~ /Analyzing.*First\.xs/mi);
409 ok($o =~ /^Scanning.*second\.h/mi);
410 ok($o =~ /Analyzing.*second\.h/mi);
411 ok($o =~ /^Scanning.*sub.*third\.c/mi);
412 ok($o =~ /Analyzing.*sub.*third\.c/mi);
413 ok($o !~ /^Scanning.*foobar/mi);
414 ok(matches($o, '^Scanning', 'm'), 3);
416 ---------------------------- First.xs -----------------------------------------
420 ---------------------------- foobar.xyz ---------------------------------------
424 ---------------------------- second.h -----------------------------------------
428 ---------------------------- sub/third.c --------------------------------------
432 ===============================================================================
434 my $o = ppport(qw(--nochanges));
435 ok($o =~ /Possibly wrong #define NEED_foobar in.*test.xs/i);
437 ---------------------------- test.xs ------------------------------------------
441 ===============================================================================
443 # And now some complex "real-world" example
445 my $o = ppport(qw(--copy=f));
446 for (qw(main.xs mod1.c mod2.c mod3.c mod4.c mod5.c)) {
447 ok($o =~ /^Scanning.*\Q$_\E/mi);
448 ok($o =~ /Analyzing.*\Q$_\E/i);
450 ok(matches($o, '^Scanning', 'm'), 6);
452 ok(matches($o, '^Writing copy of', 'm'), 5);
455 for (qw(main.xs mod1.c mod2.c mod3.c mod4.c)) {
456 ok($o =~ /^Writing copy of.*\Q$_\E.*with changes/mi);
458 ok(eq_files("${_}f", "${_}r"));
462 ---------------------------- main.xs ------------------------------------------
468 #define NEED_newCONSTSUB
469 #define NEED_grok_hex_GLOBAL
474 Perl_grok_bin(aTHX_ foo, bar);
480 Perl_grok_bin(bar, sv_no);
482 ---------------------------- mod1.c -------------------------------------------
488 #define NEED_grok_bin_GLOBAL
489 #define NEED_newCONSTSUB
496 Perl_sv_catpvf(); /* I know it's wrong ;-) */
499 ---------------------------- mod2.c -------------------------------------------
514 ---------------------------- mod3.c -------------------------------------------
523 ---------------------------- mod4.c -------------------------------------------
531 ---------------------------- mod5.c -------------------------------------------
540 ---------------------------- main.xsr -----------------------------------------
546 #define NEED_eval_pv_GLOBAL
547 #define NEED_grok_hex
548 #define NEED_newCONSTSUB_GLOBAL
559 grok_bin(bar, PL_sv_no);
561 ---------------------------- mod1.cr ------------------------------------------
567 #define NEED_grok_bin_GLOBAL
573 Perl_croak (aTHX_ "foo");
574 Perl_sv_catpvf(aTHX); /* I know it's wrong ;-) */
577 ---------------------------- mod2.cr ------------------------------------------
590 ---------------------------- mod3.cr ------------------------------------------
595 #define NEED_grok_oct
601 ---------------------------- mod4.cr ------------------------------------------
610 ===============================================================================
612 my $o = ppport(qw(--nochanges));
613 ok($o =~ /Uses grok_hex/m);
614 ok($o !~ /Looks good/m);
616 $o = ppport(qw(--nochanges --compat-version=5.8.0));
617 ok($o !~ /Uses grok_hex/m);
618 ok($o =~ /Looks good/m);
620 ---------------------------- FooBar.xs ----------------------------------------
624 ===============================================================================
626 my $o = ppport(qw(--nochanges));
627 ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
629 $o = ppport(qw(--nochanges --compat-version=5.5.3));
630 ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
632 $o = ppport(qw(--nochanges --compat-version=5.005_03));
633 ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
635 $o = ppport(qw(--nochanges --compat-version=5.6.0));
636 ok($o !~ /Uses SvPVutf8_force/m);
638 $o = ppport(qw(--nochanges --compat-version=5.006));
639 ok($o !~ /Uses SvPVutf8_force/m);
641 $o = ppport(qw(--nochanges --compat-version=5.999.999));
642 ok($o !~ /Uses SvPVutf8_force/m);
644 $o = ppport(qw(--nochanges --compat-version=6.0.0));
645 ok($o =~ /Only Perl 5 is supported/m);
647 $o = ppport(qw(--nochanges --compat-version=5.1000.999));
648 ok($o =~ /Invalid version number: 5.1000.999/m);
650 $o = ppport(qw(--nochanges --compat-version=5.999.1000));
651 ok($o =~ /Invalid version number: 5.999.1000/m);
653 ---------------------------- FooBar.xs ----------------------------------------
657 ===============================================================================
659 my $o = ppport(qw(--nochanges));
660 ok($o !~ /potentially required change/);
661 ok(matches($o, '^Looks good', 'm'), 2);
663 ---------------------------- FooBar.xs ----------------------------------------
665 #define NEED_grok_numeric_radix
666 #define NEED_grok_number
669 GROK_NUMERIC_RADIX();
672 ---------------------------- foo.c --------------------------------------------
678 ===============================================================================
680 # check --api-info option
682 my $o = ppport(qw(--api-info=INT2PTR));
683 my %found = map {($_ => 1)} $o =~ /^===\s+(\w+)\s+===/mg;
684 ok(scalar keys %found, 1);
685 ok(exists $found{INT2PTR});
686 ok(matches($o, '^Supported at least starting from perl-5\.6\.0\.', 'm'), 1);
687 ok(matches($o, '^Support by .*ppport.* provided back to perl-5\.003\.', 'm'), 1);
689 $o = ppport(qw(--api-info=Zero));
690 %found = map {($_ => 1)} $o =~ /^===\s+(\w+)\s+===/mg;
691 ok(scalar keys %found, 1);
692 ok(exists $found{Zero});
693 ok(matches($o, '^No portability information available\.', 'm'), 1);
695 $o = ppport(qw(--api-info=/Zero/));
696 %found = map {($_ => 1)} $o =~ /^===\s+(\w+)\s+===/mg;
697 ok(scalar keys %found, 2);
698 ok(exists $found{Zero});
699 ok(exists $found{ZeroD});
701 ===============================================================================
703 # check --list-provided option
705 my @o = ppport(qw(--list-provided));
709 my($name, $flags) = /^(\w+)(?:\s+\[(\w+(?:,\s+\w+)*)\])?$/ or $fail++;
710 exists $p{$name} and $fail++;
711 $p{$name} = defined $flags ? { map { ($_ => 1) } $flags =~ /(\w+)/g } : '';
716 ok(exists $p{call_pv});
717 ok(not ref $p{call_pv});
719 ok(exists $p{grok_bin});
720 ok(ref $p{grok_bin}, 'HASH');
721 ok(scalar keys %{$p{grok_bin}}, 2);
722 ok($p{grok_bin}{explicit});
723 ok($p{grok_bin}{depend});
725 ok(exists $p{gv_stashpvn});
726 ok(ref $p{gv_stashpvn}, 'HASH');
727 ok(scalar keys %{$p{gv_stashpvn}}, 2);
728 ok($p{gv_stashpvn}{depend});
729 ok($p{gv_stashpvn}{hint});
731 ok(exists $p{sv_catpvf_mg});
732 ok(ref $p{sv_catpvf_mg}, 'HASH');
733 ok(scalar keys %{$p{sv_catpvf_mg}}, 2);
734 ok($p{sv_catpvf_mg}{explicit});
735 ok($p{sv_catpvf_mg}{depend});
737 ok(exists $p{PL_signals});
738 ok(ref $p{PL_signals}, 'HASH');
739 ok(scalar keys %{$p{PL_signals}}, 1);
740 ok($p{PL_signals}{explicit});
742 ===============================================================================
744 # check --list-unsupported option
746 my @o = ppport(qw(--list-unsupported));
750 my($name, $ver) = /^(\w+)\s*\.+\s*([\d._]+)$/ or $fail++;
751 exists $p{$name} and $fail++;
757 ok(exists $p{utf8_distance});
758 ok($p{utf8_distance}, '5.6.0');
760 ok(exists $p{save_generic_svref});
761 ok($p{save_generic_svref}, '5.005_03');
763 ===============================================================================
765 # check --nofilter option
767 my $o = ppport(qw(--nochanges));
768 ok($o =~ /^Scanning.*foo\.cpp/mi);
769 ok($o =~ /Analyzing.*foo\.cpp/mi);
770 ok(matches($o, '^Scanning', 'm'), 1);
771 ok(matches($o, 'Analyzing', 'm'), 1);
773 $o = ppport(qw(--nochanges foo.cpp foo.o Makefile.PL));
774 ok($o =~ /Skipping the following files \(use --nofilter to avoid this\):/m);
775 ok(matches($o, '^\|\s+foo\.o', 'mi'), 1);
776 ok(matches($o, '^\|\s+Makefile\.PL', 'mi'), 1);
777 ok($o =~ /^Scanning.*foo\.cpp/mi);
778 ok($o =~ /Analyzing.*foo\.cpp/mi);
779 ok(matches($o, '^Scanning', 'm'), 1);
780 ok(matches($o, 'Analyzing', 'm'), 1);
782 $o = ppport(qw(--nochanges --nofilter foo.cpp foo.o Makefile.PL));
783 ok($o =~ /^Scanning.*foo\.cpp/mi);
784 ok($o =~ /Analyzing.*foo\.cpp/mi);
785 ok($o =~ /^Scanning.*foo\.o/mi);
786 ok($o =~ /Analyzing.*foo\.o/mi);
787 ok($o =~ /^Scanning.*Makefile/mi);
788 ok($o =~ /Analyzing.*Makefile/mi);
789 ok(matches($o, '^Scanning', 'm'), 3);
790 ok(matches($o, 'Analyzing', 'm'), 3);
792 ---------------------------- foo.cpp ------------------------------------------
796 ---------------------------- foo.o --------------------------------------------
800 ---------------------------- Makefile.PL --------------------------------------
804 ===============================================================================
806 # check if explicit variables are handled propery
808 my $o = ppport(qw(--copy=a));
809 ok($o =~ /^Needs to include.*ppport\.h/m);
810 ok($o =~ /^Uses PL_signals/m);
811 ok($o =~ /^File needs PL_signals, adding static request/m);
812 ok(eq_files('MyExt.xsa', 'MyExt.ra'));
814 unlink qw(MyExt.xsa);
816 ---------------------------- MyExt.xs -----------------------------------------
819 if (PL_signals == 42)
822 ---------------------------- MyExt.ra -----------------------------------------
824 #define NEED_PL_signals
827 if (PL_signals == 42)
830 ===============================================================================
832 my $o = ppport(qw(--nochanges file.xs));
833 ok($o =~ /^Uses PL_copline/m);
834 ok($o =~ /WARNING: PL_copline/m);
835 ok($o =~ /^Uses SvUOK/m);
836 ok($o =~ /WARNING: Uses SvUOK, which may not be portable/m);
837 ok($o =~ /^Analysis completed \(2 warnings\)/m);
838 ok($o =~ /^Looks good/m);
840 $o = ppport(qw(--nochanges --compat-version=5.8.0 file.xs));
841 ok($o =~ /^Uses PL_copline/m);
842 ok($o =~ /WARNING: PL_copline/m);
843 ok($o !~ /WARNING: Uses SvUOK, which may not be portable/m);
844 ok($o =~ /^Analysis completed \(1 warning\)/m);
845 ok($o =~ /^Looks good/m);
847 ---------------------------- file.xs -----------------------------------------
849 #define NEED_PL_parser
854 ===============================================================================
856 my $o = ppport(qw(--copy=f));
859 ok($o =~ /^Writing copy of.*\Q$_\E.*with changes/mi);
861 ok(eq_files("${_}f", "${_}r"));
865 ---------------------------- file.xs -----------------------------------------
867 a_string = "sv_undef"
869 #define SOMETHING defgv
870 /* C-comment: sv_tainted */
872 # This is just a big XS comment using sv_no
874 /* The following, is NOT an XS comment! */
875 # define SOMETHING_ELSE defgv + \
878 ---------------------------- file.xsr -----------------------------------------
881 a_string = "sv_undef"
883 #define SOMETHING PL_defgv
884 /* C-comment: sv_tainted */
886 # This is just a big XS comment using sv_no
888 /* The following, is NOT an XS comment! */
889 # define SOMETHING_ELSE PL_defgv + \
892 ===============================================================================
894 my $o = ppport(qw(--copy=f));
897 ok($o =~ /^Writing copy of.*\Q$_\E.*with changes/mi);
899 ok(eq_files("${_}f", "${_}r"));
903 ---------------------------- file.xs -----------------------------------------
905 #define NEED_sv_2pv_flags
906 #define NEED_vnewSVpvf
909 Perl_croak_nocontext("foo");
912 croak_nocontext("foo");
913 Perl_warner_nocontext("foo");
915 warner_nocontext("foo");
918 ---------------------------- file.xsr -----------------------------------------
920 #define NEED_sv_2pv_flags
921 #define NEED_vnewSVpvf
924 Perl_croak_nocontext("foo");
925 Perl_croak(aTHX_ "bar");
927 croak_nocontext("foo");
928 Perl_warner_nocontext("foo");
929 Perl_warner(aTHX_ "foo");
930 warner_nocontext("foo");