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'}) {
50 $inc = '-I../../lib' if -d '../../lib';
52 if ($perl =~ m!^\./!) {
57 chdir("..") if !-d $tmp && -d "../$tmp";
61 ok(&Devel::PPPort::WriteFile("ppport.h"));
66 print "# *** running $perl $inc ppport.h @args ***\n";
67 my $out = join '', `$perl $inc ppport.h @args`;
76 my($str, $re, $mod) = @_;
78 eval "\@n = \$str =~ /$re/g$mod;";
81 $err =~ s/^/# *** /mg;
82 print "# *** ERROR ***\n$err\n";
84 return $@ ? -42 : scalar @n;
90 return 0 unless -e $f1 && -e $f2;
95 print "# couldn't open $_: $!\n";
98 $_ = do { local $/; <F> };
101 $copy =~ s/^/# | /mg;
109 for (split /\s*={70,}\s*/, do { local $/; <DATA> }) {
112 ($c, @f{m/-{20,}\s+(\S+)\s+-{20,}/g}) = split /\s*-{20,}\s+\S+\s+-{20,}\s*/;
113 push @tests, { code => $c, files => \%f };
119 for $f (keys %{$t->{files}}) {
120 my @f = split /\//, $f;
123 my $path = join '/', @f;
124 mkpath($path) or die "mkpath('$path'): $!\n";
126 my $txt = $t->{files}{$f};
128 open F, ">$f" or die "open $f: $!\n";
132 print "# *** writing $f ***\n$txt\n";
138 $err =~ s/^/# *** /mg;
139 print "# *** ERROR ***\n$err\n";
143 for (keys %{$t->{files}}) {
144 unlink $_ or die "unlink('$_'): $!\n";
152 return $perl if $^O eq 'VMS';
154 my $exe = $Config{'_exe'} || '';
156 if ($perl =~ /^perl\Q$exe\E$/i) {
158 eval "require File::Spec";
162 $perl = File::Spec->catfile(File::Spec->curdir(), $perl);
166 if ($perl !~ /\Q$exe\E$/i) {
170 warn "find_perl: cannot find $perl from $^X" unless -f $perl;
177 my $o = ppport(qw(--help));
178 ok($o =~ /^Usage:.*ppport\.h/m);
181 $o = ppport(qw(--nochanges));
182 ok($o =~ /^scanning.*test\.xs/mi);
183 ok($o =~ /analyzing.*test\.xs/mi);
184 ok(matches($o, '^scanning', 'mi'), 1);
185 ok(matches($o, 'analyzing', 'mi'), 1);
186 ok($o =~ /Uses Perl_newSViv instead of newSViv/);
188 $o = ppport(qw(--quiet --nochanges));
191 ---------------------------- test.xs ------------------------------------------
195 ===============================================================================
197 # check if C and C++ comments are filtered correctly
199 my $o = ppport(qw(--copy=a));
200 ok($o =~ /^scanning.*MyExt\.xs/mi);
201 ok($o =~ /analyzing.*MyExt\.xs/mi);
202 ok(matches($o, '^scanning', 'mi'), 1);
203 ok($o =~ /^Needs to include.*ppport\.h/m);
204 ok($o !~ /^Uses grok_bin/m);
205 ok($o !~ /^Uses newSVpv/m);
206 ok($o =~ /Uses 1 C\+\+ style comment/m);
207 ok(eq_files('MyExt.xsa', 'MyExt.ra'));
209 # check if C++ are left untouched with --cplusplus
211 $o = ppport(qw(--copy=b --cplusplus));
212 ok($o =~ /^scanning.*MyExt\.xs/mi);
213 ok($o =~ /analyzing.*MyExt\.xs/mi);
214 ok(matches($o, '^scanning', 'mi'), 1);
215 ok($o =~ /^Needs to include.*ppport\.h/m);
216 ok($o !~ /^Uses grok_bin/m);
217 ok($o !~ /^Uses newSVpv/m);
218 ok($o !~ /Uses \d+ C\+\+ style comment/m);
219 ok(eq_files('MyExt.xsb', 'MyExt.rb'));
221 unlink qw(MyExt.xsa MyExt.xsb);
223 ---------------------------- MyExt.xs -----------------------------------------
230 ---------------------------- MyExt.ra -----------------------------------------
238 ---------------------------- MyExt.rb -----------------------------------------
246 ===============================================================================
248 my $o = ppport(qw(--nochanges file1.xs));
249 ok($o =~ /^scanning.*file1\.xs/mi);
250 ok($o =~ /analyzing.*file1\.xs/mi);
251 ok($o !~ /^scanning.*file2\.xs/mi);
252 ok($o =~ /^Uses newCONSTSUB/m);
253 ok($o =~ /^Uses SvPV_nolen.*depends.*sv_2pv_nolen/m);
254 ok($o =~ /hint for newCONSTSUB/m);
255 ok($o !~ /hint for sv_2pv_nolen/m);
256 ok($o =~ /^Looks good/m);
258 $o = ppport(qw(--nochanges --nohints file1.xs));
259 ok($o =~ /^scanning.*file1\.xs/mi);
260 ok($o =~ /analyzing.*file1\.xs/mi);
261 ok($o !~ /^scanning.*file2\.xs/mi);
262 ok($o =~ /^Uses newCONSTSUB/m);
263 ok($o =~ /^Uses SvPV_nolen.*depends.*sv_2pv_nolen/m);
264 ok($o !~ /hint for newCONSTSUB/m);
265 ok($o !~ /hint for sv_2pv_nolen/m);
266 ok($o =~ /^Looks good/m);
268 $o = ppport(qw(--nochanges --nohints --nodiag file1.xs));
269 ok($o =~ /^scanning.*file1\.xs/mi);
270 ok($o =~ /analyzing.*file1\.xs/mi);
271 ok($o !~ /^scanning.*file2\.xs/mi);
272 ok($o !~ /^Uses newCONSTSUB/m);
273 ok($o !~ /^Uses SvPV_nolen/m);
274 ok($o !~ /hint for newCONSTSUB/m);
275 ok($o !~ /hint for sv_2pv_nolen/m);
276 ok($o =~ /^Looks good/m);
278 $o = ppport(qw(--nochanges --quiet file1.xs));
281 $o = ppport(qw(--nochanges file2.xs));
282 ok($o =~ /^scanning.*file2\.xs/mi);
283 ok($o =~ /analyzing.*file2\.xs/mi);
284 ok($o !~ /^scanning.*file1\.xs/mi);
285 ok($o =~ /^Uses mXPUSHp/m);
286 ok($o =~ /^Needs to include.*ppport\.h/m);
287 ok($o !~ /^Looks good/m);
288 ok($o =~ /^1 potentially required change detected/m);
290 $o = ppport(qw(--nochanges --nohints file2.xs));
291 ok($o =~ /^scanning.*file2\.xs/mi);
292 ok($o =~ /analyzing.*file2\.xs/mi);
293 ok($o !~ /^scanning.*file1\.xs/mi);
294 ok($o =~ /^Uses mXPUSHp/m);
295 ok($o =~ /^Needs to include.*ppport\.h/m);
296 ok($o !~ /^Looks good/m);
297 ok($o =~ /^1 potentially required change detected/m);
299 $o = ppport(qw(--nochanges --nohints --nodiag file2.xs));
300 ok($o =~ /^scanning.*file2\.xs/mi);
301 ok($o =~ /analyzing.*file2\.xs/mi);
302 ok($o !~ /^scanning.*file1\.xs/mi);
303 ok($o !~ /^Uses mXPUSHp/m);
304 ok($o !~ /^Needs to include.*ppport\.h/m);
305 ok($o !~ /^Looks good/m);
306 ok($o =~ /^1 potentially required change detected/m);
308 $o = ppport(qw(--nochanges --quiet file2.xs));
311 ---------------------------- file1.xs -----------------------------------------
313 #define NEED_newCONSTSUB
314 #define NEED_sv_2pv_nolen
320 ---------------------------- file2.xs -----------------------------------------
324 ===============================================================================
326 my $o = ppport(qw(--nochanges));
327 ok($o =~ /^scanning.*FooBar\.xs/mi);
328 ok($o =~ /analyzing.*FooBar\.xs/mi);
329 ok(matches($o, '^scanning', 'mi'), 1);
330 ok($o !~ /^Looks good/m);
331 ok($o =~ /^Uses grok_bin/m);
333 ---------------------------- FooBar.xs ----------------------------------------
339 ===============================================================================
341 my $o = ppport(qw(--nochanges));
342 ok($o =~ /^scanning.*First\.xs/mi);
343 ok($o =~ /analyzing.*First\.xs/mi);
344 ok($o =~ /^scanning.*second\.h/mi);
345 ok($o =~ /analyzing.*second\.h/mi);
346 ok($o =~ /^scanning.*sub.*third\.c/mi);
347 ok($o =~ /analyzing.*sub.*third\.c/mi);
348 ok($o !~ /^scanning.*foobar/mi);
349 ok(matches($o, '^scanning', 'mi'), 3);
351 ---------------------------- First.xs -----------------------------------------
355 ---------------------------- foobar.xyz ---------------------------------------
359 ---------------------------- second.h -----------------------------------------
363 ---------------------------- sub/third.c --------------------------------------
367 ===============================================================================
369 my $o = ppport(qw(--nochanges));
370 ok($o =~ /Possibly wrong #define NEED_foobar in.*test.xs/i);
372 ---------------------------- test.xs ------------------------------------------
376 ===============================================================================
378 # And now some complex "real-world" example
380 my $o = ppport(qw(--copy=f));
381 for (qw(main.xs mod1.c mod2.c mod3.c mod4.c mod5.c)) {
382 ok($o =~ /^scanning.*\Q$_\E/mi);
383 ok($o =~ /analyzing.*\Q$_\E/i);
385 ok(matches($o, '^scanning', 'mi'), 6);
387 ok(matches($o, '^Writing copy of', 'mi'), 5);
390 for (qw(main.xs mod1.c mod2.c mod3.c mod4.c)) {
391 ok($o =~ /^Writing copy of.*\Q$_\E.*with changes/mi);
393 ok(eq_files("${_}f", "${_}r"));
397 ---------------------------- main.xs ------------------------------------------
403 #define NEED_newCONSTSUB
404 #define NEED_grok_hex_GLOBAL
409 Perl_grok_bin(aTHX_ foo, bar);
415 Perl_grok_bin(bar, sv_no);
417 ---------------------------- mod1.c -------------------------------------------
423 #define NEED_grok_bin_GLOBAL
424 #define NEED_newCONSTSUB
431 Perl_sv_catpvf(); /* I know it's wrong ;-) */
434 ---------------------------- mod2.c -------------------------------------------
449 ---------------------------- mod3.c -------------------------------------------
458 ---------------------------- mod4.c -------------------------------------------
466 ---------------------------- mod5.c -------------------------------------------
475 ---------------------------- main.xsr -----------------------------------------
481 #define NEED_eval_pv_GLOBAL
482 #define NEED_grok_hex
483 #define NEED_newCONSTSUB_GLOBAL
494 grok_bin(bar, PL_sv_no);
496 ---------------------------- mod1.cr ------------------------------------------
502 #define NEED_grok_bin_GLOBAL
508 Perl_croak (aTHX_ "foo");
509 Perl_sv_catpvf(aTHX); /* I know it's wrong ;-) */
512 ---------------------------- mod2.cr ------------------------------------------
525 ---------------------------- mod3.cr ------------------------------------------
530 #define NEED_grok_oct
536 ---------------------------- mod4.cr ------------------------------------------
545 ===============================================================================
547 my $o = ppport(qw(--nochanges));
548 ok($o =~ /Uses grok_hex/m);
549 ok($o !~ /Looks good/m);
551 $o = ppport(qw(--nochanges --compat-version=5.8.0));
552 ok($o !~ /Uses grok_hex/m);
553 ok($o =~ /Looks good/m);
555 ---------------------------- FooBar.xs ----------------------------------------
559 ===============================================================================
561 my $o = ppport(qw(--nochanges));
562 ok($o =~ /Uses SvPVutf8_force, which may not be portable/m);
564 $o = ppport(qw(--nochanges --compat-version=5.6.0));
565 ok($o !~ /Uses SvPVutf8_force/m);
567 ---------------------------- FooBar.xs ----------------------------------------
571 ===============================================================================
573 my $o = ppport(qw(--nochanges));
574 ok($o !~ /potentially required change/);
575 ok(matches($o, '^Looks good', 'mi'), 2);
577 ---------------------------- FooBar.xs ----------------------------------------
579 #define NEED_grok_numeric_radix
580 #define NEED_grok_number
583 GROK_NUMERIC_RADIX();
586 ---------------------------- foo.c --------------------------------------------