1#!./perl 2 3# This tests the B:: module(s) with CHECK, BEGIN, END and INIT blocks. The 4# text excerpts below marked with "# " in front are the expected output. They 5# are there twice, EOT for threading, and EONT for a non-threading Perl. The 6# output is matched losely. If the match fails even though the "got" and 7# "expected" output look exactly the same, then watch for trailing, invisible 8# spaces. 9 10BEGIN { 11 if ($ENV{PERL_CORE}){ 12 chdir('t') if -d 't'; 13 @INC = ('.', '../lib', '../ext/B/t'); 14 } else { 15 unshift @INC, 't'; 16 push @INC, "../../t"; 17 } 18 require Config; 19 if (($Config::Config{'extensions'} !~ /\bB\b/) ){ 20 print "1..0 # Skip -- Perl configured without B module\n"; 21 exit 0; 22 } 23 # require 'test.pl'; # now done by OptreeCheck 24} 25 26# import checkOptree(), and %gOpts (containing test state) 27use OptreeCheck; # ALSO DOES @ARGV HANDLING !!!!!! 28use Config; 29 30plan tests => 7 + ($] > 5.009 ? 1 : 0); 31 32require_ok("B::Concise"); 33 34my $out = runperl( 35 switches => ["-MO=Concise,BEGIN,CHECK,INIT,END,-exec"], 36 prog => q{$a=$b && print q/foo/}, 37 stderr => 1 ); 38 39#print "out:$out\n"; 40 41my $src = q[our ($beg, $chk, $init, $end, $uc) = qq{'foo'}; BEGIN { $beg++ } CHECK { $chk++ } INIT { $init++ } END { $end++ } UNITCHECK {$uc++}]; 42 43 44my @warnings_todo; 45@warnings_todo = (todo => 46 "Change 23768 (Remove Carp from warnings.pm) alters expected output, not" 47 . "propagated to 5.8.x") 48 if $] < 5.009; 49 50checkOptree ( name => 'BEGIN', 51 bcopts => 'BEGIN', 52 prog => $src, 53 @warnings_todo, 54 strip_open_hints => 1, 55 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); 56# BEGIN 1: 57# b <1> leavesub[1 ref] K/REFC,1 ->(end) 58# - <@> lineseq KP ->b 59# 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ ->2 60# 3 <1> require sK/1 ->4 61# 2 <$> const[PV "strict.pm"] s/BARE ->3 62# 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ ->5 63# - <@> lineseq K ->- 64# 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$ ->6 65# a <1> entersub[t1] KS*/TARG,2 ->b 66# 6 <0> pushmark s ->7 67# 7 <$> const[PV "strict"] sM ->8 68# 8 <$> const[PV "refs"] sM ->9 69# 9 <$> method_named[PV "unimport"] ->a 70# BEGIN 2: 71# m <1> leavesub[1 ref] K/REFC,1 ->(end) 72# - <@> lineseq K ->m 73# c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ ->d 74# e <1> require sK/1 ->f 75# d <$> const[PV "strict.pm"] s/BARE ->e 76# f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ ->g 77# - <@> lineseq K ->- 78# g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$ ->h 79# l <1> entersub[t1] KS*/TARG,2 ->m 80# h <0> pushmark s ->i 81# i <$> const[PV "strict"] sM ->j 82# j <$> const[PV "refs"] sM ->k 83# k <$> method_named[PV "unimport"] ->l 84# BEGIN 3: 85# x <1> leavesub[1 ref] K/REFC,1 ->(end) 86# - <@> lineseq KP ->x 87# n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ ->o 88# p <1> require sK/1 ->q 89# o <$> const[PV "warnings.pm"] s/BARE ->p 90# q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ ->r 91# - <@> lineseq K ->- 92# r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$ ->s 93# w <1> entersub[t1] KS*/TARG,2 ->x 94# s <0> pushmark s ->t 95# t <$> const[PV "warnings"] sM ->u 96# u <$> const[PV "qw"] sM ->v 97# v <$> method_named[PV "unimport"] ->w 98# BEGIN 4: 99# 11 <1> leavesub[1 ref] K/REFC,1 ->(end) 100# - <@> lineseq KP ->11 101# y <;> nextstate(main 2 -e:1) v:>,<,%,{ ->z 102# 10 <1> postinc[t3] sK/1 ->11 103# - <1> ex-rv2sv sKRM/1 ->10 104# z <#> gvsv[*beg] s ->10 105EOT_EOT 106# BEGIN 1: 107# b <1> leavesub[1 ref] K/REFC,1 ->(end) 108# - <@> lineseq KP ->b 109# 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ ->2 110# 3 <1> require sK/1 ->4 111# 2 <$> const(PV "strict.pm") s/BARE ->3 112# 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ ->5 113# - <@> lineseq K ->- 114# 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$ ->6 115# a <1> entersub[t1] KS*/TARG,2 ->b 116# 6 <0> pushmark s ->7 117# 7 <$> const(PV "strict") sM ->8 118# 8 <$> const(PV "refs") sM ->9 119# 9 <$> method_named(PV "unimport") ->a 120# BEGIN 2: 121# m <1> leavesub[1 ref] K/REFC,1 ->(end) 122# - <@> lineseq K ->m 123# c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ ->d 124# e <1> require sK/1 ->f 125# d <$> const(PV "strict.pm") s/BARE ->e 126# f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ ->g 127# - <@> lineseq K ->- 128# g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$ ->h 129# l <1> entersub[t1] KS*/TARG,2 ->m 130# h <0> pushmark s ->i 131# i <$> const(PV "strict") sM ->j 132# j <$> const(PV "refs") sM ->k 133# k <$> method_named(PV "unimport") ->l 134# BEGIN 3: 135# x <1> leavesub[1 ref] K/REFC,1 ->(end) 136# - <@> lineseq KP ->x 137# n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ ->o 138# p <1> require sK/1 ->q 139# o <$> const(PV "warnings.pm") s/BARE ->p 140# q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ ->r 141# - <@> lineseq K ->- 142# r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$ ->s 143# w <1> entersub[t1] KS*/TARG,2 ->x 144# s <0> pushmark s ->t 145# t <$> const(PV "warnings") sM ->u 146# u <$> const(PV "qw") sM ->v 147# v <$> method_named(PV "unimport") ->w 148# BEGIN 4: 149# 11 <1> leavesub[1 ref] K/REFC,1 ->(end) 150# - <@> lineseq KP ->11 151# y <;> nextstate(main 2 -e:1) v:>,<,%,{ ->z 152# 10 <1> postinc[t2] sK/1 ->11 153# - <1> ex-rv2sv sKRM/1 ->10 154# z <$> gvsv(*beg) s ->10 155EONT_EONT 156 157 158checkOptree ( name => 'END', 159 bcopts => 'END', 160 prog => $src, 161 strip_open_hints => 1, 162 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); 163# END 1: 164# 4 <1> leavesub[1 ref] K/REFC,1 ->(end) 165# - <@> lineseq KP ->4 166# 1 <;> nextstate(main 5 -e:6) v:>,<,%,{ ->2 167# 3 <1> postinc[t3] sK/1 ->4 168# - <1> ex-rv2sv sKRM/1 ->3 169# 2 <#> gvsv[*end] s ->3 170EOT_EOT 171# END 1: 172# 4 <1> leavesub[1 ref] K/REFC,1 ->(end) 173# - <@> lineseq KP ->4 174# 1 <;> nextstate(main 5 -e:6) v:>,<,%,{ ->2 175# 3 <1> postinc[t2] sK/1 ->4 176# - <1> ex-rv2sv sKRM/1 ->3 177# 2 <$> gvsv(*end) s ->3 178EONT_EONT 179 180 181checkOptree ( name => 'CHECK', 182 bcopts => 'CHECK', 183 prog => $src, 184 strip_open_hints => 1, 185 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); 186# CHECK 1: 187# 4 <1> leavesub[1 ref] K/REFC,1 ->(end) 188# - <@> lineseq KP ->4 189# 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2 190# 3 <1> postinc[t3] sK/1 ->4 191# - <1> ex-rv2sv sKRM/1 ->3 192# 2 <#> gvsv[*chk] s ->3 193EOT_EOT 194# CHECK 1: 195# 4 <1> leavesub[1 ref] K/REFC,1 ->(end) 196# - <@> lineseq KP ->4 197# 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2 198# 3 <1> postinc[t2] sK/1 ->4 199# - <1> ex-rv2sv sKRM/1 ->3 200# 2 <$> gvsv(*chk) s ->3 201EONT_EONT 202 203if ($] >= 5.009) { 204 checkOptree ( name => 'UNITCHECK', 205 bcopts=> 'UNITCHECK', 206 prog => $src, 207 strip_open_hints => 1, 208 expect=> <<'EOT_EOT', expect_nt => <<'EONT_EONT'); 209# UNITCHECK 1: 210# 4 <1> leavesub[1 ref] K/REFC,1 ->(end) 211# - <@> lineseq KP ->4 212# 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2 213# 3 <1> postinc[t3] sK/1 ->4 214# - <1> ex-rv2sv sKRM/1 ->3 215# 2 <#> gvsv[*uc] s ->3 216EOT_EOT 217# UNITCHECK 1: 218# 4 <1> leavesub[1 ref] K/REFC,1 ->(end) 219# - <@> lineseq KP ->4 220# 1 <;> nextstate(main 3 -e:4) v:>,<,%,{ ->2 221# 3 <1> postinc[t2] sK/1 ->4 222# - <1> ex-rv2sv sKRM/1 ->3 223# 2 <$> gvsv(*uc) s ->3 224EONT_EONT 225} 226 227checkOptree ( name => 'INIT', 228 bcopts => 'INIT', 229 #todo => 'get working', 230 prog => $src, 231 strip_open_hints => 1, 232 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); 233# INIT 1: 234# 4 <1> leavesub[1 ref] K/REFC,1 ->(end) 235# - <@> lineseq KP ->4 236# 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2 237# 3 <1> postinc[t3] sK/1 ->4 238# - <1> ex-rv2sv sKRM/1 ->3 239# 2 <#> gvsv[*init] s ->3 240EOT_EOT 241# INIT 1: 242# 4 <1> leavesub[1 ref] K/REFC,1 ->(end) 243# - <@> lineseq KP ->4 244# 1 <;> nextstate(main 4 -e:5) v:>,<,%,{ ->2 245# 3 <1> postinc[t2] sK/1 ->4 246# - <1> ex-rv2sv sKRM/1 ->3 247# 2 <$> gvsv(*init) s ->3 248EONT_EONT 249 250 251checkOptree ( name => 'all of BEGIN END INIT CHECK UNITCHECK -exec', 252 bcopts => [qw/ BEGIN END INIT CHECK UNITCHECK -exec /], 253 prog => $src, 254 @warnings_todo, 255 strip_open_hints => 1, 256 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); 257# BEGIN 1: 258# 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ 259# 2 <$> const[PV "strict.pm"] s/BARE 260# 3 <1> require sK/1 261# 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ 262# 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$ 263# 6 <0> pushmark s 264# 7 <$> const[PV "strict"] sM 265# 8 <$> const[PV "refs"] sM 266# 9 <$> method_named[PV "unimport"] 267# a <1> entersub[t1] KS*/TARG,2 268# b <1> leavesub[1 ref] K/REFC,1 269# BEGIN 2: 270# c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ 271# d <$> const[PV "strict.pm"] s/BARE 272# e <1> require sK/1 273# f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ 274# g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$ 275# h <0> pushmark s 276# i <$> const[PV "strict"] sM 277# j <$> const[PV "refs"] sM 278# k <$> method_named[PV "unimport"] 279# l <1> entersub[t1] KS*/TARG,2 280# m <1> leavesub[1 ref] K/REFC,1 281# BEGIN 3: 282# n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ 283# o <$> const[PV "warnings.pm"] s/BARE 284# p <1> require sK/1 285# q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ 286# r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$ 287# s <0> pushmark s 288# t <$> const[PV "warnings"] sM 289# u <$> const[PV "qw"] sM 290# v <$> method_named[PV "unimport"] 291# w <1> entersub[t1] KS*/TARG,2 292# x <1> leavesub[1 ref] K/REFC,1 293# BEGIN 4: 294# y <;> nextstate(main 2 -e:1) v:>,<,%,{ 295# z <#> gvsv[*beg] s 296# 10 <1> postinc[t3] sK/1 297# 11 <1> leavesub[1 ref] K/REFC,1 298# END 1: 299# 12 <;> nextstate(main 5 -e:1) v:>,<,%,{ 300# 13 <#> gvsv[*end] s 301# 14 <1> postinc[t3] sK/1 302# 15 <1> leavesub[1 ref] K/REFC,1 303# INIT 1: 304# 16 <;> nextstate(main 4 -e:1) v:>,<,%,{ 305# 17 <#> gvsv[*init] s 306# 18 <1> postinc[t3] sK/1 307# 19 <1> leavesub[1 ref] K/REFC,1 308# CHECK 1: 309# 1a <;> nextstate(main 3 -e:1) v:>,<,%,{ 310# 1b <#> gvsv[*chk] s 311# 1c <1> postinc[t3] sK/1 312# 1d <1> leavesub[1 ref] K/REFC,1 313# UNITCHECK 1: 314# 1e <;> nextstate(main 6 -e:1) v:>,<,%,{ 315# 1f <#> gvsv[*uc] s 316# 1g <1> postinc[t3] sK/1 317# 1h <1> leavesub[1 ref] K/REFC,1 318EOT_EOT 319# BEGIN 1: 320# 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ 321# 2 <$> const(PV "strict.pm") s/BARE 322# 3 <1> require sK/1 323# 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ 324# 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$ 325# 6 <0> pushmark s 326# 7 <$> const(PV "strict") sM 327# 8 <$> const(PV "refs") sM 328# 9 <$> method_named(PV "unimport") 329# a <1> entersub[t1] KS*/TARG,2 330# b <1> leavesub[1 ref] K/REFC,1 331# BEGIN 2: 332# c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ 333# d <$> const(PV "strict.pm") s/BARE 334# e <1> require sK/1 335# f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ 336# g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$ 337# h <0> pushmark s 338# i <$> const(PV "strict") sM 339# j <$> const(PV "refs") sM 340# k <$> method_named(PV "unimport") 341# l <1> entersub[t1] KS*/TARG,2 342# m <1> leavesub[1 ref] K/REFC,1 343# BEGIN 3: 344# n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ 345# o <$> const(PV "warnings.pm") s/BARE 346# p <1> require sK/1 347# q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ 348# r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$ 349# s <0> pushmark s 350# t <$> const(PV "warnings") sM 351# u <$> const(PV "qw") sM 352# v <$> method_named(PV "unimport") 353# w <1> entersub[t1] KS*/TARG,2 354# x <1> leavesub[1 ref] K/REFC,1 355# BEGIN 4: 356# y <;> nextstate(main 2 -e:1) v:>,<,%,{ 357# z <$> gvsv(*beg) s 358# 10 <1> postinc[t2] sK/1 359# 11 <1> leavesub[1 ref] K/REFC,1 360# END 1: 361# 12 <;> nextstate(main 5 -e:1) v:>,<,%,{ 362# 13 <$> gvsv(*end) s 363# 14 <1> postinc[t2] sK/1 364# 15 <1> leavesub[1 ref] K/REFC,1 365# INIT 1: 366# 16 <;> nextstate(main 4 -e:1) v:>,<,%,{ 367# 17 <$> gvsv(*init) s 368# 18 <1> postinc[t2] sK/1 369# 19 <1> leavesub[1 ref] K/REFC,1 370# CHECK 1: 371# 1a <;> nextstate(main 3 -e:1) v:>,<,%,{ 372# 1b <$> gvsv(*chk) s 373# 1c <1> postinc[t2] sK/1 374# 1d <1> leavesub[1 ref] K/REFC,1 375# UNITCHECK 1: 376# 1e <;> nextstate(main 6 -e:1) v:>,<,%,{ 377# 1f <$> gvsv(*uc) s 378# 1g <1> postinc[t2] sK/1 379# 1h <1> leavesub[1 ref] K/REFC,1 380EONT_EONT 381 382 383# perl "-I../lib" -MO=Concise,BEGIN,CHECK,INIT,END,-exec -e '$a=$b && print q/foo/' 384 385 386 387checkOptree ( name => 'regression test for patch 25352', 388 bcopts => [qw/ BEGIN END INIT CHECK -exec /], 389 prog => 'print q/foo/', 390 @warnings_todo, 391 expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT'); 392# BEGIN 1: 393# 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ 394# 2 <$> const[PV "strict.pm"] s/BARE 395# 3 <1> require sK/1 396# 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ 397# 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$ 398# 6 <0> pushmark s 399# 7 <$> const[PV "strict"] sM 400# 8 <$> const[PV "refs"] sM 401# 9 <$> method_named[PV "unimport"] 402# a <1> entersub[t1] KS*/TARG,2 403# b <1> leavesub[1 ref] K/REFC,1 404# BEGIN 2: 405# c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ 406# d <$> const[PV "strict.pm"] s/BARE 407# e <1> require sK/1 408# f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ 409# g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$ 410# h <0> pushmark s 411# i <$> const[PV "strict"] sM 412# j <$> const[PV "refs"] sM 413# k <$> method_named[PV "unimport"] 414# l <1> entersub[t1] KS*/TARG,2 415# m <1> leavesub[1 ref] K/REFC,1 416# BEGIN 3: 417# n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ 418# o <$> const[PV "warnings.pm"] s/BARE 419# p <1> require sK/1 420# q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ 421# r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$ 422# s <0> pushmark s 423# t <$> const[PV "warnings"] sM 424# u <$> const[PV "qw"] sM 425# v <$> method_named[PV "unimport"] 426# w <1> entersub[t1] KS*/TARG,2 427# x <1> leavesub[1 ref] K/REFC,1 428EOT_EOT 429# BEGIN 1: 430# 1 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ 431# 2 <$> const(PV "strict.pm") s/BARE 432# 3 <1> require sK/1 433# 4 <;> nextstate(B::Concise -275 Concise.pm:356) v:*,&,{,$ 434# 5 <;> nextstate(B::Concise -275 Concise.pm:356) :*,&,{,$ 435# 6 <0> pushmark s 436# 7 <$> const(PV "strict") sM 437# 8 <$> const(PV "refs") sM 438# 9 <$> method_named(PV "unimport") 439# a <1> entersub[t1] KS*/TARG,2 440# b <1> leavesub[1 ref] K/REFC,1 441# BEGIN 2: 442# c <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ 443# d <$> const(PV "strict.pm") s/BARE 444# e <1> require sK/1 445# f <;> nextstate(B::Concise -265 Concise.pm:367) v:*,&,$ 446# g <;> nextstate(B::Concise -265 Concise.pm:367) :*,&,$ 447# h <0> pushmark s 448# i <$> const(PV "strict") sM 449# j <$> const(PV "refs") sM 450# k <$> method_named(PV "unimport") 451# l <1> entersub[t1] KS*/TARG,2 452# m <1> leavesub[1 ref] K/REFC,1 453# BEGIN 3: 454# n <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ 455# o <$> const(PV "warnings.pm") s/BARE 456# p <1> require sK/1 457# q <;> nextstate(B::Concise -254 Concise.pm:386) v:*,&,{,$ 458# r <;> nextstate(B::Concise -254 Concise.pm:386) :*,&,{,$ 459# s <0> pushmark s 460# t <$> const(PV "warnings") sM 461# u <$> const(PV "qw") sM 462# v <$> method_named(PV "unimport") 463# w <1> entersub[t1] KS*/TARG,2 464# x <1> leavesub[1 ref] K/REFC,1 465EONT_EONT 466