testplc.sh 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. #!/bin/bash
  2. # Usage:
  3. # for p in 5.6.2 5.8.9d 5.10.1 5.11.2; do make -q clean >/dev/null; perl$p Makefile.PL; t/testplc.sh -q -c; done
  4. # use the actual perl from the Makefile (perld, perl5.10.0, perl5.8.8, perl5.11.0, ...)
  5. function help {
  6. echo "t/testplc.sh [OPTIONS] [1-$ntests]"
  7. echo " -s skip all B:Debug, roundtrips and options"
  8. echo " -S skip all roundtrips and options but -S and Concise"
  9. echo " -c continue on errors"
  10. echo " -o orig. no -Mblib. only for 5.6 and 5.8"
  11. echo " -q quiet"
  12. echo " -v avoid -MO,-qq"
  13. echo " -h help"
  14. echo "t/testplc.sh -q -s -c <=> perl -Mblib t/bytecode.t"
  15. echo "Without arguments try all $ntests tests. Else the given test numbers."
  16. }
  17. # use the actual perl from the Makefile (perl5.8.8,
  18. # perl5.10.0d-nt, perl5.11.0, ...)
  19. PERL=`grep "^PERL =" Makefile|cut -c8-`
  20. PERL=${PERL:-perl}
  21. PERL=`echo $PERL|sed -e's,^",,; s,"$,,'`
  22. VERS=`echo $PERL|sed -e's,.*perl,,; s,.exe$,,'`
  23. D="`$PERL -e'print (($] < 5.007) ? q(256) : q(v))'`"
  24. v518=`$PERL -e'print (($] < 5.018)?0:1)'`
  25. function init {
  26. # test what? core or our module?
  27. Mblib="`$PERL -e'print (($] < 5.008) ? q() : q(-Iblib/arch -Iblib/lib))'`"
  28. #Mblib=${Mblib:--Mblib} # B::C is now fully 5.6+5.8 backwards compatible
  29. OCMD="$PERL $Mblib -MO=Bytecode,"
  30. QOCMD="$PERL $Mblib -MO=-qq,Bytecode,"
  31. ICMD="$PERL $Mblib -MByteLoader"
  32. if [ "$D" = "256" ]; then QOCMD=$OCMD; fi
  33. if [ "$Mblib" = " " ]; then VERS="${VERS}_global"; fi
  34. }
  35. function pass {
  36. echo -e -n "\033[1;32mPASS \033[0;0m"
  37. echo $*
  38. }
  39. function fail {
  40. echo -e -n "\033[1;31mFAIL \033[0;0m"
  41. echo $*
  42. }
  43. function bcall {
  44. o=$1
  45. opt=${2:-s}
  46. ext=${3:-plc}
  47. optf=$(echo $opt|sed 's/,-//g')
  48. [ -n "$Q" ] || echo ${QOCMD}-$opt,-o${o}${optf}_${VERS}.${ext} ${o}.pl
  49. ${QOCMD}-$opt,-o${o}${optf}_${VERS}.${ext} ${o}.pl
  50. }
  51. function btest {
  52. n=$1
  53. o="bytecode$n"
  54. if [ -z "$2" ]; then
  55. if [ "$n" = "08" ]; then n=8; fi
  56. if [ "$n" = "09" ]; then n=9; fi
  57. echo "${tests[${n}]}" > ${o}.pl
  58. test -z "${tests[${n}]}" && exit
  59. str="${tests[${n}]}"
  60. else
  61. echo "$2" > ${o}.pl
  62. fi
  63. #bcall ${o} O6
  64. rm ${o}_s_${VERS}.plc 2>/dev/null
  65. # annotated assembler
  66. if [ -z "$SKIP" -o -n "$SKI" ]; then
  67. if [ "$Mblib" != " " ]; then
  68. bcall ${o} S,-s asm 1
  69. bcall ${o} S,-k asm 1
  70. bcall ${o} S,-i,-b asm 1
  71. fi
  72. fi
  73. if [ "$Mblib" != " " -a -z "$SKIP" ]; then
  74. m=${o}s_${VERS}
  75. rm ${m}.disasm ${o}_${VERS}.concise ${o}_${VERS}.dbg 2>/dev/null
  76. bcall ${o} s
  77. [ -n "$Q" ] || echo $PERL $Mblib script/disassemble $m.plc \> ${m}.disasm
  78. $PERL $Mblib script/disassemble $m.plc > ${m}.disasm
  79. [ -n "$Q" ] || echo ${ICMD} ${m}.plc
  80. res=$(${ICMD} ${m}.plc)
  81. if [ "X${result[$n]}" = "X" ]; then result[$n]='ok'; fi
  82. if [ "X$res" != "X${result[$n]}" ]; then
  83. fail "./${m}.plc" "'$str' => '$res' Expected: '${result[$n]}'"
  84. fi
  85. # understand annotations
  86. m=${o}S_${VERS}
  87. [ -n "$Q" ] || echo $PERL $Mblib script/assemble ${o}s_${VERS}.disasm \> $m.plc
  88. $PERL $Mblib script/assemble ${o}s_${VERS}.disasm > $m.plc
  89. # full assembler roundtrips
  90. [ -n "$Q" ] || echo $PERL $Mblib script/disassemble $m.plc \> $m.disasm
  91. $PERL $Mblib script/disassemble $m.plc > $m.disasm
  92. md=${o}SD_${VERS}
  93. [ -n "$Q" ] || echo $PERL $Mblib script/assemble $m.disasm \> ${md}.plc
  94. $PERL $Mblib script/assemble $m.disasm > ${md}.plc
  95. [ -n "$Q" ] || echo $PERL $Mblib script/disassemble ${md}.plc \> ${o}SDS_${VERS}.disasm
  96. $PERL $Mblib script/disassemble ${md}.plc > ${o}SDS_${VERS}.disasm
  97. bcall ${o} i,-b
  98. m=${o}ib_${VERS}
  99. $PERL $Mblib script/disassemble ${m}.plc > ${m}.disasm
  100. [ -n "$Q" ] || echo ${ICMD} ${m}.plc
  101. res=$(${ICMD} ${m}.plc)
  102. if [ "X$res" = "X${result[$n]}" ]; then
  103. pass "./${m}.plc" "=> '$res'"
  104. else
  105. fail "./${m}.plc" "'$str' => '$res' Expected: '${result[$n]}'"
  106. fi
  107. bcall ${o} k
  108. m=${o}k_${VERS}
  109. $PERL $Mblib script/disassemble ${m}.plc > ${m}.disasm
  110. [ -n "$Q" ] || echo ${ICMD} ${m}.plc
  111. res=$(${ICMD} ${m}.plc)
  112. if [ "X$res" != "X${result[$n]}" ]; then
  113. fail "./${m}.plc" "'$str' => '$res' Expected: '${result[$n]}'"
  114. fi
  115. [ -n "$Q" ] || echo $PERL $Mblib -MO=${qq}Debug,-exec ${o}.pl -o ${o}_${VERS}.dbg
  116. [ -n "$Q" ] || $PERL $Mblib -MO=${qq}Debug,-exec ${o}.pl > ${o}_${VERS}.dbg
  117. fi
  118. if [ -z "$SKIP" -o -n "$SKI" ]; then
  119. # 5.8 has a bad concise
  120. [ -n "$Q" ] || echo $PERL $Mblib -MO=${qq}Concise,-exec ${o}.pl -o ${o}_${VERS}.concise
  121. $PERL $Mblib -MO=${qq}Concise,-exec ${o}.pl > ${o}_${VERS}.concise
  122. fi
  123. if [ -z "$SKIP" ]; then
  124. if [ "$Mblib" != " " ]; then
  125. #bcall ${o} TI
  126. bcall ${o} H
  127. m="${o}H_${VERS}"
  128. [ -n "$Q" ] || echo $PERL $Mblib ${m}.plc
  129. res=$($PERL $Mblib ${m}.plc)
  130. if [ "X$res" != "X${result[$n]}" ]; then
  131. fail "./${m}.plc" "'$str' => '$res' Expected: '${result[$n]}'"
  132. fi
  133. fi
  134. fi
  135. if [ "$Mblib" != " " ]; then
  136. # -s ("scan") should be the new default
  137. [ -n "$Q" ] || echo ${OCMD}-s,-o${o}.plc ${o}.pl
  138. ${OCMD}-s,-o${o}.plc ${o}.pl || (test -z $CONT && exit)
  139. else
  140. # No -s with 5.6
  141. [ -n "$Q" ] || echo ${OCMD}-o${o}.plc ${o}.pl
  142. ${OCMD}-o${o}.plc ${o}.pl || (test -z $CONT && exit)
  143. fi
  144. [ -n "$Q" ] || echo $PERL $Mblib script/disassemble ${o}.plc -o ${o}.disasm
  145. $PERL $Mblib script/disassemble ${o}.plc > ${o}.disasm
  146. [ -n "$Q" ] || echo ${ICMD} ${o}.plc
  147. res=$(${ICMD} ${o}.plc)
  148. if [ "X$res" = "X${result[$n]}" ]; then
  149. pass "./${o}.plc" "=> '$res'"
  150. else
  151. fail "./${o}.plc" "'$str' => '$res' Expected: '${result[$n]}'"
  152. if [ -z "$Q" ]; then
  153. echo -n "Again with -Dv? (or Ctrl-Break)"
  154. read
  155. echo ${ICMD} -D$D ${o}.plc; ${ICMD} -D$D ${o}.plc
  156. fi
  157. test -z $CONT && exit
  158. fi
  159. }
  160. ntests=350
  161. declare -a tests[$ntests]
  162. declare -a result[$ntests]
  163. tests[1]="print 'hi'"
  164. result[1]='hi'
  165. tests[2]='for (1,2,3) { print if /\d/ }'
  166. result[2]='123'
  167. tests[3]='$_ = "xyxyx"; %j=(1,2); s/x/$j{print("z")}/ge; print $_'
  168. result[3]='zzz2y2y2'
  169. tests[4]='$_ = "xyxyx"; %j=(1,2); s/x/$j{print("z")}/g; print $_'
  170. if [[ $v518 -gt 0 ]]; then result[4]='zzz2y2y2'; else result[4]='z2y2y2'; fi
  171. tests[5]='print split /a/,"bananarama"'
  172. result[5]='bnnrm'
  173. tests[6]="{package P; sub x {print 'ya'} x}"
  174. result[6]='ya'
  175. tests[7]='@z = split /:/,"b:r:n:f:g"; print @z'
  176. result[7]='brnfg'
  177. tests[8]='sub AUTOLOAD { print 1 } &{"a"}()'
  178. result[8]='1'
  179. tests[9]='my $l = 3; $x = sub { print $l }; &$x'
  180. result[9]='3'
  181. tests[10]='my $i = 1;
  182. my $foo = sub {
  183. $i = shift if @_
  184. }; print $i;
  185. print &$foo(3),$i;'
  186. result[10]='133'
  187. # index: do fbm_compile or not
  188. tests[11]='$x="Cannot use"; print index $x, "Can"'
  189. result[11]='0'
  190. tests[12]='my $i=6; eval "print \$i\n"'
  191. result[12]='6'
  192. tests[13]='BEGIN { %h=(1=>2,3=>4) } print $h{3}'
  193. result[13]='4'
  194. tests[14]='open our $T,"a"; print "ok";'
  195. result[14]='ok'
  196. tests[15]='print <DATA>
  197. __DATA__
  198. a
  199. b'
  200. result[15]='a
  201. b'
  202. tests[16]='BEGIN{tie @a, __PACKAGE__;sub TIEARRAY {bless{}} sub FETCH{1}}; print $a[1]'
  203. result[16]='1'
  204. tests[17]='my $i=3; print 1 .. $i'
  205. result[17]='123'
  206. # custom key sort
  207. tests[18]='my $h = { a=>3, b=>1 }; print sort {$h->{$a} <=> $h->{$b}} keys %$h'
  208. result[18]='ba'
  209. # fool the sort optimizer by my $p
  210. tests[19]='print sort { my $p; $b <=> $a } 1,4,3'
  211. result[19]='431'
  212. # not repro: something like this is broken in original 5.6 (Net::DNS::ZoneFile::Fast)
  213. # see new test 33
  214. tests[20]='$a="abcd123";my $r=qr/\d/;print $a =~ $r;'
  215. result[20]='1'
  216. # broken on early alpha and 5.10: run-time labels.
  217. tests[21]='sub skip_on_odd{next NUMBER if $_[0]% 2}NUMBER:for($i=0;$i<5;$i++){skip_on_odd($i);print $i;}'
  218. result[21]='024'
  219. # broken in original perl 5.6
  220. tests[22]='my $fh; BEGIN { open($fh,"<","/dev/null"); } print "ok";';
  221. # broken in perl 5.8
  222. tests[23]='package MyMod; our $VERSION = 1.3; print "ok";'
  223. # works in original perl 5.6, broken with latest B::C in 5.6, 5.8
  224. tests[24]='sub level1{return(level2()?"fail":"ok")} sub level2{0} print level1();'
  225. # enforce custom ncmp sort and count it. fails as CC in all. How to enforce icmp?
  226. # <=5.6 qsort needs two more passes here than >=5.8 merge_sort
  227. # 5.12 got it backwards and added 4 more passes.
  228. tests[25]='print sort { $i++; $b <=> $a } 1..4'
  229. result[25]="4321"
  230. # lvalue sub
  231. tests[26]='sub a:lvalue{my $a=26; ${\(bless \$a)}}sub b:lvalue{${\shift}}; print ${a(b)}';
  232. result[26]="26"
  233. # xsub constants (constant folded). newlib: 0x200, glibc: 0x100
  234. tests[27]='use Fcntl ();my $a=Fcntl::O_CREAT(); print "ok" if ( $a >= 64 && &Fcntl::O_CREAT >= 64 );'
  235. # require $fname
  236. tests[28]='my($fname,$tmp_fh);while(!open($tmp_fh,">",($fname=q{ccode28_} . rand(999999999999)))){$bail++;die "Failed to create a tmp file after 500 tries" if $bail>500;}print {$tmp_fh} q{$x="ok";1;};close($tmp_fh);sleep 1;require $fname;END{unlink($fname);};print $x;'
  237. # multideref with static index and sv and dynamic gv ptrs
  238. tests[29]='my (%b,%h); BEGIN { %b=(1..8);@a=(1,2,3,4); %h=(1=>2,3=>4) } $i=0; my $l=-1; print $h->{$b->{3}},$h->{$a[-1]},$a[$i],$a[$l],$h{3}'
  239. result[29]='144'
  240. # special old IO handling
  241. tests[291]='use IO;print "ok"'
  242. # run-time context of .., fails in CC
  243. tests[30]='@a=(4,6,1,0,0,1);sub range{(shift @a)..(shift @a)}print range();while(@a){print scalar(range())}'
  244. result[30]='456123E0'
  245. # AUTOLOAD w/o goto xsub
  246. tests[31]='package MockShell;sub AUTOLOAD{my $p=$AUTOLOAD;$p=~s/.*:://;print(join(" ",$p,@_),";");} package main; MockShell::date();MockShell::who("am","i");MockShell::ls("-l");'
  247. result[31]='date;who am i;ls -l;'
  248. # CC entertry/jmpenv_jump/leavetry
  249. tests[32]='eval{print "1"};eval{die 1};print "2";'
  250. result[32]='12'
  251. # C qr test was broken in 5.6 -- needs to load an actual file to test. See test 20.
  252. # used to error with Can't locate object method "save" via package "U??WVS?-" (perhaps you forgot to load "U??WVS?-"?) at /usr/lib/perl5/5.6.2/i686-linux/B/C.pm line 676.
  253. # fails with new constant only. still not repro (r-magic probably)
  254. tests[33]='BEGIN{unshift @INC,("t");} use qr_loaded_module; print "ok" if qr_loaded_module::qr_called_in_sub("name1")'
  255. # init of magic hashes. %ENV has e magic since a0714e2c perl.c
  256. # (Steven Schubiger 2006-02-03 17:24:49 +0100 3967) i.e. 5.8.9 but not 5.8.8
  257. tests[34]='my $x=$ENV{TMPDIR};print "ok"'
  258. # static method_named. fixed with 1.16
  259. tests[35]='package dummy;my $i=0;sub meth{print $i++};package main;dummy->meth(1);my dummy $o = bless {},"dummy";$o->meth("const");my $meth="meth";$o->$meth("const");dummy->$meth("const");dummy::meth("dummy","const")'
  260. result[35]='01234'
  261. # HV self-ref
  262. tests[36]='my ($rv, %hv); %hv = ( key => \$rv ); $rv = \%hv; print "ok";'
  263. # AV self-ref
  264. tests[37]='my ($rv, @av); @av = ( \$rv ); $rv = \@av; print "ok";'
  265. # constant autoload loop crash test
  266. tests[38]='for(1 .. 1024) { if (open(my $null_fh,"<","/dev/null")) { seek($null_fh,0,SEEK_SET); close($null_fh); $ok++; } }if ($ok == 1024) { print "ok"; }'
  267. # check re::is_regexp, and on 5.12 if being upgraded to SVt_REGEXP
  268. usere="`$PERL -e'print (($] < 5.011) ? q(use re;) : q())'`"
  269. tests[39]=$usere'$a=qr/x/;print ($] < 5.010?1:re::is_regexp($a))'
  270. result[39]='1'
  271. # String with a null byte -- used to generate broken .c on 5.6.2 with static pvs
  272. tests[40]='my $var="this string has a null \\000 byte in it";print "ok";'
  273. # Shared scalar, n magic. => Don't know how to handle magic of type \156.
  274. usethreads="`$PERL -MConfig -e'print ($Config{useithreads} ? q(use threads;) : q())'`"
  275. #usethreads='BEGIN{use Config; unless ($Config{useithreads}) {print "ok"; exit}} '
  276. #;threads->create(sub{$s="ok"})->join;
  277. # not yet testing n, only P
  278. tests[41]=$usethreads'use threads::shared;{my $s="ok";share($s);print $s}'
  279. # Shared aggregate, P magic
  280. tests[42]=$usethreads'use threads::shared;my %h : shared; print "ok"'
  281. # Aggregate element, n + p magic
  282. tests[43]=$usethreads'use threads::shared;my @a : shared; $a[0]="ok"; print $a[0]'
  283. # perl #72922 (5.11.4 fails with magic_killbackrefs)
  284. tests[44]='use Scalar::Util "weaken";my $re1=qr/foo/;my $re2=$re1;weaken($re2);print "ok" if $re3=qr/$re1/;'
  285. # test dynamic loading
  286. tests[45]='use Data::Dumper ();Data::Dumper::Dumpxs({});print "ok";'
  287. # issue 79: Exporter:: stash missing in main::
  288. #tests[46]='use Exporter; if (exists $main::{"Exporter::"}) { print "ok"; }'
  289. tests[46]='use Exporter; print "ok" if %main::Exporter::'
  290. #tests[46]='use Exporter; print "ok" if scalar(keys(%main::Exporter::)) > 2'
  291. # non-tied av->MAGICAL
  292. tests[47]='@ISA=(q(ok));print $ISA[0];'
  293. # END block del_backref with bytecode only
  294. tests[48]='my $s=q{ok};END{print $s}'
  295. # even this failed until r1000, overlarge AvFILL=3 endav
  296. #tests[48]='print q(ok);END{}'
  297. # no-fold
  298. tests[49]='print q(ok) if "test" =~ /es/i;'
  299. # @ISA issue 64
  300. tests[50]='package Top;sub top{q(ok)};package Next;our @ISA=qw(Top);package main;print Next->top();'
  301. # XXX TODO sigwarn $w = B::NULL without -v
  302. tests[51]='$SIG{__WARN__}=sub{print "ok"};warn 1;'
  303. # check if general signals work
  304. tests[511]='BEGIN{$SIG{USR1}=sub{$w++;};} kill USR1 => $$; print q(ok) if $w'
  305. tests[68]='package A;sub test{use Data::Dumper();$_ =~ /^(.*?)\d+$/;"Some::Package"->new();}print q(ok);'
  306. #-------------
  307. # issue27
  308. tests[70]='require LWP::UserAgent;print q(ok);'
  309. # issue24
  310. tests[71]='dbmopen(%H,q(f),0644);print q(ok);'
  311. tests[81]='%int::; #create int package for types
  312. sub x(int,int) { @_ } #cvproto
  313. my $o = prototype \&x;
  314. if ($o eq "int,int") {print "o"}else{print $o};
  315. sub y($) { @_ } #cvproto
  316. my $p = prototype \&y;
  317. if ($p eq q($)) {print "k"}else{print $p};
  318. require bytes;
  319. sub my::length ($) { # possible prototype mismatch vs _
  320. if ( bytes->can(q(length)) ) {
  321. *length = *bytes::length;
  322. goto &bytes::length;
  323. }
  324. return CORE::length( $_[0] );
  325. }
  326. print my::length($p);'
  327. result[81]='ok1'
  328. tests[90]='my $s = q(test string);
  329. $s =~ s/(?<first>test) (?<second>string)/\2 \1/g;
  330. print q(o) if $s eq q(string test);
  331. q(test string) =~ /(?<first>\w+) (?<second>\w+)/;
  332. print q(k) if $+{first} eq q(test);'
  333. tests[901]='my %errs = %!; # t/op/magic.t Errno compiled in
  334. print q(ok) if defined ${"!"}{ENOENT};'
  335. tests[902]='my %errs = %{"!"}; # t/op/magic.t Errno to be loaded at run-time
  336. print q(ok) if defined ${"!"}{ENOENT};'
  337. # issue #199
  338. tests[903]='"abc" =~ /(.)./; print "ok" if "21" eq join"",@+;'
  339. # issue #220
  340. tests[904]='my $content = "ok\n";
  341. while ( $content =~ m{\w}g ) {
  342. $_ .= "$-[0]$+[0]";
  343. }
  344. print "ok" if $_ eq "0112";'
  345. # IO handles
  346. tests[91]='# issue59
  347. use strict;
  348. use warnings;
  349. use IO::Socket;
  350. my $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "perl.org", PeerPort => "80" );
  351. print $remote "GET / HTTP/1.0" . "\r\n\r\n";
  352. my $result = <$remote>;
  353. $result =~ m|HTTP/1.1 200 OK| ? print "ok" : print $result;
  354. close $remote;'
  355. tests[93]='#SKIP
  356. my ($pid, $out, $in);
  357. BEGIN {
  358. local(*FPID);
  359. $pid = open(FPID, "echo <<EOF |"); # DIE
  360. open($out, ">&STDOUT"); # EASY
  361. open(my $tmp, ">", "pcc.tmp"); # HARD to get filename, WARN
  362. print $tmp "test\n";
  363. close $tmp; # OK closed
  364. open($in, "<", "pcc.tmp"); # HARD to get filename, WARN
  365. }
  366. # === run-time ===
  367. print $out "o";
  368. kill 0, $pid; # BAD! warn? die?
  369. print "k" if "test" eq read $in, my $x, 4;
  370. unlink "pcc.tmp";
  371. '
  372. result[93]='o'
  373. tests[931]='my $f;BEGIN{open($f,"<README");}read $f,my $in, 2; print "ok"'
  374. tests[932]='my $f;BEGIN{open($f,">&STDOUT");}print $f "ok"'
  375. tests[95]='use IO::Socket::SSL();
  376. my IO::Handle $handle = IO::Socket::SSL->new(SSL_verify_mode =>0);
  377. $handle->blocking(0);
  378. print "ok";'
  379. tests[96]='defined(&B::OP::name) || print q(ok)'
  380. tests[97]='use v5.12; print q(ok);'
  381. result[97]='ok'
  382. tests[971]='use v5.6; print q(ok);'
  383. result[971]='ok'
  384. tests[98]='BEGIN{$^H{feature_say} = 1;}
  385. sub test { eval(""); }
  386. print q(ok);'
  387. result[98]='ok'
  388. tests[105]='package A; use Storable qw/dclone/; my $a = \""; dclone $a; print q(ok);'
  389. result[105]='ok'
  390. if [[ $v518 -gt 0 ]]; then
  391. tests[130]='no warnings "experimental::lexical_subs";use feature "lexical_subs";my sub p{q(ok)}; my $a=\&p;print p;'
  392. fi
  393. tests[135]='"to" =~ /t(?{ print "ok"})o/;'
  394. tests[138]='print map { chr $_ } qw/97 98 99/;'
  395. result[138]='abc'
  396. tests[140]='my %a;print "ok" if !%a;'
  397. #tests[141]='print "ok" if "1" > 0'
  398. tests[141]='@x=(0..1);print "ok" if $#x == "1"'
  399. tests[142]='$_ = "abc\x{1234}";chop;print "ok" if $_ eq "abc"'
  400. tests[143]='BEGIN {
  401. package Net::IDN::Encode;
  402. our $DOT = qr/[\.]/; #works with my!
  403. my $RE = qr/xx/;
  404. sub domain_to_ascii {
  405. my $x = shift || "";
  406. $x =~ m/$RE/o;
  407. return split( qr/($DOT)/o, $x);
  408. }
  409. }
  410. package main;
  411. Net::IDN::Encode::domain_to_ascii(42);
  412. print "ok\n";'
  413. tests[1431]='BEGIN{package Foo;our $DOT=qr/[.]/;};package main;print "ok\n" if "dot.dot" =~ m/($Foo::DOT)/'
  414. tests[1432]='BEGIN{$DOT=qr/[.]/}print "ok\n" if "dot.dot" =~ m/($DOT)/'
  415. tests[144]='print index("long message\0xx","\0")'
  416. result[144]='12'
  417. tests[145]='my $bits = 0; for (my $i = ~0; $i; $i >>= 1) { ++$bits; }; print $bits'
  418. result[145]=`$PERL -MConfig -e'print 8*$Config{ivsize}'`
  419. tests[146]='my $a = v120.300; my $b = v200.400; $a ^= $b; print sprintf("%vd", $a);'
  420. result[146]='176.188'
  421. tests[148]='open(FH, ">", "ccode148i.tmp"); print FH "1\n"; close FH; print -s "ccode148i.tmp"'
  422. result[148]='2'
  423. tests[149]='format Comment =
  424. ok
  425. .
  426. {
  427. local $~ = "Comment";
  428. write;
  429. }'
  430. tests[150]='print NONEXISTENT "foo"; print "ok" if $! == 9'
  431. tests[1501]='$! = 0; print NONEXISTENT "foo"; print "ok" if $! == 9'
  432. tests[152]='print "ok" if find PerlIO::Layer "perlio"'
  433. tests[154]='$SIG{__WARN__} = sub { die "warning: $_[0]" }; opendir(DIR, ".");closedir(DIR);print q(ok)'
  434. tests[156]='use warnings;
  435. no warnings qw(portable);
  436. use XSLoader;
  437. XSLoader::load() if $ENV{force_xsloader}; # trick for perlcc to force xloader to be compiled
  438. {
  439. my $q = 12345678901;
  440. my $x = sprintf("%llx", $q);
  441. print "ok\n" if hex $x == 0x2dfdc1c35;
  442. exit;
  443. }'
  444. tests[157]='$q = 18446744073709551615;print scalar($q)."\n";print scalar(18446744073709551615)."\n";'
  445. result[157]='18446744073709551615
  446. 18446744073709551615'
  447. tests[1571]='my $a = 9223372036854775807; print "ok\n" if ++$a == 9223372036854775808;'
  448. # duplicate of 148
  449. tests[158]='open W, ">ccodetmp" or die "1: $!";print W "foo";close W;open R, "ccodetmp" or die "2: $!";my $e=eof R ? 1 : 0;close R;print "$e\n";'
  450. result[158]='0'
  451. tests[159]='@X::ISA = "Y"; sub Y::z {"Y::z"} print "ok\n" if X->z eq "Y::z"; delete $X::{z}; exit'
  452. # see 188
  453. tests[160]='sub foo { (shift =~ m?foo?) ? 1 : 0 }
  454. print "ok\n";'
  455. tests[161]='sub PVBM () { foo } { my $dummy = index foo, PVBM } print PVBM'
  456. result[161]='foo'
  457. # duplicate of 142
  458. tests[162]='$x = "\x{1234}"; print "ok\n" if ord($x) == 0x1234;'
  459. tests[163]='# WontFix
  460. my $destroyed = 0;
  461. sub X::DESTROY { $destroyed = 1 }
  462. {
  463. my $x;
  464. BEGIN {$x = sub { } }
  465. $x = bless {}, 'X';
  466. }
  467. print qq{ok\n} if $destroyed == 1;'
  468. # duplicate of 148
  469. tests[164]='open(DUPOUT,">&STDOUT");close(STDOUT);open(F,">&DUPOUT");print F "ok\n";'
  470. tests[165]='use warnings;
  471. sub recurse1 {
  472. unshift @_, "x";
  473. no warnings "recursion";
  474. goto &recurse2;
  475. }
  476. sub recurse2 {
  477. my $x = shift;
  478. $_[0] ? +1 + recurse1($_[0] - 1) : 0
  479. }
  480. print "ok\n" if recurse1(500) == 500;'
  481. tests[166]='my $ok = 1;
  482. foreach my $chr (60, 200, 600, 6000, 60000) {
  483. my ($key, $value) = (chr ($chr) . "\x{ABCD}", "$chr\x{ABCD}");
  484. chop($key, $value);
  485. my %utf8c = ( $key => $value );
  486. my $tempval = sprintf q($utf8c{"\x{%x}"}), $chr;
  487. my $ev = eval $tempval;
  488. $ok = 0 if !$ev or $ev ne $value;
  489. } print "ok" if $ok'
  490. tests[167]='$a = "a\xFF\x{100}";
  491. eval {$b = crypt($a, "cd")};
  492. print $@;'
  493. result[167]='Wide character in crypt at ccode167.pl line 2.'
  494. tests[168]='my $start_time = time;
  495. eval {
  496. local $SIG{ALRM} = sub { die "ALARM !\n" };
  497. alarm 1;
  498. # perlfunc recommends against using sleep in combination with alarm.
  499. 1 while (time - $start_time < 3);
  500. };
  501. alarm 0;
  502. print $@;
  503. print "ok\n" if $@ eq "ALARM !\n";'
  504. result[168]='ALARM !
  505. ok'
  506. tests[169]='#TODO Attribute::Handlers
  507. package MyTest;
  508. use Attribute::Handlers;
  509. sub Check :ATTR {
  510. print "called\n";
  511. print "ok\n" if ref $_[4] eq "ARRAY" && join(",", @{$_[4]}) eq join(",", qw/a b c/);
  512. }
  513. sub a_sub :Check(qw/a b c/) {
  514. return 42;
  515. }
  516. print a_sub()."\n";'
  517. result[169]='called
  518. ok
  519. 42'
  520. tests[170]='eval "sub xyz (\$) : bad ;"; print "~~~~\n$@~~~~\n"'
  521. result[170]='~~~~
  522. Invalid CODE attribute: bad at (eval 1) line 1.
  523. BEGIN failed--compilation aborted at (eval 1) line 1.
  524. ~~~~'
  525. tests[172]='package Foo;
  526. use overload q("") => sub { "Foo" };
  527. package main;
  528. my $foo = bless {}, "Foo";
  529. print "ok " if "$foo" eq "Foo";
  530. print "$foo\n";'
  531. result[172]='ok Foo'
  532. tests[173]='# WontFix
  533. use constant BEGIN => 42; print "ok 1\n" if BEGIN == 42;
  534. use constant INIT => 42; print "ok 2\n" if INIT == 42;
  535. use constant CHECK => 42; print "ok 3\n" if CHECK == 42;'
  536. result[173]='Prototype mismatch: sub main::BEGIN () vs none at ./ccode173.pl line 2.
  537. Constant subroutine BEGIN redefined at ./ccode173.pl line 2.
  538. ok 1
  539. ok 2
  540. ok 3'
  541. tests[174]='
  542. my $str = "\x{10000}\x{800}";
  543. no warnings "utf8";
  544. { use bytes; $str =~ s/\C\C\z//; }
  545. my $ref = "\x{10000}\0";
  546. print "ok 1\n" if ~~$str eq $ref;
  547. $str = "\x{10000}\x{800}";
  548. { use bytes; $str =~ s/\C\C\z/\0\0\0/; }
  549. my $ref = "\x{10000}\0\0\0\0";
  550. print "ok 2\n" if ~~$str eq $ref;'
  551. result[174]='ok 1
  552. ok 2'
  553. tests[175]='{
  554. # note that moving the use in an eval block solve the problem
  555. use warnings NONFATAL => all;
  556. $SIG{__WARN__} = sub { "ok - expected warning\n" };
  557. my $x = pack( "I,A", 4, "X" );
  558. print "ok\n";
  559. }'
  560. result[175]='ok - expected warning
  561. ok'
  562. tests[176]='use Math::BigInt; print Math::BigInt::->new(5000000000);'
  563. result[176]='5000000000'
  564. tests[177]='use version; print "ok\n" if version::is_strict("4.2");'
  565. tests[178]='BEGIN { $hash = { pi => 3.14, e => 2.72, i => -1 } ;} print scalar keys $hash;'
  566. result[178]='3'
  567. tests[179]='#TODO smartmatch subrefs
  568. {
  569. package Foo;
  570. sub new { bless {} }
  571. }
  572. package main;
  573. our $foo = Foo->new;
  574. our $bar = $foor; # required to generate the wrong behavior
  575. my $match = eval q($foo ~~ undef) ? 1 : 0;
  576. print "match ? $match\n";'
  577. result[179]='match ? 0'
  578. tests[180]='use feature "switch"; use integer; given(3.14159265) { when(3) { print "ok\n"; } }'
  579. tests[181]='sub End::DESTROY { $_[0]->() };
  580. my $inx = "OOOO";
  581. $SIG{__WARN__} = sub { print$_[0] . "\n" };
  582. {
  583. $@ = "XXXX";
  584. my $e = bless( sub { die $inx }, "End")
  585. }
  586. print q(ok)'
  587. tests[182]='#TODO stash-magic delete renames to ANON
  588. my @c; sub foo { @c = caller(0); print $c[3] } my $fooref = delete $::{foo}; $fooref -> ();'
  589. result[182]='main::__ANON__'
  590. tests[183]='main->import(); print q(ok)'
  591. tests[184]='use warnings;
  592. sub xyz { no warnings "redefine"; *xyz = sub { $a <=> $b }; &xyz }
  593. eval { @b = sort xyz 4,1,3,2 };
  594. print defined $b[0] && $b[0] == 1 && $b[1] == 2 && $b[2] == 3 && $b[3] == 4 ? "ok\n" : "fail\n";
  595. exit;
  596. {
  597. package Foo;
  598. use overload (qw("" foo));
  599. }
  600. {
  601. package Bar;
  602. no warnings "once";
  603. sub foo { $ENV{fake} }
  604. }
  605. '
  606. # usage: t/testc.sh -O3 -Dp,-UCarp 185
  607. tests[185]='my $a=pack("U",0xFF);use bytes;print "not " unless $a eq "\xc3\xbf" && bytes::length($a) == 2; print "ok\n";'
  608. tests[186]='eval q/require B/; my $sub = do { package one; \&{"one"}; }; delete $one::{one}; my $x = "boom"; print "ok\n";'
  609. # duplicate of 182
  610. tests[187]='my $glob = \*Phoo::glob; undef %Phoo::; print ( ( "$$glob" eq "*__ANON__::glob" ) ? "ok\n" : "fail with $$glob\n" );'
  611. tests[188]='package aiieee;sub zlopp {(shift =~ m?zlopp?) ? 1 : 0;} sub reset_zlopp {reset;}
  612. package main; print aiieee::zlopp(""), aiieee::zlopp("zlopp"), aiieee::zlopp(""), aiieee::zlopp("zlopp");
  613. aiieee::reset_zlopp(); print aiieee::zlopp("zlopp")'
  614. result[188]='01001'
  615. tests[191]='# WontFix
  616. BEGIN{sub plan{42}} {package Foo::Bar;} print((exists $Foo::{"Bar::"} && $Foo::{"Bar::"} eq "*Foo::Bar::") ? "ok\n":"bad\n"); plan(fake=>0);'
  617. tests[192]='use warnings;
  618. {
  619. no warnings qw "once void";
  620. my %h; # We pass a key of this hash to the subroutine to get a PVLV.
  621. sub { for(shift) {
  622. # Set up our glob-as-PVLV
  623. $_ = *hon;
  624. # Assigning undef to the glob should not overwrite it...
  625. {
  626. my $w;
  627. local $SIG{__WARN__} = sub { $w = shift };
  628. *$_ = undef;
  629. print ( $w =~ m/Undefined value assigned to typeglob/ ? "ok" : "not ok");
  630. }
  631. }}->($h{k});
  632. }'
  633. tests[193]='unlink q{not.a.file}; $! = 0; open($FOO, q{not.a.file}); print( $! ne 0 ? "ok" : q{error: $! should not be 0}."\n"); close $FOO;'
  634. tests[194]='$0 = q{ccdave with long name}; #print "pid: $$\n";
  635. $s=`ps w | grep "$$" | grep "[c]cdave"`;
  636. print ($s =~ /ccdave with long name/ ? q(ok) : $s);'
  637. tests[1941]='$0 = q{ccdave}; #print "pid: $$\n";
  638. $s=`ps auxw | grep "$$" | grep "ccdave"|grep -v grep`;
  639. print q(ok) if $s =~ /ccdave/'
  640. # duplicate of 152
  641. tests[195]='use PerlIO; eval { require PerlIO::scalar }; find PerlIO::Layer "scalar"; print q(ok)'
  642. tests[196]='package Foo;
  643. sub new { bless {}, shift }
  644. DESTROY { $_[0] = "foo" }
  645. package main;
  646. eval q{\\($x, $y, $z) = (1, 2, 3);};
  647. my $m;
  648. $SIG{__DIE__} = sub { $m = shift };
  649. { my $f = Foo->new }
  650. print "m: $m\n";'
  651. result[196]='m: Modification of a read-only value attempted at ccode196.pl line 3.'
  652. tests[197]='package FINALE;
  653. {
  654. $ref3 = bless ["ok - package destruction"];
  655. my $ref2 = bless ["ok - lexical destruction\n"];
  656. local $ref1 = bless ["ok - dynamic destruction\n"];
  657. 1;
  658. }
  659. DESTROY {
  660. print $_[0][0];
  661. }'
  662. result[197]='ok - dynamic destruction
  663. ok - lexical destruction
  664. ok - package destruction'
  665. # duplicate of 150
  666. tests[198]='{
  667. open(my $NIL, qq{|/bin/echo 23}) or die "fork failed: $!";
  668. $! = 1;
  669. close $NIL;
  670. if($! == 5) { print}
  671. }'
  672. result[198]='23'
  673. # duplicate of 90
  674. tests[199]='"abc" =~ /(.)./; print @+; print "end\n"'
  675. result[199]='21end'
  676. tests[200]='%u=("\x{123}"=>"fo"); print "ok" if $u{"\x{123}"} eq "fo"'
  677. tests[2001]='BEGIN{%u=("\x{123}"=>"fo");} print "ok" if $u{"\x{123}"} eq "fo";'
  678. tests[201]='use Storable;*Storable::CAN_FLOCK=sub{1};print qq{ok\n}'
  679. tests[2011]='sub can {require Config; import Config;return $Config{d_flock}}
  680. use IO::File;
  681. can();
  682. print "ok\n";'
  683. tests[203]='#TODO perlio layers
  684. use open(IN => ":crlf", OUT => ":encoding(cp1252)");
  685. open F, "<", "/dev/null";
  686. my %l = map {$_=>1} PerlIO::get_layers(F, input => 1);
  687. print $l{crlf} ? q(ok) : keys(%l);'
  688. # issue 29
  689. tests[2900]='use open qw(:std :utf8);
  690. BEGIN{ `echo ö > xx.bak`; }
  691. open X, "xx.bak";
  692. $_ = <X>;
  693. print unpack("U*", $_), " ";
  694. print $_ if /\w/;'
  695. result[2900]='24610 ö'
  696. tests[207]='use warnings;
  697. sub asub { }
  698. asub(tests => 48);
  699. my $str = q{0};
  700. $str =~ /^[ET1]/i;
  701. {
  702. no warnings qw<io deprecated>;
  703. print "ok 1\n" if opendir(H, "t");
  704. print "ok 2" if open(H, "<", "TESTS");
  705. }'
  706. result[207]='ok 1
  707. ok 2'
  708. tests[208]='sub MyKooh::DESTROY { print "${^GLOBAL_PHASE} MyKooh " } my $my =bless {}, MyKooh;
  709. sub OurKooh::DESTROY { print "${^GLOBAL_PHASE} OurKooh" }our $our=bless {}, OurKooh;'
  710. if [[ `$PERL -e'print (($] < 5.014)?0:1)'` -gt 0 ]]; then
  711. result[208]='RUN MyKooh DESTRUCT OurKooh'
  712. else
  713. result[208]=' MyKooh OurKooh'
  714. fi
  715. tests[210]='$a = 123;
  716. package xyz;
  717. sub xsub {bless [];}
  718. $x1 = 1; $x2 = 2;
  719. $s = join(":", sort(keys %xyz::));
  720. package abc;
  721. my $foo;
  722. print $xyz::s'
  723. result[210]='s:x1:x2:xsub'
  724. tests[212]='$blurfl = 123;
  725. {
  726. package abc;
  727. $blurfl = 5;
  728. }
  729. $abc = join(":", sort(keys %abc::));
  730. package abc;
  731. print "variable: $blurfl\n";
  732. print "eval: ". eval q/"$blurfl\n"/;
  733. package main;
  734. sub ok { 1 }'
  735. result[212]='variable: 5
  736. eval: 5'
  737. tests[214]='
  738. my $expected = "foo";
  739. sub check(_) { print( (shift eq $expected) ? "ok\n" : "not ok\n" ) }
  740. $_ = $expected;
  741. check;
  742. undef $expected;
  743. &check; # $_ not passed'
  744. result[214]='ok
  745. ok'
  746. tests[215]='eval { $@ = "t1\n"; do { die "t3\n" }; 1; }; print ":$@:\n";'
  747. result[215]=':t3
  748. :'
  749. tests[216]='eval { $::{q{@}}=42; }; print qq{ok\n}'
  750. # multideref, also now a 29
  751. tests[219]='my (%b,%h); BEGIN { %b=(1..8);@a=(1,2,3,4); %h=(1=>2,3=>4) } $i=0; my $l=-1; print $h->{$b->{3}},$h->{$a[-1]},$a[$i],$a[$l],$h{3}'
  752. result[219]='144'
  753. # also at 904
  754. tests[220]='
  755. my $content = "ok\n";
  756. while ( $content =~ m{\w}g ) {
  757. $_ .= "$-[0]$+[0]";
  758. }
  759. print "ok" if $_ eq "0112";'
  760. tests[223]='use strict; eval q({ $x = sub }); print $@'
  761. result[223]='Illegal declaration of anonymous subroutine at (eval 1) line 1.'
  762. tests[224]='use bytes; my $p = "\xB6"; my $u = "\x{100}"; my $pu = "\xB6\x{100}"; print ( $p.$u eq $pu ? "ko\n" : "ok\n" );'
  763. tests[225]='$_ = $dx = "\x{10f2}"; s/($dx)/$dx$1/; $ok = 1 if $_ eq "$dx$dx"; $_ = $dx = "\x{10f2}"; print qq{end\n};'
  764. result[225]='end'
  765. tests[226]='# WontFix
  766. @INC = (); dbmopen(%H, $file, 0666)'
  767. result[226]='No dbm on this machine at -e line 1.'
  768. tests[227]='open IN, "/dev/null" or die $!; *ARGV = *IN; foreach my $x (<>) { print $x; } close IN; print qq{ok\n}'
  769. tests[229]='sub yyy () { "yyy" } print "ok\n" if( eval q{yyy} eq "yyy");'
  770. #issue 30
  771. tests[230]='sub f1 { my($self) = @_; $self->f2;} sub f2 {} sub new {} print "@ARGV\n";'
  772. result[230]=' '
  773. tests[232]='use Carp (); exit unless Carp::longmess(); print qq{ok\n}'
  774. tests[234]='$c = 0; for ("-3" .. "0") { $c++ } ; print "$c"'
  775. result[234]='4'
  776. # t/testc.sh -O3 -Dp,-UCarp,-v 235
  777. tests[235]='BEGIN{$INC{"Carp.pm"}="/dev/null"} $d = pack("U*", 0xe3, 0x81, 0xAF); { use bytes; $ol = bytes::length($d) } print $ol'
  778. result[235]='6'
  779. # -O3
  780. tests[236]='sub t { if ($_[0] == $_[1]) { print "ok\n"; } else { print "not ok - $_[0] == $_[1]\n"; } } t(-1.2, " -1.2");'
  781. tests[237]='print "\000\000\000\000_"'
  782. result[237]='_'
  783. tests[238]='sub f ($);
  784. sub f ($) {
  785. my $test = $_[0];
  786. write;
  787. format STDOUT =
  788. ok @<<<<<<<
  789. $test
  790. .
  791. }
  792. f("");
  793. '
  794. tests[239]='my $x="1";
  795. format STDOUT =
  796. ok @<<<<<<<
  797. $x
  798. .
  799. write;print "\n";'
  800. result[239]='ok 1'
  801. tests[240]='my $a = "\x{100}\x{101}Aa";
  802. print "ok\n" if "\U$a" eq "\x{100}\x{100}AA";
  803. my $b = "\U\x{149}cD"; # no pb without that line'
  804. tests[241]='package Pickup; use UNIVERSAL qw( can ); if (can( "Pickup", "can" ) != \&UNIVERSAL::can) { print "not " } print "ok\n";'
  805. tests[242]='$xyz = ucfirst("\x{3C2}");
  806. $a = "\x{3c3}foo.bar";
  807. ($c = $a) =~ s/(\p{IsWord}+)/ucfirst($1)/ge;
  808. print "ok\n" if $c eq "\x{3a3}foo.Bar";'
  809. tests[243]='use warnings "deprecated"; print hex(${^WARNINGS}) . " "; print hex(${^H})'
  810. result[243]='0 598'
  811. tests[244]='print "($_)\n" for q{-2}..undef;'
  812. result[244]='(-2)
  813. (-1)
  814. (0)'
  815. tests[245]='sub foo {
  816. my ( $a, $b ) = @_;
  817. print "a: ".ord($a)." ; b: ".ord($b)." [ from foo ]\n";
  818. }
  819. print "a: ". ord(lc("\x{1E9E}"))." ; ";
  820. print "b: ". ord("\x{df}")."\n";
  821. foo(lc("\x{1E9E}"), "\x{df}");'
  822. result[245]='a: 223 ; b: 223
  823. a: 223 ; b: 223 [ from foo ]'
  824. # see t/issue235.t test 2
  825. tests[246]='sub foo($\@); eval q/foo "s"/; print $@'
  826. result[246]='Not enough arguments for main::foo at (eval 1) line 1, at EOF'
  827. tests[247]='# WontFix
  828. no warnings; $[ = 1; $big = "N\xabN\xab"; print qq{ok\n} if rindex($big, "N", 3) == 3'
  829. tests[248]='#WONTFIX lexical $_ in re-eval
  830. {my $s="toto";my $_="titi";{$s =~ /to(?{ print "-$_-$s-\n";})to/;}}'
  831. result[248]='-titi-toto-'
  832. tests[249]='#TODO version
  833. use version; print version::is_strict(q{01}) ? 1 : 0'
  834. result[249]='0'
  835. tests[250]='#TODO version
  836. use warnings qw/syntax/; use version; $withversion::VERSION = undef; eval q/package withversion 1.1_;/; print $@;'
  837. result[250]='Misplaced _ in number at (eval 1) line 1.
  838. Invalid version format (no underscores) at (eval 1) line 1, near "package withversion "
  839. syntax error at (eval 1) line 1, near "package withversion 1.1_"'
  840. tests[251]='sub f;print "ok" if exists &f'
  841. tests[2511]='#TODO 5.18
  842. sub f :lvalue;print "ok" if exists &f'
  843. tests[2512]='sub f ();print "ok" if exists &f'
  844. tests[2513]='sub f ($);print "ok" if exists &f'
  845. tests[2514]='sub f;print "ok" if exists &f'
  846. # duplicate of 234
  847. tests[252]='my $i = 0; for ("-3".."0") { ++$i } print $i'
  848. result[252]='4'
  849. tests[253]='INIT{require "t/TestBC.pm"}plan(tests=>2);is("\x{2665}", v9829);is(v9829,"\x{2665}");'
  850. result[253]='1..2
  851. ok 1
  852. ok 2'
  853. tests[254]='#TODO destroy upgraded lexvar
  854. my $flag = 0;
  855. sub X::DESTROY { $flag = 1 }
  856. {
  857. my $x; # x only exists in that scope
  858. BEGIN { $x = 42 } # pre-initialized as IV
  859. $x = bless {}, "X"; # run-time upgrade and bless to call DESTROY
  860. # undef($x); # value should be free when exiting scope
  861. }
  862. print "ok\n" if $flag;'
  863. # duplicate of 185, bytes_heavy
  864. tests[255]='$a = chr(300);
  865. my $l = length($a);
  866. my $lb;
  867. { use bytes; $lb = length($a); }
  868. print( ( $l == 1 && $lb == 2 ) ? "ok\n" : "l -> $l ; lb -> $lb\n" );'
  869. tests[256]='BEGIN{ $| = 1; } print "ok\n" if $| == 1'
  870. tests[2561]='BEGIN{ $/ = "1"; } print "ok\n" if $/ == "1"'
  871. tests[259]='use JSON::XS; print encode_json([\0])'
  872. result[259]='[false]'
  873. tests[260]='sub FETCH_SCALAR_ATTRIBUTES {''} sub MODIFY_SCALAR_ATTRIBUTES {''}; my $a :x=1; print $a'
  874. result[260]='1'
  875. tests[261]='q(12-feb-2015) =~ m#(\d\d?)([\-\./])(feb|jan)(?:\2(\d\d+))?#; print $4'
  876. result[261]='2015'
  877. tests[262]='use POSIX'
  878. result[262]=' '
  879. tests[263]='use JSON::XS; print encode_json []'
  880. result[263]='[]'
  881. tests[264]='no warnings; warn "$a.\n"'
  882. result[264]='.'
  883. tests[272]='$d{""} = qq{ok\n}; print $d{""};'
  884. tests[2721]='BEGIN{$d{""} = qq{ok\n};} print $d{""};'
  885. tests[273]='package Foo; use overload; sub import { overload::constant "integer" => sub { return shift }}; package main; BEGIN { $INC{"Foo.pm"} = "/lib/Foo.pm" }; use Foo; my $result = eval "5+6"; print "$result\n"'
  886. result[273]='11'
  887. tests[274]='package Foo;
  888. sub match { shift =~ m?xyz? ? 1 : 0; }
  889. sub match_reset { reset; }
  890. package Bar;
  891. sub match { shift =~ m?xyz? ? 1 : 0; }
  892. sub match_reset { reset; }
  893. package main;
  894. print "1..5\n";
  895. print "ok 1\n" if Bar::match("xyz");
  896. print "ok 2\n" unless Bar::match("xyz");
  897. print "ok 3\n" if Foo::match("xyz");
  898. print "ok 4\n" unless Foo::match("xyz");
  899. Foo::match_reset();
  900. print "ok 5\n" if Foo::match("xyz");'
  901. result[274]='1..5
  902. ok 1
  903. ok 2
  904. ok 3
  905. ok 4
  906. ok 5'
  907. tests[277]='format OUT =
  908. bar ~~
  909. .
  910. open(OUT, ">/dev/null"); write(OUT); close OUT; print q(ok)'
  911. tests[280]='package M; $| = 1; sub DESTROY {eval {print "Farewell ",ref($_[0])};} package main; bless \$A::B, q{M}; *A:: = \*B::;'
  912. result[280]='Farewell M'
  913. tests[281]='"I like pie" =~ /(I) (like) (pie)/; "@-" eq "0 0 2 7" and print "ok\n"; print "\@- = @-\n\@+ = @+\nlen \@- = ",scalar @-'
  914. result[281]='ok
  915. @- = 0 0 2 7
  916. @+ = 10 1 6 10
  917. len @- = 4'
  918. tests[282]='use vars qw($glook $smek $foof); $glook = 3; $smek = 4; $foof = "halt and cool down"; my $rv = \*smek; *glook = $rv; my $pv = ""; $pv = \*smek; *foof = $pv; print "ok\n";'
  919. tests[283]='#238 Undefined format "STDOUT"
  920. format =
  921. ok
  922. .
  923. write'
  924. tests[284]='#-O3 only
  925. my $x="123456789";
  926. format OUT =
  927. ^<<~~
  928. $x
  929. .
  930. open OUT, ">ccode.tmp";
  931. write(OUT);
  932. close(OUT);
  933. print `cat "ccode.tmp"`'
  934. result[284]='123
  935. 456
  936. 789'
  937. tests[289]='no warnings; sub z_zwap (&); print qq{ok\n} if eval q{sub z_zwap {return @_}; 1;}'
  938. tests[290]='sub f;print "ok" if exists &f && not defined &f;'
  939. tests[293]='use Coro; print q(ok)'
  940. tests[295]='"zzaaabbb" =~ m/(a+)(b+)/ and print "@- : @+\n"'
  941. result[295]='2 2 5 : 8 5 8'
  942. tests[299]='#TODO version
  943. package Pickup; use UNIVERSAL qw( VERSION ); print qq{ok\n} if VERSION "UNIVERSAL";'
  944. tests[300]='use mro;print @{mro::get_linear_isa("mro")};'
  945. result[300]='mro'
  946. tests[301]='{ package A; use mro "c3"; sub foo { "A::foo" } } { package B; use base "A"; use mro "c3"; sub foo { (shift)->next::method() } } print qq{ok\n} if B->foo eq "A::foo";'
  947. tests[305]='use constant ASCII => eval { require Encode; Encode::find_encoding("ascii"); } || 0; print ASCII->encode("www.google.com")'
  948. result[305]='www.google.com'
  949. tests[3051]='INIT{ sub ASCII { eval { require Encode; Encode::find_encoding("ASCII"); } || 0; }} print ASCII->encode("www.google.com")'
  950. result[3051]='www.google.com'
  951. tests[3052]='use Net::DNS::Resolver; my $res = Net::DNS::Resolver->new; $res->send("www.google.com"), print q(ok)'
  952. tests[365]='use constant JP => eval { require Encode; Encode::find_encoding("euc-jp"); } || 0; print JP->encode("www.google.com")'
  953. result[365]='www.google.com'
  954. tests[306]='package foo; sub check_dol_slash { print ($/ eq "\n" ? "ok" : "not ok") ; print "\n"} sub begin_local { local $/;} ; package main; BEGIN { foo::begin_local() } foo::check_dol_slash();'
  955. tests[308]='print (eval q{require Net::SSLeay;} ? qq{ok\n} : $@);'
  956. tests[309]='print $_,": ",(eval q{require }.$_.q{;} ? qq{ok\n} : $@) for qw(Net::LibIDN Net::SSLeay);'
  957. result[309]='Net::LibIDN: ok
  958. Net::SSLeay: ok'
  959. tests[310]='package foo;
  960. sub dada { my $line = <DATA> }
  961. print dada;
  962. __DATA__
  963. ok
  964. b
  965. c
  966. '
  967. tests[312]='require Scalar::Util; eval "require List::Util"; print "ok"'
  968. tests[314]='open FOO, ">", "ccode314.tmp"; print FOO "abc"; close FOO; open FOO, "<", "ccode314.tmp"; { local $/="b"; $in=<FOO>; if ($in eq "ab") { print "ok\n" } else { print qq(separator: "$/"\n\$/ is "$/"\nFAIL: "$in"\n)}}; unlink "ccode314.tmp"'
  969. tests[3141]='open FOO, ">", "ccode3141.tmp"; print FOO "abc"; close FOO; open FOO, "<", "ccode3141.tmp"; { $/="b"; $in=<FOO>; if ($in eq "ab") { print "ok\n" } else { print qq(separator: "$/"\n\$/ is "$/"\nFAIL: "$in"\n)}}; unlink "ccode3141.tmp"'
  970. tests[316]='
  971. package Diamond_A; sub foo {};
  972. package Diamond_B; use base "Diamond_A";
  973. package Diamond_C; use base "Diamond_A";
  974. package Diamond_D; use base ("Diamond_B", "Diamond_C"); use mro "c3";
  975. package main; my $order = mro::get_linear_isa("Diamond_D");
  976. print $order->[3] eq "Diamond_A" ? "ok" : "not ok"; print "\n"'
  977. tests[317]='use Net::SSLeay();use IO::Socket::SSL();Net::SSLeay::OpenSSL_add_ssl_algorithms(); my $ssl_ctx = IO::Socket::SSL::SSL_Context->new(SSL_server => 1); print q(ok)'
  978. tests[318]='{ local $\ = "ok" ; print "" }'
  979. tests[319]='#TODO Wide character warnings missing (bytes layer ignored)
  980. use warnings q{utf8}; my $w; local $SIG{__WARN__} = sub { $w = $_[0] }; my $c = chr(300); open F, ">", "a"; binmode(F, ":bytes:"); print F $c,"\n"; close F; print $w'
  981. tests[320]='#TODO No warnings reading in invalid utf8 stream (utf8 layer ignored)
  982. use warnings "utf8"; local $SIG{__WARN__} = sub { $@ = shift }; open F, ">", "a"; binmode F; my ($chrE4, $chrF6) = (chr(0xE4), chr(0xF6)); print F "foo", $chrE4, "\n"; print F "foo", $chrF6, "\n"; close F; open F, "<:utf8", "a"; undef $@; my $line = <F>; print q(ok) if $@ =~ /utf8 "\xE4" does not map to Unicode/;'
  983. tests[324]='package Master;
  984. use mro "c3";
  985. sub me { "Master" }
  986. package Slave;
  987. use mro "c3";
  988. use base "Master";
  989. sub me { "Slave of ".(shift)->next::method }
  990. package main;
  991. print Master->me()."\n";
  992. print Slave->me()."\n";
  993. '
  994. result[324]='Master
  995. Slave of Master'
  996. tests[326]='#TODO method const maybe::next::method
  997. package Diamond_C; sub maybe { "Diamond_C::maybe" } package Diamond_D; use base "Diamond_C"; use mro "c3"; sub maybe { "Diamond_D::maybe => " . ((shift)->maybe::next::method() || 0) } package main; print "ok\n" if Diamond_D->maybe;'
  998. tests[328]='#WONTFIX re-eval lex/global mixup
  999. my $code = q[{$blah = 45}]; our $blah = 12; eval "/(?$code)/"; print "$blah\n"'
  1000. result[328]=45
  1001. tests[329]='#WONTFIX re-eval lex/global mixup
  1002. $_ = q{aaa}; my @res; pos = 1; s/\Ga(?{push @res, $_, $`})/xx/g; print "ok\n" if "$_ @res" eq "axxxx aaa a aaa aa"; print "$_ @res\n"'
  1003. result[329]='ok
  1004. axxxx aaa a aaa aa'
  1005. tests[330]='"\x{101}a" =~ qr/\x{100}/i && print "ok\n"'
  1006. tests[331]='use 5.010; use charnames ":full"; my $char = q/\N{LATIN CAPITAL LETTER A WITH MACRON}/; my $a = eval qq ["$char"]; print length($a) == 1 ? "ok\n" : "$a\n".length($a)."\n"'
  1007. tests[332]='#TODO re-eval no_modify, probably WONTFIX
  1008. use re "eval"; our ( $x, $y, $z ) = 1..3; $x =~ qr/$x(?{ $y = $z++ })/; undef $@; print "ok\n"'
  1009. tests[333]='use encoding "utf8";
  1010. my @hiragana = map {chr} ord("ぁ")..ord("ん"); my @katakana = map {chr} ord("ァ")..ord("ン"); my $hiragana = join(q{} => @hiragana); my $katakana = join(q{} => @katakana); my %h2k; @h2k{@hiragana} = @katakana; $str = $hiragana; $str =~ s/([ぁ-ん])/$h2k{$1}/go; print $str eq $katakana ? "ok\n" : "not ok\n$hiragana\n$katakana\n";'
  1011. tests[338]='use utf8; my $l = "ñ"; my $re = qr/ñ/; print $l =~ $re ? qq{ok\n} : length($l)."\n".ord($l)."\n";'
  1012. tests[340]='eval q/use Net::DNS/; my $new = "IO::Socket::INET6"->can("new") or die "die at new"; my $inet = $new->("IO::Socket::INET6", LocalAddr => q/localhost/, Proto => "udp", LocalPort => undef); print q(ok) if ref($inet) eq "IO::Socket::INET6";'
  1013. # used to fail in the inc-i340 branches CORE/base/lex.t 54
  1014. tests[3401]='sub foo::::::bar { print "ok\n"; } foo::::::bar;'
  1015. # wontfix on -O3: static string *end for "main::bar"
  1016. tests[345]='eval q/use Sub::Name; 1/ or die "no Sub::Name"; subname("main::bar", sub { 42 } ); print "ok\n";'
  1017. # those work fine:
  1018. tests[3451]='eval q/use Sub::Name; 1/ or die "no Sub::Name"; subname("bar", sub { 42 } ); print "ok\n";'
  1019. tests[3452]='eval q/use Sub::Name; 1/ or die "no Sub::Name"; $bar="main::bar"; subname($bar, sub { 42 } ); print "ok\n";'
  1020. tests[348]='package Foo::Bar; sub baz { 1 }
  1021. package Foo; sub new { bless {}, shift } sub method { print "ok\n"; }
  1022. package main; Foo::Bar::baz();
  1023. my $foo = sub {
  1024. Foo->new
  1025. }->();
  1026. $foo->method;'
  1027. tests[350]='package Foo::Moose; use Moose; has bar => (is => "rw", isa => "Int");
  1028. package main; my $moose = Foo::Moose->new; print "ok" if 32 == $moose->bar(32);'
  1029. tests[368]='use EV; print q(ok)'
  1030. tests[369]='
  1031. use EV;
  1032. use Coro;
  1033. use Coro::Timer;
  1034. my @a;
  1035. push @a, async {
  1036. while() {
  1037. warn $c++;
  1038. Coro::Timer::sleep 1;
  1039. };
  1040. };
  1041. push @a, async {
  1042. while() {
  1043. warn $d++;
  1044. Coro::Timer::sleep 0.5;
  1045. };
  1046. };
  1047. schedule;
  1048. print q(ok)'
  1049. tests[371]='package foo;use Moose;
  1050. has "x" => (isa => "Int", is => "rw", required => 1);
  1051. has "y" => (isa => "Int", is => "rw", required => 1);
  1052. sub clear { my $self = shift; $self->x(0); $self->y(0); }
  1053. __PACKAGE__->meta->make_immutable;
  1054. package main;
  1055. my $f = foo->new( x => 5, y => 6);
  1056. print $f->x . "\n";'
  1057. result[371]='5'
  1058. if [[ $v518 -gt 0 ]]; then
  1059. tests[372]='use utf8; require mro; my $f_gen = mro::get_pkg_gen("ᕘ"); undef %ᕘ::; mro::get_pkg_gen("ᕘ"); delete $::{"ᕘ::"}; print "ok";'
  1060. result[372]='ok'
  1061. fi
  1062. tests[2050]='use utf8;package 텟ţ::ᴼ; sub ᴼ_or_Ḋ { "ok" } print ᴼ_or_Ḋ;'
  1063. result[2050]='ok'
  1064. tests[2051]='use utf8;package ƂƂƂƂ; sub ƟK { "ok" } package ƦƦƦƦ; use base "ƂƂƂƂ"; my $x = bless {}, "ƦƦƦƦ"; print $x->ƟK();'
  1065. result[2051]='ok'
  1066. tests[404]='use FCGI;sub test {my $s=" ";$s =~ s/ //g;print "ok $s\n";}test();'
  1067. result[404]='ok '
  1068. init
  1069. while getopts "qsScohv" opt
  1070. do
  1071. if [ "$opt" = "q" ]; then
  1072. Q=1
  1073. OCMD="$QOCMD"
  1074. qq="-qq,"
  1075. if [ "$VERS" = "5.6.2" ]; then QOCMD=$OCMD; qq=""; fi
  1076. fi
  1077. if [ "$opt" = "v" ]; then
  1078. Q=
  1079. QOCMD="$OCMD"
  1080. qq=""
  1081. fi
  1082. if [ "$opt" = "s" ]; then SKIP=1; fi
  1083. if [ "$opt" = "o" ]; then Mblib=" "; SKIP=1; SKI=1; init; fi
  1084. if [ "$opt" = "S" ]; then SKIP=1; SKI=1; fi
  1085. if [ "$opt" = "c" ]; then CONT=1; shift; fi
  1086. if [ "$opt" = "h" ]; then help; exit; fi
  1087. done
  1088. if [ -z "$Q" ]; then
  1089. make
  1090. else
  1091. make -s >/dev/null
  1092. fi
  1093. # need to shift the options
  1094. while [ -n "$1" -a "${1:0:1}" = "-" ]; do shift; done
  1095. if [ -n "$1" ]; then
  1096. while [ -n "$1" ]; do
  1097. btest $1
  1098. shift
  1099. done
  1100. else
  1101. for b in $(seq $ntests); do
  1102. btest $b
  1103. done
  1104. fi
  1105. # 5.8: all PASS
  1106. # 5.10: FAIL: 2-5, 7, 11, 15. With -D 9-12 fail also.
  1107. # 5.11: FAIL: 2-5, 7, 11, 15-16 (all segfaulting in REGEX). With -D 9-12 fail also.
  1108. # 5.11d: WRONG 4, FAIL: 9-11, 15-16
  1109. # 5.11d linux: WRONG 4, FAIL: 11, 16
  1110. #only if ByteLoader installed in @INC
  1111. if false; then
  1112. echo ${OCMD}-H,-obytecode2.plc bytecode2.pl
  1113. ${OCMD}-H,-obytecode2.plc bytecode2.pl
  1114. chmod +x bytecode2.plc
  1115. echo ./bytecode2.plc
  1116. ./bytecode2.plc
  1117. fi
  1118. # package pmc
  1119. if false; then
  1120. echo "package MY::Test;" > bytecode1.pm
  1121. echo "print 'hi'" >> bytecode1.pm
  1122. echo ${OCMD}-m,-obytecode1.pmc bytecode1.pm
  1123. ${OCMD}-obytecode1.pmc bytecode1.pm
  1124. fi