Commit | Line | Data |
---|---|---|
ccc418af GS |
1 | #!./perl |
2 | ||
3 | BEGIN { | |
4 | chdir 't' if -d 't'; | |
20822f61 | 5 | @INC = '../lib'; |
ccc418af GS |
6 | } |
7 | ||
8 | $| = 1; | |
9 | use warnings; | |
10 | use strict; | |
11 | use Config; | |
12 | ||
1e1dbab6 | 13 | print "1..17\n"; |
ccc418af GS |
14 | |
15 | my $test = 1; | |
16 | ||
17 | sub ok { print "ok $test\n"; $test++ } | |
18 | ||
19 | use B::Deparse; | |
20 | my $deparse = B::Deparse->new() or print "not "; | |
21 | ok; | |
22 | ||
23 | print "not " if "{\n 1;\n}" ne $deparse->coderef2text(sub {1}); | |
24 | ok; | |
25 | ||
26 | print "not " if "{\n '???';\n 2;\n}" ne | |
27 | $deparse->coderef2text(sub {1;2}); | |
28 | ok; | |
29 | ||
30 | print "not " if "{\n \$test /= 2 if ++\$test;\n}" ne | |
31 | $deparse->coderef2text(sub {++$test and $test/=2;}); | |
32 | ok; | |
9b86dfa2 SC |
33 | { |
34 | my $a = <<'EOF'; | |
35 | { | |
36 | $test = sub : lvalue { | |
78f9721b | 37 | my $x; |
9b86dfa2 SC |
38 | } |
39 | ; | |
40 | } | |
41 | EOF | |
42 | chomp $a; | |
78f9721b | 43 | print "not " if $deparse->coderef2text(sub{$test = sub : lvalue{my $x}}) ne $a; |
9b86dfa2 SC |
44 | ok; |
45 | ||
46 | $a =~ s/lvalue/method/; | |
78f9721b | 47 | print "not " if $deparse->coderef2text(sub{$test = sub : method{my $x}}) ne $a; |
9b86dfa2 SC |
48 | ok; |
49 | ||
50 | $a =~ s/method/locked method/; | |
78f9721b | 51 | print "not " if $deparse->coderef2text(sub{$test = sub : method locked {my $x}}) |
9b86dfa2 SC |
52 | ne $a; |
53 | ok; | |
54 | } | |
ccc418af | 55 | |
de3f1649 JT |
56 | print "not " if (eval "sub ".$deparse->coderef2text(sub () { 42 }))->() != 42; |
57 | ok; | |
58 | ||
59 | use constant 'c', 'stuff'; | |
60 | print "not " if (eval "sub ".$deparse->coderef2text(\&c))->() ne 'stuff'; | |
61 | ok; | |
62 | ||
63 | # XXX ToDo - constsub that returns a reference | |
64 | #use constant cr => ['hello']; | |
65 | #my $string = "sub " . $deparse->coderef2text(\&cr); | |
66 | #my $val = (eval $string)->(); | |
67 | #print "not " if ref($val) ne 'ARRAY' || $val->[0] ne 'hello'; | |
68 | #ok; | |
69 | ||
885a8af1 JH |
70 | my $a; |
71 | my $Is_VMS = $^O eq 'VMS'; | |
6b462c4a | 72 | $a = `$^X "-I../lib" "-MO=Deparse" -anle 1 2>&1`; |
5fb4d820 | 73 | $a =~ s/-e syntax OK\n//g; |
bd145f00 PP |
74 | $a =~ s{\\340\\242}{\\s} if (ord("\\") == 224); # EBCDIC, cp 1047 or 037 |
75 | $a =~ s{\\274\\242}{\\s} if (ord("\\") == 188); # $^O eq 'posix-bc' | |
ccc418af | 76 | $b = <<'EOF'; |
ccc418af GS |
77 | |
78 | LINE: while (defined($_ = <ARGV>)) { | |
79 | chomp $_; | |
80 | @F = split(/\s+/, $_, 0); | |
58cccf98 | 81 | '???'; |
ccc418af | 82 | } |
ccc418af GS |
83 | |
84 | EOF | |
5fb4d820 | 85 | print "# [$a]\n\# vs\n# [$b]\nnot " if $a ne $b; |
ccc418af GS |
86 | ok; |
87 | ||
6b462c4a | 88 | $a = `$^X "-I../lib" "-MO=Debug" -e 1 2>&1`; |
ccc418af GS |
89 | print "not " unless $a =~ |
90 | /\bLISTOP\b.*\bOP\b.*\bCOP\b.*\bOP\b/s; | |
91 | ok; | |
92 | ||
6b462c4a | 93 | $a = `$^X "-I../lib" "-MO=Terse" -e 1 2>&1`; |
ccc418af | 94 | print "not " unless $a =~ |
f72d64f0 | 95 | /\bLISTOP\b.*leave.*\n OP\b.*enter.*\n COP\b.*nextstate.*\n OP\b.*null/s; |
ccc418af GS |
96 | ok; |
97 | ||
6b462c4a | 98 | $a = `$^X "-I../lib" "-MO=Terse" -ane "s/foo/bar/" 2>&1`; |
ccc418af GS |
99 | $a =~ s/\(0x[^)]+\)//g; |
100 | $a =~ s/\[[^\]]+\]//g; | |
101 | $a =~ s/-e syntax OK//; | |
102 | $a =~ s/[^a-z ]+//g; | |
103 | $a =~ s/\s+/ /g; | |
b2ec7025 | 104 | $a =~ s/\b(s|foo|bar|ullsv)\b\s?//g; |
ccc418af GS |
105 | $a =~ s/^\s+//; |
106 | $a =~ s/\s+$//; | |
208edb77 MG |
107 | my $is_thread = $Config{use5005threads} && $Config{use5005threads} eq 'define'; |
108 | if ($is_thread) { | |
cfe9256d JH |
109 | $b=<<EOF; |
110 | leave enter nextstate label leaveloop enterloop null and defined null | |
111 | threadsv readline gv lineseq nextstate aassign null pushmark split pushre | |
112 | threadsv const null pushmark rvav gv nextstate subst const unstack nextstate | |
113 | EOF | |
114 | } else { | |
115 | $b=<<EOF; | |
ccc418af GS |
116 | leave enter nextstate label leaveloop enterloop null and defined null |
117 | null gvsv readline gv lineseq nextstate aassign null pushmark split pushre | |
cfe9256d | 118 | null gvsv const null pushmark rvav gv nextstate subst const unstack nextstate |
ccc418af | 119 | EOF |
cfe9256d | 120 | } |
ccc418af GS |
121 | $b=~s/\n/ /g;$b=~s/\s+/ /g; |
122 | $b =~ s/\s+$//; | |
cfe9256d | 123 | print "# [$a]\n# vs\n# [$b]\nnot " if $a ne $b; |
ccc418af GS |
124 | ok; |
125 | ||
6b462c4a | 126 | chomp($a = `$^X "-I../lib" "-MB::Stash" "-Mwarnings" -e1`); |
ccc418af | 127 | $a = join ',', sort split /,/, $a; |
3ca0b005 | 128 | $a =~ s/-u(perlio|open)(?:::\w+)?,//g if defined $Config{'useperlio'} and $Config{'useperlio'} eq 'define'; |
754a99e1 GS |
129 | $a =~ s/-uWin32,// if $^O eq 'MSWin32'; |
130 | $a =~ s/-u(Cwd|File|File::Copy|OS2),//g if $^O eq 'os2'; | |
5d129265 | 131 | $a =~ s/-uCwd,// if $^O eq 'cygwin'; |
f3ff050f JH |
132 | if ($Config{static_ext} eq ' ') { |
133 | $b = '-uCarp,-uCarp::Heavy,-uDB,-uExporter,-uExporter::Heavy,-uattributes,' | |
c6eba773 | 134 | . '-umain,-ustrict,-uwarnings'; |
f3ff050f JH |
135 | print "# [$a] vs [$b]\nnot " if $a ne $b; |
136 | ok; | |
137 | } else { | |
138 | print "ok $test # skipped: one or more static extensions\n"; $test++; | |
139 | } | |
ccc418af | 140 | |
208edb77 | 141 | if ($is_thread) { |
cfe9256d JH |
142 | print "# use5005threads: test $test skipped\n"; |
143 | } else { | |
6b462c4a | 144 | $a = `$^X "-I../lib" "-MO=Showlex" -e "my %one" 2>&1`; |
bd145f00 PP |
145 | if (ord('A') != 193) { # ASCIIish |
146 | print "# [$a]\nnot " unless $a =~ /sv_undef.*PVNV.*%one.*sv_undef.*HV/s; | |
147 | } | |
148 | else { # EBCDICish C<1: PVNV (0x1a7ede34) "%\226\225\205"> | |
149 | print "# [$a]\nnot " unless $a =~ /sv_undef.*PVNV.*%\\[0-9].*sv_undef.*HV/s; | |
150 | } | |
885a8af1 | 151 | } |
ccc418af | 152 | ok; |
1e1dbab6 SC |
153 | |
154 | # Bug 20001204.07 | |
155 | { | |
156 | my $foo = $deparse->coderef2text(sub { { 234; }}); | |
157 | # Constants don't get optimised here. | |
158 | print "not " unless $foo =~ /{.*{.*234;.*}.*}/sm; | |
159 | ok; | |
160 | $foo = $deparse->coderef2text(sub { { 234; } continue { 123; } }); | |
161 | print "not " unless $foo =~ /{.*{.*234;.*}.*continue.*{.*123.*}/sm; | |
162 | ok; | |
163 | } |