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