Commit | Line | Data |
87a42246 |
1 | #!./perl |
2 | |
3 | BEGIN { |
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 |
14 | use warnings; |
15 | use strict; |
16 | use Config; |
cc02ea56 |
17 | use B::Showlex (); |
87a42246 |
18 | |
cc02ea56 |
19 | plan tests => 8; |
87a42246 |
20 | |
cc02ea56 |
21 | my $verbose = @ARGV; # set if ANY ARGS |
87a42246 |
22 | |
23 | my $a; |
24 | my $Is_VMS = $^O eq 'VMS'; |
25 | my $Is_MacOS = $^O eq 'MacOS'; |
26 | |
27 | my $path = join " ", map { qq["-I$_"] } @INC; |
d0c1fe9a |
28 | $path = '"-I../lib" "-Iperl_root:[lib]"' if $Is_VMS; # gets too long otherwise |
87a42246 |
29 | my $redir = $Is_MacOS ? "" : "2>&1"; |
30 | my $is_thread = $Config{use5005threads} && $Config{use5005threads} eq 'define'; |
31 | |
32 | if ($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 | |
42 | my ($na,$nb,$nc); # holds regex-strs |
43 | sub padrep { |
44 | my $varname = shift; |
45 | return "PVNV \\\(0x[0-9a-fA-F]+\\\) \\$varname\n"; |
46 | } |
47 | |
48 | my $out = runperl ( switches => ["-MO=Showlex"], |
49 | prog => 'my ($a,$b)', stderr => 1 ); |
50 | $na = padrep('$a'); |
51 | $nb = padrep('$b'); |
52 | like ($out, qr/1: $na/ms, 'found $a in "my ($a,$b)"'); |
53 | like ($out, qr/2: $nb/ms, 'found $b in "my ($a,$b)"'); |
54 | |
55 | print $out if $verbose; |
56 | |
57 | our $buf = 'arb startval'; |
58 | my $ak = B::Showlex::walk_output (\$buf); |
59 | |
60 | my $walker = B::Showlex::compile(sub { my ($foo,$bar) }); |
61 | $walker->(); |
62 | $na = padrep('$foo'); |
63 | $nb = padrep('$bar'); |
64 | like ($buf, qr/1: $na/ms, 'found $foo in "sub { my ($foo,$bar) }"'); |
65 | like ($buf, qr/2: $nb/ms, 'found $bar in "sub { my ($foo,$bar) }"'); |
66 | |
67 | print $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'); |
76 | like ($buf, qr/1: $na/ms, 'found $scalar in "sub { my ($scalar,@arr,%hash) }"'); |
77 | like ($buf, qr/2: $nb/ms, 'found @arr in "sub { my ($scalar,@arr,%hash) }"'); |
78 | like ($buf, qr/3: $nc/ms, 'found %hash in "sub { my ($scalar,@arr,%hash) }"'); |
79 | |
80 | print $buf if $verbose; |
81 | |
82 | my $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 | |
102 | print $buf if $verbose; |