1 ################################################################################
3 # !!!!! Do NOT edit this file directly! !!!!!
5 # Edit mktests.PL and/or parts/inc/ppphtest instead.
7 ################################################################################
10 if ($ENV{'PERL_CORE'}) {
12 @INC = ('../lib', '../ext/Devel/PPPort/t') if -d '../lib' && -d '../ext';
13 require Config; import Config;
15 if (" $Config{'extensions'} " !~ m[ Devel/PPPort ]) {
16 print "1..0 # Skip -- Perl configured without Devel::PPPort module\n";
26 require 'testutil.pl';
38 use File::Path qw/rmtree mkpath/;
43 my $perl = find_perl();
45 rmtree($tmp) if -d $tmp;
46 mkpath($tmp) or die "mkpath $tmp: $!\n";
47 chdir($tmp) or die "chdir $tmp: $!\n";
49 if ($ENV{'PERL_CORE'}) {
51 $inc = $^O eq 'VMS' ? '-"I../../lib"' : '-I../../lib';
52 unshift @INC, '../../lib';
55 if ($perl =~ m!^\./!) {
60 chdir('..') if !-d $tmp && -d "../$tmp";
61 rmtree($tmp) if -d $tmp;
64 ok(&Devel::PPPort::WriteFile("ppport.h"));
69 print "# *** running $perl $inc ppport.h @args ***\n";
70 my $out = join '', `$perl $inc ppport.h @args`;
79 my($str, $re, $mod) = @_;
81 eval "\@n = \$str =~ /$re/g$mod;";
84 $err =~ s/^/# *** /mg;
85 print "# *** ERROR ***\n$err\n";
87 return $@ ? -42 : scalar @n;
93 return 0 unless -e $f1 && -e $f2;
98 print "# couldn't open $_: $!\n";
101 $_ = do { local $/; <F> };
104 $copy =~ s/^/# | /mg;
112 for (split /\s*={70,}\s*/, do { local $/; <DATA> }) {
115 ($c, @f{m/-{20,}\s+(\S+)\s+-{20,}/g}) = split /\s*-{20,}\s+\S+\s+-{20,}\s*/;
116 push @tests, { code => $c, files => \%f };
122 for $f (keys %{$t->{files}}) {
123 my @f = split /\//, $f;
126 my $path = join '/', @f;
127 mkpath($path) or die "mkpath('$path'): $!\n";
129 my $txt = $t->{files}{$f};
131 open F, ">$f" or die "open $f: $!\n";
135 print "# *** writing $f ***\n$txt\n";
141 $err =~ s/^/# *** /mg;
142 print "# *** ERROR ***\n$err\n";
146 for (keys %{$t->{files}}) {
147 unlink $_ or die "unlink('$_'): $!\n";
155 return $perl if $^O eq 'VMS';
157 my $exe = $Config{'_exe'} || '';
159 if ($perl =~ /^perl\Q$exe\E$/i) {
161 eval "require File::Spec";
165 $perl = File::Spec->catfile(File::Spec->curdir(), $perl);
169 if ($perl !~ /\Q$exe\E$/i) {
173 warn "find_perl: cannot find $perl from $^X" unless -f $perl;
180 my $o = ppport(qw(--help));
181 ok($o =~ /^Usage:.*ppport\.h/m);
184 $o = ppport(qw(--nochanges));
185 ok($o =~ /^scanning.*test\.xs/mi);
186 ok($o =~ /analyzing.*test\.xs/mi);
187 ok(matches($o, '^scanning', 'mi'), 1);
188 ok(matches($o, 'analyzing', 'mi'), 1);
189 ok($o =~ /Uses Perl_newSViv instead of newSViv/);
191 $o = ppport(qw(--quiet --nochanges));
194 ---------------------------- test.xs ------------------------------------------
198 ===============================================================================
200 # check if C and C++ comments are filtered correctly
202 my $o = ppport(qw(--copy=a));
203 ok($o =~ /^scanning.*MyExt\.xs/mi);
204 ok($o =~ /analyzing.*MyExt\.xs/mi);
205 ok(matches($o, '^scanning', 'mi'), 1);
206 ok($o =~ /^Needs to include.*ppport\.h/m);
207 ok($o !~ /^Uses grok_bin/m);
208 ok($o !~ /^Uses newSVpv/m);
209 ok($o =~ /Uses 1 C\+\+ style comment/m);
210 ok(eq_files('MyExt.xsa', 'MyExt.ra'));
212 # check if C++ are left untouched with --cplusplus
214 $o = ppport(qw(--copy=b --cplusplus));
215 ok($o =~ /^scanning.*MyExt\.xs/mi);
216 ok($o =~ /analyzing.*MyExt\.xs/mi);
217 ok(matches($o, '^scanning', 'mi'), 1);
218 ok($o =~ /^Needs to include.*ppport\.h/m);
219 ok($o !~ /^Uses grok_bin/m);
220 ok($o !~ /^Uses newSVpv/m);
221 ok($o !~ /Uses \d+ C\+\+ style comment/m);
222 ok(eq_files('MyExt.xsb', 'MyExt.rb'));
224 unlink qw(MyExt.xsa MyExt.xsb);
226 ---------------------------- MyExt.xs -----------------------------------------
233 ---------------------------- MyExt.ra -----------------------------------------
241 ---------------------------- MyExt.rb -----------------------------------------
249 ===============================================================================
251 my $o = ppport(qw(--nochanges file1.xs));
252 ok($o =~ /^scanning.*file1\.xs/mi);
253 ok($o =~ /analyzing.*file1\.xs/mi);
254 ok($o !~ /^scanning.*file2\.xs/mi);
255 ok($o =~ /^Uses newCONSTSUB/m);
256 ok($o =~ /^Uses SvPV_nolen.*depends.*sv_2pv_nolen/m);
257 ok($o =~ /hint for newCONSTSUB/m);
258 ok($o !~ /hint for sv_2pv_nolen/m);
259 ok($o =~ /^Looks good/m);
261 $o = ppport(qw(--nochanges --nohints file1.xs));
262 ok($o =~ /^scanning.*file1\.xs/mi);
263 ok($o =~ /analyzing.*file1\.xs/mi);
264 ok($o !~ /^scanning.*file2\.xs/mi);
265 ok($o =~ /^Uses newCONSTSUB/m);
266 ok($o =~ /^Uses SvPV_nolen.*depends.*sv_2pv_nolen/m);
267 ok($o !~ /hint for newCONSTSUB/m);
268 ok($o !~ /hint for sv_2pv_nolen/m);
269 ok($o =~ /^Looks good/m);
271 $o = ppport(qw(--nochanges --nohints --nodiag file1.xs));
272 ok($o =~ /^scanning.*file1\.xs/mi);
273 ok($o =~ /analyzing.*file1\.xs/mi);
274 ok($o !~ /^scanning.*file2\.xs/mi);
275 ok($o !~ /^Uses newCONSTSUB/m);
276 ok($o !~ /^Uses SvPV_nolen/m);
277 ok($o !~ /hint for newCONSTSUB/m);
278 ok($o !~ /hint for sv_2pv_nolen/m);
279 ok($o =~ /^Looks good/m);
281 $o = ppport(qw(--nochanges --quiet file1.xs));
284 $o = ppport(qw(--nochanges file2.xs));
285 ok($o =~ /^scanning.*file2\.xs/mi);
286 ok($o =~ /analyzing.*file2\.xs/mi);
287 ok($o !~ /^scanning.*file1\.xs/mi);
288 ok($o =~ /^Uses mXPUSHp/m);
289 ok($o =~ /^Needs to include.*ppport\.h/m);
290 ok($o !~ /^Looks good/m);
291 ok($o =~ /^1 potentially required change detected/m);
293 $o = ppport(qw(--nochanges --nohints file2.xs));
294 ok($o =~ /^scanning.*file2\.xs/mi);
295 ok($o =~ /analyzing.*file2\.xs/mi);
296 ok($o !~ /^scanning.*file1\.xs/mi);
297 ok($o =~ /^Uses mXPUSHp/m);
298 ok($o =~ /^Needs to include.*ppport\.h/m);
299 ok($o !~ /^Looks good/m);
300 ok($o =~ /^1 potentially required change detected/m);
302 $o = ppport(qw(--nochanges --nohints --nodiag file2.xs));
303 ok($o =~ /^scanning.*file2\.xs/mi);
304 ok($o =~ /analyzing.*file2\.xs/mi);
305 ok($o !~ /^scanning.*file1\.xs/mi);
306 ok($o !~ /^Uses mXPUSHp/m);
307 ok($o !~ /^Needs to include.*ppport\.h/m);
308 ok($o !~ /^Looks good/m);
309 ok($o =~ /^1 potentially required change detected/m);
311 $o = ppport(qw(--nochanges --quiet file2.xs));
314 ---------------------------- file1.xs -----------------------------------------
316 #define NEED_newCONSTSUB
317 #define NEED_sv_2pv_nolen
323 ---------------------------- file2.xs -----------------------------------------
327 ===============================================================================
329 my $o = ppport(qw(--nochanges));
330 ok($o =~ /^scanning.*FooBar\.xs/mi);
331 ok($o =~ /analyzing.*FooBar\.xs/mi);
332 ok(matches($o, '^scanning', 'mi'), 1);
333 ok($o !~ /^Looks good/m);
334 ok($o =~ /^Uses grok_bin/m);
336 ---------------------------- FooBar.xs ----------------------------------------
342 ===============================================================================
344 my $o = ppport(qw(--nochanges));
345 ok($o =~ /^scanning.*First\.xs/mi);
346 ok($o =~ /analyzing.*First\.xs/mi);
347 ok($o =~ /^scanning.*second\.h/mi);
348 ok($o =~ /analyzing.*second\.h/mi);
349 ok($o =~ /^scanning.*sub.*third\.c/mi);
350 ok($o =~ /analyzing.*sub.*third\.c/mi);
351 ok($o !~ /^scanning.*foobar/mi);
352 ok(matches($o, '^scanning', 'mi'), 3);
354 ---------------------------- First.xs -----------------------------------------
358 ---------------------------- foobar.xyz ---------------------------------------
362 ---------------------------- second.h -----------------------------------------
366 ---------------------------- sub/third.c --------------------------------------
370 ===============================================================================
372 my $o = ppport(qw(--nochanges));
373 ok($o =~ /Possibly wrong #define NEED_foobar in.*test.xs/i);
375 ---------------------------- test.xs ------------------------------------------
379 ===============================================================================
381 # And now some complex "real-world" example
383 my $o = ppport(qw(--copy=f));
384 for (qw(main.xs mod1.c mod2.c mod3.c mod4.c mod5.c)) {
385 ok($o =~ /^scanning.*\Q$_\E/mi);
386 ok($o =~ /analyzing.*\Q$_\E/i);
388 ok(matches($o, '^scanning', 'mi'), 6);
390 ok(matches($o, '^Writing copy of', 'mi'), 5);
393 for (qw(main.xs mod1.c mod2.c mod3.c mod4.c)) {
394 ok($o =~ /^Writing copy of.*\Q$_\E.*with changes/mi);
396 ok(eq_files("${_}f", "${_}r"));
400 ---------------------------- main.xs ------------------------------------------
406 #define NEED_newCONSTSUB
407 #define NEED_grok_hex_GLOBAL
412 Perl_grok_bin(aTHX_ foo, bar);
418 Perl_grok_bin(bar, sv_no);
420 ---------------------------- mod1.c -------------------------------------------
426 #define NEED_grok_bin_GLOBAL
427 #define NEED_newCONSTSUB
434 Perl_sv_catpvf(); /* I know it's wrong ;-) */
437 ---------------------------- mod2.c -------------------------------------------
452 ---------------------------- mod3.c -------------------------------------------
461 ---------------------------- mod4.c -------------------------------------------
469 ---------------------------- mod5.c -------------------------------------------
478 ---------------------------- main.xsr -----------------------------------------
484 #define NEED_eval_pv_GLOBAL
485 #define NEED_grok_hex
486 #define NEED_newCONSTSUB_GLOBAL
497 grok_bin(bar, PL_sv_no);
499 ---------------------------- mod1.cr ------------------------------------------
505 #define NEED_grok_bin_GLOBAL
511 Perl_croak (aTHX_ "foo");
512 Perl_sv_catpvf(aTHX); /* I know it's wrong ;-) */
515 ---------------------------- mod2.cr ------------------------------------------
528 ---------------------------- mod3.cr ------------------------------------------
533 #define NEED_grok_oct
539 ---------------------------- mod4.cr ------------------------------------------
548 ===============================================================================
550 my $o = ppport(qw(--nochanges));
551 ok($o =~ /Uses grok_hex/m);
552 ok($o !~ /Looks good/m);
554 $o = ppport(qw(--nochanges --compat-version=5.8.0));
555 ok($o !~ /Uses grok_hex/m);
556 ok($o =~ /Looks good/m);
558 ---------------------------- FooBar.xs ----------------------------------------
562 ===============================================================================
564 my $o = ppport(qw(--nochanges));
565 ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
567 $o = ppport(qw(--nochanges --compat-version=5.6.0));
568 ok($o !~ /Uses SvPVutf8_force/m);
570 ---------------------------- FooBar.xs ----------------------------------------
574 ===============================================================================
576 my $o = ppport(qw(--nochanges));
577 ok($o !~ /potentially required change/);
578 ok(matches($o, '^Looks good', 'mi'), 2);
580 ---------------------------- FooBar.xs ----------------------------------------
582 #define NEED_grok_numeric_radix
583 #define NEED_grok_number
586 GROK_NUMERIC_RADIX();
589 ---------------------------- foo.c --------------------------------------------