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