Re: more B::Concise stuff (PATCH - updated)
[p5sagit/p5-mst-13.2.git] / ext / B / t / showlex.t
CommitLineData
87a42246 1#!./perl
2
3BEGIN {
88587957 4 chdir 't' if -d 't';
87a42246 5 if ($^O eq 'MacOS') {
6 @INC = qw(: ::lib ::macos:lib);
88587957 7 } else {
8 @INC = '../lib';
87a42246 9 }
cc02ea56 10 require './test.pl';
87a42246 11}
12
cc02ea56 13$| = 1;
87a42246 14use warnings;
15use strict;
16use Config;
cc02ea56 17use B::Showlex ();
87a42246 18
cc02ea56 19plan tests => 8;
87a42246 20
cc02ea56 21my $verbose = @ARGV; # set if ANY ARGS
87a42246 22
23my $a;
24my $Is_VMS = $^O eq 'VMS';
25my $Is_MacOS = $^O eq 'MacOS';
26
27my $path = join " ", map { qq["-I$_"] } @INC;
d0c1fe9a 28$path = '"-I../lib" "-Iperl_root:[lib]"' if $Is_VMS; # gets too long otherwise
87a42246 29my $redir = $Is_MacOS ? "" : "2>&1";
30my $is_thread = $Config{use5005threads} && $Config{use5005threads} eq 'define';
31
32if ($is_thread) {
cc02ea56 33 ok "# use5005threads: test skipped\n";
87a42246 34} else {
56034a21 35 $a = `$^X $path "-MO=Showlex" -e "my \@one" $redir`;
cc02ea56 36 like ($a, qr/sv_undef.*PVNV.*\@one.*sv_undef.*AV/s,
37 "canonical usage works");
87a42246 38}
cc02ea56 39
40# v1.01 tests
41
42my ($na,$nb,$nc); # holds regex-strs
43sub padrep {
44 my $varname = shift;
45 return "PVNV \\\(0x[0-9a-fA-F]+\\\) \\$varname\n";
46}
47
48my $out = runperl ( switches => ["-MO=Showlex"],
49 prog => 'my ($a,$b)', stderr => 1 );
50$na = padrep('$a');
51$nb = padrep('$b');
52like ($out, qr/1: $na/ms, 'found $a in "my ($a,$b)"');
53like ($out, qr/2: $nb/ms, 'found $b in "my ($a,$b)"');
54
55print $out if $verbose;
56
57our $buf = 'arb startval';
58my $ak = B::Showlex::walk_output (\$buf);
59
60my $walker = B::Showlex::compile(sub { my ($foo,$bar) });
61$walker->();
62$na = padrep('$foo');
63$nb = padrep('$bar');
64like ($buf, qr/1: $na/ms, 'found $foo in "sub { my ($foo,$bar) }"');
65like ($buf, qr/2: $nb/ms, 'found $bar in "sub { my ($foo,$bar) }"');
66
67print $buf if $verbose;
68
69$ak = B::Showlex::walk_output (\$buf);
70
71$walker = B::Showlex::compile(sub { my ($scalar,@arr,%hash) });
72$walker->();
73$na = padrep('$scalar');
74$nb = padrep('@arr');
75$nc = padrep('%hash');
76like ($buf, qr/1: $na/ms, 'found $scalar in "sub { my ($scalar,@arr,%hash) }"');
77like ($buf, qr/2: $nb/ms, 'found @arr in "sub { my ($scalar,@arr,%hash) }"');
78like ($buf, qr/3: $nc/ms, 'found %hash in "sub { my ($scalar,@arr,%hash) }"');
79
80print $buf if $verbose;
81
82my $asub = sub {
83 my ($self,%props)=@_;
84 my $total;
85 { # inner block vars
86 my (@fib)=(1,2);
87 for (my $i=2; $i<10; $i++) {
88 $fib[$i] = $fib[$i-2] + $fib[$i-1];
89 }
90 for my $i(0..10) {
91 $total += $i;
92 }
93 }
94};
95$walker = B::Showlex::compile($asub, '-newlex');
96$walker->();
97
98$walker = B::Concise::compile($asub, '-exec');
99$walker->();
100
101
102print $buf if $verbose;