xref: /openbsd-src/gnu/usr.bin/perl/ext/XS-APItest/t/peep.t (revision 898184e3e61f9129feb5978fad5a8c6865f00b92)
1*898184e3Ssthen#!perl
2*898184e3Ssthen
3*898184e3Ssthenuse strict;
4*898184e3Ssthenuse warnings;
5*898184e3Ssthenuse Test::More tests => 6;
6*898184e3Ssthen
7*898184e3Ssthenuse XS::APItest;
8*898184e3Ssthen
9*898184e3Ssthenmy $record = XS::APItest::peep_record;
10*898184e3Ssthenmy $rrecord = XS::APItest::rpeep_record;
11*898184e3Ssthen
12*898184e3Ssthen# our peep got called and remembered the string constant
13*898184e3SsthenXS::APItest::peep_enable;
14*898184e3Sstheneval q[my $foo = q/affe/];
15*898184e3SsthenXS::APItest::peep_disable;
16*898184e3Ssthen
17*898184e3Ssthenis(scalar @{ $record }, 1);
18*898184e3Ssthenis(scalar @{ $rrecord }, 1);
19*898184e3Ssthenis($record->[0], 'affe');
20*898184e3Ssthenis($rrecord->[0], 'affe');
21*898184e3Ssthen
22*898184e3Ssthen
23*898184e3Ssthen# A deep-enough nesting of conditionals defeats the deferring mechanism
24*898184e3Ssthen# and triggers recursion. Note that this test is sensitive to the details
25*898184e3Ssthen# rpeep: the main thing it is testing is that rpeep is called more than
26*898184e3Ssthen# peep, and that all branches are covered; the order of branch calling is
27*898184e3Ssthen# less important.
28*898184e3Ssthen
29*898184e3Ssthenmy $code =  q[my ($a,$b); $a =];
30*898184e3Ssthen$code .= qq{ \$b ? "foo$_" :} for (1..10);
31*898184e3Ssthen$code .= qq{ "foo11" };
32*898184e3SsthenXS::APItest::peep_enable;
33*898184e3Sstheneval $code;
34*898184e3SsthenXS::APItest::peep_disable;
35*898184e3Ssthen
36*898184e3Ssthenis_deeply($record,  [ "foo11" ]);
37*898184e3Ssthenis_deeply($rrecord, [
38*898184e3Ssthen    qw(foo1 foo2 foo3 foo4 foo5 foo6 foo10 foo9 foo8 foo7 foo11) ]);
39