Eviscerate README.macos to match the state of the world
[p5sagit/p5-mst-13.2.git] / ext / B / t / showlex.t
CommitLineData
87a42246 1#!./perl
2
3BEGIN {
74517a3a 4 unshift @INC, 't';
9cd8f857 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 11}
12
cc02ea56 13$| = 1;
87a42246 14use warnings;
15use strict;
16use Config;
cc02ea56 17use B::Showlex ();
87a42246 18
59910b6d 19plan tests => 15;
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
59910b6d 42my ($na,$nb,$nc); # holds regex-strs
43my ($out, $newlex); # output, option-flag
44
cc02ea56 45sub padrep {
59910b6d 46 my ($varname,$newlex) = @_;
47 return ($newlex)
48 ? 'PVNV \(0x[0-9a-fA-F]+\) "\\'.$varname.'" = '
49 : "PVNV \\\(0x[0-9a-fA-F]+\\\) \\$varname\n";
cc02ea56 50}
51
59910b6d 52for $newlex ('', '-newlex') {
53
54 $out = runperl ( switches => ["-MO=Showlex,$newlex"],
55 prog => 'my ($a,$b)', stderr => 1 );
56 $na = padrep('$a',$newlex);
57 $nb = padrep('$b',$newlex);
58 like ($out, qr/1: $na/ms, 'found $a in "my ($a,$b)"');
59 like ($out, qr/2: $nb/ms, 'found $b in "my ($a,$b)"');
cc02ea56 60
59910b6d 61 print $out if $verbose;
cc02ea56 62
e77e2f14 63SKIP: {
64 skip "no perlio in this build", 5
65 unless $Config::Config{useperlio};
66
59910b6d 67 our $buf = 'arb startval';
68 my $ak = B::Showlex::walk_output (\$buf);
69
70 my $walker = B::Showlex::compile( $newlex, sub{my($foo,$bar)} );
71 $walker->();
72 $na = padrep('$foo',$newlex);
73 $nb = padrep('$bar',$newlex);
74 like ($buf, qr/1: $na/ms, 'found $foo in "sub { my ($foo,$bar) }"');
75 like ($buf, qr/2: $nb/ms, 'found $bar in "sub { my ($foo,$bar) }"');
76
77 print $buf if $verbose;
78
79 $ak = B::Showlex::walk_output (\$buf);
80
81 my $src = 'sub { my ($scalar,@arr,%hash) }';
82 my $sub = eval $src;
83 $walker = B::Showlex::compile($sub);
84 $walker->();
85 $na = padrep('$scalar',$newlex);
86 $nb = padrep('@arr',$newlex);
87 $nc = padrep('%hash',$newlex);
88 like ($buf, qr/1: $na/ms, 'found $scalar in "'. $src .'"');
89 like ($buf, qr/2: $nb/ms, 'found @arr in "'. $src .'"');
90 like ($buf, qr/3: $nc/ms, 'found %hash in "'. $src .'"');
91
92 print $buf if $verbose;
93
94 # fibonacci function under test
95 my $asub = sub {
96 my ($self,%props)=@_;
97 my $total;
98 { # inner block vars
99 my (@fib)=(1,2);
100 for (my $i=2; $i<10; $i++) {
101 $fib[$i] = $fib[$i-2] + $fib[$i-1];
102 }
103 for my $i(0..10) {
104 $total += $i;
105 }
cc02ea56 106 }
59910b6d 107 };
108 $walker = B::Showlex::compile($asub, $newlex, -nosp);
109 $walker->();
110 print $buf if $verbose;
cc02ea56 111
59910b6d 112 $walker = B::Concise::compile($asub, '-exec');
113 $walker->();
e77e2f14 114
115}
59910b6d 116}