1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#!./perl
BEGIN {
if ($ENV{PERL_CORE}){
chdir('t') if -d 't';
if ($^O eq 'MacOS') {
@INC = qw(: ::lib ::macos:lib);
} else {
@INC = '.';
push @INC, '../lib';
}
} else {
unshift @INC, 't';
push @INC, "../../t";
}
require Config;
if (($Config::Config{'extensions'} !~ /\bB\b/) ){
print "1..0 # Skip -- Perl configured without B module\n";
exit 0;
}
require 'test.pl';
}
$| = 1;
use warnings;
use strict;
use Config;
use B::Showlex ();
plan tests => 15;
my $verbose = @ARGV; # set if ANY ARGS
my $a;
my $Is_VMS = $^O eq 'VMS';
my $Is_MacOS = $^O eq 'MacOS';
my $path = join " ", map { qq["-I$_"] } @INC;
$path = '"-I../lib" "-Iperl_root:[lib]"' if $Is_VMS; # gets too long otherwise
my $redir = $Is_MacOS ? "" : "2>&1";
my $is_thread = $Config{use5005threads} && $Config{use5005threads} eq 'define';
if ($is_thread) {
ok "# use5005threads: test skipped\n";
} else {
$a = `$^X $path "-MO=Showlex" -e "my \@one" $redir`;
like ($a, qr/sv_undef.*PVNV.*\@one.*sv_undef.*AV/s,
"canonical usage works");
}
# v1.01 tests
my ($na,$nb,$nc); # holds regex-strs
my ($out, $newlex); # output, option-flag
sub padrep {
my ($varname,$newlex) = @_;
return ($newlex)
? 'PVNV \(0x[0-9a-fA-F]+\) "\\'.$varname.'" = '
: "PVNV \\\(0x[0-9a-fA-F]+\\\) \\$varname\n";
}
for $newlex ('', '-newlex') {
$out = runperl ( switches => ["-MO=Showlex,$newlex"],
prog => 'my ($a,$b)', stderr => 1 );
$na = padrep('$a',$newlex);
$nb = padrep('$b',$newlex);
like ($out, qr/1: $na/ms, 'found $a in "my ($a,$b)"');
like ($out, qr/2: $nb/ms, 'found $b in "my ($a,$b)"');
print $out if $verbose;
SKIP: {
skip "no perlio in this build", 5
unless $Config::Config{useperlio};
our $buf = 'arb startval';
my $ak = B::Showlex::walk_output (\$buf);
my $walker = B::Showlex::compile( $newlex, sub{my($foo,$bar)} );
$walker->();
$na = padrep('$foo',$newlex);
$nb = padrep('$bar',$newlex);
like ($buf, qr/1: $na/ms, 'found $foo in "sub { my ($foo,$bar) }"');
like ($buf, qr/2: $nb/ms, 'found $bar in "sub { my ($foo,$bar) }"');
print $buf if $verbose;
$ak = B::Showlex::walk_output (\$buf);
my $src = 'sub { my ($scalar,@arr,%hash) }';
my $sub = eval $src;
$walker = B::Showlex::compile($sub);
$walker->();
$na = padrep('$scalar',$newlex);
$nb = padrep('@arr',$newlex);
$nc = padrep('%hash',$newlex);
like ($buf, qr/1: $na/ms, 'found $scalar in "'. $src .'"');
like ($buf, qr/2: $nb/ms, 'found @arr in "'. $src .'"');
like ($buf, qr/3: $nc/ms, 'found %hash in "'. $src .'"');
print $buf if $verbose;
# fibonacci function under test
my $asub = sub {
my ($self,%props)=@_;
my $total;
{ # inner block vars
my (@fib)=(1,2);
for (my $i=2; $i<10; $i++) {
$fib[$i] = $fib[$i-2] + $fib[$i-1];
}
for my $i(0..10) {
$total += $i;
}
}
};
$walker = B::Showlex::compile($asub, $newlex, -nosp);
$walker->();
print $buf if $verbose;
$walker = B::Concise::compile($asub, '-exec');
$walker->();
}
}
|