testc.sh 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. #!/bin/bash
  2. # t/testc.sh -c -Du,-q -B static 2>&1 |tee c.log|grep FAIL
  3. # for p in 5.6.2 5.8.8-nt 5.8.9d 5.10.1d 5.10.1d-nt 5.11.2d 5.11.2d-nt; do make -s clean; echo perl$p; perl$p Makefile.PL; t/testc.sh -q -O0 31; done
  4. # quiet c only: t/testc.sh -q -O0
  5. # t/testcc.sh -DOscpSql,-v,-UB::Concise,-UIO::File,-UIO::Handle,-Uwarnings
  6. function help {
  7. echo "t/testc.sh [OPTIONS] [1-$ntests]"
  8. echo " -D<debugflags> for O=C or O=CC. Default: C,-DspmF,-v resp. CC,-DOscpSql,-v"
  9. echo " -O<0-4> optimization level"
  10. echo " -f<opt> special optimization"
  11. echo " -B<static|dynamic> pass to cc_harness"
  12. echo " -c continue on errors"
  13. echo " -k keep temp. files on PASS"
  14. echo " -E dump preprocessed source file with cc -E as _E.c"
  15. echo " -o orig. no -Mblib, use installed modules (5.6, 5.8)"
  16. echo " -a all. undo -Du. Unsilence scanning unused sub"
  17. echo " -A -DALLOW_PERL_OPTIONS"
  18. echo " -q quiet"
  19. echo " -h help"
  20. echo "Without arguments try all $ntests tests. Without Option -Ox try -O0 to -O3 optimizations."
  21. }
  22. # use the actual perl from the Makefile (perl5.8.8,
  23. # perl5.10.0d-nt, perl5.11.0, ...)
  24. PERL=`grep "^PERL =" Makefile|cut -c8-`
  25. PERL=${PERL:-perl}
  26. v518=`$PERL -e'print (($] < 5.018)?0:1)'`
  27. function init {
  28. BASE=`basename $0`
  29. # if $] < 5.9 you may want to remove -Mblib for testing the core lib. -o
  30. #Mblib="`$PERL -e'print (($] < 5.009005) ? q() : q(-Mblib))'`"
  31. Mblib=${Mblib:--Iblib/arch -Iblib/lib} # B::C is now fully 5.6+5.8 backwards compatible
  32. v513="`$PERL -e'print (($] < 5.013005) ? q() : q(-fno-fold,-fno-warnings,))'`"
  33. # OCMD=${OCMD}${v513}
  34. if [ -z "$Mblib" ]; then
  35. VERS="${VERS}_global";
  36. OCMD="$PERL $Mblib -MO=C,${v513}-Dcsp,"
  37. if [ $BASE = "testcc.sh" ]; then # DrOsplt
  38. OCMD="$PERL $Mblib -MO=CC,${v513}-DOsplt,"
  39. fi
  40. else
  41. OCMD="$PERL $Mblib -MO=C,${v513}-DspF,-v,"
  42. if [ $BASE = "testcc.sh" ]; then # DoOscprSql
  43. OCMD="$PERL $Mblib -MO=CC,${v513}-DOscpSql,-v,"
  44. fi
  45. fi
  46. CONT=
  47. # 5.6: rather use -B static
  48. #CCMD="$PERL script/cc_harness -g3"
  49. # rest. -DALLOW_PERL_OPTIONS for -Dtlv
  50. #CCMD="$PERL $Mblib script/cc_harness -g3 -DALLOW_PERL_OPTIONS"
  51. CCMD="$PERL $Mblib script/cc_harness"
  52. LCMD=
  53. # On some perls I also had to add $archlib/DynaLoader/DynaLoader.a to libs in Config.pm
  54. }
  55. function vcmd {
  56. test -n "$QUIET" || echo $*
  57. $*
  58. }
  59. function pass {
  60. echo -e -n "\033[1;32mPASS \033[0;0m"
  61. echo $*
  62. }
  63. function fail {
  64. echo -e -n "\033[1;31mFAIL \033[0;0m"
  65. echo $*
  66. }
  67. function runopt {
  68. o=$1
  69. optim=$2
  70. OCMDO1="$(echo $OCMD|sed -e s/C,/C,-O$optim,/)"
  71. suff="_o${optim}"
  72. if [ "$optim" == "0" ]; then suff=""; fi
  73. rm ${o}${suff} ${o}${suff}.c 2> /dev/null
  74. if [ $optim -lt 5 ]; then CMD=$OCMDO1
  75. else CMD=$OCMD
  76. fi
  77. if [ "$o" = "ccode46" -o "$o" = "cccode46" ]; then
  78. CMD="$CMD-fstash,"
  79. fi
  80. if [ -z $qq ]; then
  81. vcmd ${CMD}-o${o}${suff}.c $o.pl 2>&1 | grep -v "$o.pl syntax OK"
  82. else
  83. vcmd ${CMD}-o${o}${suff}.c $o.pl
  84. fi
  85. test -z $CPP || vcmd $CCMD ${o}${suff}.c -c -E -o ${o}${suff}_E.c
  86. test -n "$QUIET" || echo ${CMD}-o${o}${suff}.c $o.pl
  87. vcmd $CCMD ${o}${suff}.c $LCMD -o ${o}${suff}
  88. test -x ${o}${suff} || (test -z $CONT && exit)
  89. if [ -z "$QUIET" ]; then echo "./${o}${suff}"
  90. else echo -n "./${o}${suff} "
  91. fi
  92. mem=$(ulimit -m 2>/dev/null)
  93. err=$?
  94. test -z $err && ulimit -S -m 50000
  95. res=$(./${o}${suff}) || fail "./${o}${suff}" "errcode $?"
  96. test -z $err && ulimit -S -m $mem
  97. if [ "X$res" = "X${result[$n]}" ]; then
  98. test "X$res" = "X${result[$n]}" && pass "./${o}${suff}" "=> '$res'"
  99. if [ -z $KEEP ]; then rm ${o}${suff}_E.c ${o}${suff}.c ${o}${suff} 2>/dev/null; fi
  100. true
  101. else
  102. fail "./${o}${suff}" "=> '$str' => '$res'. Expected: '${result[$n]}'"
  103. false
  104. fi
  105. }
  106. function ctest {
  107. n=$1
  108. str=$2
  109. if [ $BASE = "testcc.sh" ]; then
  110. o="cccode$n"
  111. else
  112. o="ccode$n"
  113. fi
  114. if [ -z "$str" ]; then
  115. if [ "$n" = "08" ]; then n=8; fi
  116. if [ "$n" = "09" ]; then n=9; fi
  117. echo "${tests[${n}]}" > ${o}.pl
  118. str="${tests[${n}]}"
  119. else
  120. echo "$str" > ${o}.pl
  121. fi
  122. if [ -z "$str" ]; then
  123. true
  124. else
  125. if [ $OPTIM -ge 0 ]; then
  126. runopt "$o" "$OPTIM"
  127. else # -1
  128. rm $o.c $o ${o}_o.c ${o}_o 2> /dev/null
  129. vcmd ${OCMD}-o$o.c $o.pl
  130. test -s $o.c || (echo "empty $o.c"; test -z $CONT && exit 2)
  131. test -z $CPP || vcmd $CCMD $o.c -c -E -o ${o}_E.c
  132. test -n "$QUIET" || echo ${OCMD}-o$o.c $o.pl
  133. vcmd $CCMD $o.c $LCMD -o $o
  134. test -x $o || (test -z $CONT && exit)
  135. if [ -z "$QUIET" ]; then echo "./$o"
  136. else echo -n "./$o "
  137. fi
  138. res=$(./$o) || (fail "./${o}${suff}" "'$?' = $?"; test -z $CONT && exit 1)
  139. if [ "X$res" = "X${result[$n]}" ]; then
  140. pass "./$o" "'$str' => '$res'"
  141. if [ -z $KEEP ]; then rm ${o}_E.c ${o}.c ${o} 2>/dev/null; fi
  142. if [ $BASE = "testcc.sh" ]; then
  143. runopt $o 1 && \
  144. runopt $o 2
  145. else
  146. runopt $o 1 && \
  147. runopt $o 2 && \
  148. runopt $o 3 && \
  149. runopt $o 4
  150. fi
  151. true
  152. else
  153. fail "./$o" "'$str' => '$res' Expected: '${result[$n]}'"
  154. test -z $CONT && exit 3
  155. fi
  156. fi
  157. fi
  158. }
  159. ntests=300
  160. declare -a tests[$ntests]
  161. declare -a result[$ntests]
  162. ncctests=23
  163. declare -a cctests[$((100+$ncctests))]
  164. declare -a ccresult[$((100+$ncctests))]
  165. tests[1]='print "hi"'
  166. result[1]='hi'
  167. tests[2]='for (1,2,3) { print if /\d/ }'
  168. result[2]='123'
  169. tests[3]='$_ = "xyxyx"; %j=(1,2); s/x/$j{print("z")}/ge; print $_'
  170. result[3]='zzz2y2y2'
  171. tests[4]='$_ = "xyxyx"; %j=(1,2); s/x/$j{print("z")}/g; print $_'
  172. if [[ $v518 -gt 0 ]]; then
  173. result[4]='zzz2y2y2'
  174. else
  175. result[4]='z2y2y2'
  176. fi
  177. tests[5]='print split /a/,"bananarama"'
  178. result[5]='bnnrm'
  179. tests[6]="{package P; sub x {print 'ya'} x}"
  180. result[6]='ya'
  181. tests[7]='@z = split /:/,"b:r:n:f:g"; print @z'
  182. result[7]='brnfg'
  183. tests[8]='sub AUTOLOAD { print 1 } &{"a"}()'
  184. result[8]='1'
  185. tests[9]='my $l_i = 3; $x = sub { print $l_i }; &$x'
  186. result[9]='3'
  187. tests[10]='my $i_i = 1;
  188. my $foo = sub {
  189. $i_i = shift if @_
  190. }; print $i_i;
  191. print &$foo(3),$i_i;'
  192. result[10]='133'
  193. # index: do fbm_compile or not
  194. tests[11]='$x="Cannot use"; print index $x, "Can"'
  195. result[11]='0'
  196. tests[12]='my $i_i=6; eval "print \$i_i\n"; print ""'
  197. result[12]='6'
  198. tests[13]='BEGIN { %h=(1=>2,3=>4) } print $h{3}'
  199. result[13]='4'
  200. tests[14]='open our $T,"a"; print "ok";'
  201. result[14]='ok'
  202. # __DATA__ handles still broken non-threaded 5.10
  203. tests[15]='print <DATA>
  204. __DATA__
  205. a
  206. b'
  207. result[15]='a
  208. b'
  209. tests[16]='BEGIN{tie @a, __PACKAGE__;sub TIEARRAY {bless{}} sub FETCH{1}}; print $a[1]'
  210. result[16]='1'
  211. tests[17]='my $i_ir=3; print 1 .. $i_ir'
  212. result[17]='123'
  213. # custom key sort
  214. tests[18]='my $h = { a=>3, b=>1 }; print sort {$h->{$a} <=> $h->{$b}} keys %$h'
  215. result[18]='ba'
  216. # fool the sort optimizer by my $p, pp_sort works ok on CC
  217. tests[19]='print sort { my $p; $b <=> $a } 1,4,3'
  218. result[19]='431'
  219. # not repro: something like this is broken in original 5.6 (Net::DNS::ZoneFile::Fast)
  220. # see new test 33
  221. tests[20]='$a="abcd123";my $r=qr/\d/;print $a =~ $r;'
  222. result[20]='1'
  223. # broken on early alpha and 5.10: run-time labels.
  224. tests[21]='sub skip_on_odd{next NUMBER if $_[0]% 2}NUMBER:for($i=0;$i<5;$i++){skip_on_odd($i);print $i;}'
  225. result[21]='024'
  226. # broken in original perl 5.6
  227. tests[22]='my $fh; BEGIN { open($fh,"<","/dev/null"); } print "ok";';
  228. result[22]='ok'
  229. # broken in perl 5.8
  230. tests[23]='package MyMod; our $VERSION = 1.3; print "ok";'
  231. result[23]='ok'
  232. # works in original perl 5.6, broken with latest B::C in 5.6, 5.8
  233. tests[24]='sub level1{return(level2()?"fail":"ok")} sub level2{0} print level1();'
  234. result[24]='ok'
  235. # enforce custom ncmp sort and count it. fails as CC in all. How to enforce icmp?
  236. # <=5.6 qsort needs two more passes here than >=5.8 merge_sort
  237. # 5.12 got it backwards and added 4 more passes.
  238. tests[25]='print sort { $i++; $b <=> $a } 1..4'
  239. result[25]="4321"
  240. # lvalue sub
  241. tests[26]='sub a:lvalue{my $a=26; ${\(bless \$a)}}sub b:lvalue{${\shift}}; print ${a(b)}';
  242. result[26]="26"
  243. # xsub constants (constant folded). newlib: 0x200, glibc: 0x100
  244. tests[27]='use Fcntl ();my $a=Fcntl::O_CREAT(); print "ok" if ( $a >= 64 && &Fcntl::O_CREAT >= 64 );'
  245. result[27]='ok'
  246. # require $fname
  247. 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;'
  248. result[28]='ok'
  249. # special old IO handling
  250. tests[29]='use IO;print "ok"'
  251. result[29]='ok'
  252. # run-time context of .., fails in CC
  253. tests[30]='@a=(4,6,1,0,0,1);sub range{(shift @a)..(shift @a)}print range();while(@a){print scalar(range())}'
  254. result[30]='456123E0'
  255. # AUTOLOAD w/o goto xsub
  256. 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");'
  257. result[31]='date;who am i;ls -l;'
  258. # CC entertry/jmpenv_jump/leavetry
  259. tests[32]='eval{print "1"};eval{die 1};print "2";'
  260. result[32]='12'
  261. # C qr test was broken in 5.6 -- needs to load an actual file to test. See test 20.
  262. # 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.
  263. # fails with new constant only. still not repro (r-magic probably)
  264. tests[33]='BEGIN{unshift @INC,("t");} use qr_loaded_module; print "ok" if qr_loaded_module::qr_called_in_sub("name1")'
  265. result[33]='ok'
  266. # init of magic hashes. %ENV has e magic since a0714e2c perl.c
  267. # (Steven Schubiger 2006-02-03 17:24:49 +0100 3967) i.e. 5.8.9 but not 5.8.8
  268. tests[34]='my $x=$ENV{TMPDIR};print "ok"'
  269. result[34]='ok'
  270. # static method_named. fixed with 1.16
  271. 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")'
  272. result[35]='01234'
  273. # HV self-ref
  274. tests[36]='my ($rv, %hv); %hv = ( key => \$rv ); $rv = \%hv; print "ok";'
  275. result[36]='ok'
  276. # AV self-ref
  277. tests[37]='my ($rv, @av); @av = ( \$rv ); $rv = \@av; print "ok";'
  278. result[37]='ok'
  279. # constant autoload loop crash test
  280. 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"; }'
  281. result[38]='ok'
  282. # check re::is_regexp, and on 5.12 if being upgraded to SVt_REGEXP
  283. # => Undefined subroutine &re::is_regexp with B-C-1.19, even with -ure
  284. tests[39]='{$a=qr/x/;print($]<5.010?1:re::is_regexp($a))}'
  285. result[39]='1'
  286. # String with a null byte -- used to generate broken .c on 5.6.2 with static pvs
  287. tests[40]='my $var="this string has a null \\000 byte in it";print "ok";'
  288. result[40]='ok'
  289. # Shared scalar, n magic. => Don't know how to handle magic of type \156.
  290. usethreads=""
  291. #usethreads="`$PERL -MConfig -e'print ($Config{useithreads} ? q(use threads;) : q())'`"
  292. #usethreads='BEGIN{use Config; unless ($Config{useithreads}) {print "ok"; exit}} '
  293. #;threads->create(sub{$s="ok"})->join;
  294. # not yet testing n, only P
  295. tests[41]=$usethreads'use threads::shared;{my $s="ok";share($s);print $s}'
  296. result[41]='ok'
  297. # Shared aggregate, P magic
  298. tests[42]=$usethreads'use threads::shared;my %h : shared; print "ok"'
  299. result[42]='ok'
  300. # Aggregate element, n + p magic
  301. tests[43]=$usethreads'use threads::shared;my @a : shared; $a[0]="ok"; print $a[0]'
  302. result[43]='ok'
  303. # perl #72922 (5.11.4 fails with magic_killbackrefs)
  304. tests[44]='use Scalar::Util "weaken";my $re1=qr/foo/;my $re2=$re1;weaken($re2);print "ok" if $re3=qr/$re1/;'
  305. result[44]='ok'
  306. # test dynamic loading
  307. tests[45]='use Data::Dumper ();Data::Dumper::Dumpxs({});print "ok";'
  308. result[45]='ok'
  309. # issue 79: Exporter:: stash missing in main::
  310. #tests[46]='use Exporter; if (exists $main::{"Exporter::"}) { print "ok"; }'
  311. tests[46]='use Exporter; print "ok" if %main::Exporter::'
  312. #tests[46]='use Exporter; print "ok" if scalar(keys(%main::Exporter::)) > 2'
  313. result[46]='ok'
  314. # non-tied av->MAGICAL
  315. tests[47]='@ISA=(q(ok));print $ISA[0];'
  316. result[47]='ok'
  317. # END block del_backref with bytecode only
  318. tests[48]='my $s=q{ok};END{print $s}'
  319. result[48]='ok'
  320. # even this failed until r1000 (AvFILL 3 of END)
  321. #tests[48]='print q{ok};END{}'
  322. #result[48]='ok'
  323. # no-fold
  324. tests[49]='print q(ok) if "test" =~ /es/i;'
  325. result[49]='ok'
  326. # @ISA issue 64
  327. tests[50]='package Top;sub top{q(ok)};package Next;our @ISA=qw(Top);package main;print Next->top();'
  328. result[50]='ok'
  329. # XXX TODO sigwarn $w = B::NULL without -v
  330. tests[51]='$SIG{__WARN__}=sub{print "ok"};warn 1;'
  331. result[51]='ok'
  332. # check if general signals work
  333. tests[511]='BEGIN{$SIG{USR1}=sub{$w++;};} kill USR1 => $$; print q(ok) if $w';
  334. result[511]='ok'
  335. #-------------
  336. # issue27
  337. tests[527]='require LWP::UserAgent;print q(ok);'
  338. result[527]='ok'
  339. #issue 24
  340. tests[224]='dbmopen(%H,q(f),0644);print q(ok);'
  341. result[224]='ok'
  342. tests[68]='package A;
  343. sub test {
  344. use Data::Dumper ();
  345. /^(.*?)\d+$/;
  346. "Some::Package"->new();
  347. }
  348. print "ok"'
  349. result[68]='ok'
  350. # issue71
  351. tests[71]='
  352. package my;
  353. our @a;
  354. sub f {
  355. my($alias,$name)=@_;
  356. unshift(@a, $alias => $name);
  357. my $find = "ok";
  358. my $val = $a[1];
  359. if ( ref($alias) eq "Regexp" && $find =~ $alias ) {
  360. eval $val;
  361. }
  362. $find
  363. }
  364. package main;
  365. *f=*my::f;
  366. print "ok" if f(qr/^(.*)$/ => q("\L$1"));'
  367. result[71]="ok"
  368. # object call: method_named with args.
  369. tests[72]='package dummy;sub meth{print "ok"};package main;my dummy $o = bless {},"dummy"; $o->meth("const")'
  370. result[72]='ok'
  371. # object call: dynamic method_named with args.
  372. tests[73]='package dummy;sub meth{print "ok"};package main;my $meth="meth";my $o = bless {},"dummy"; $o->$meth("const")'
  373. result[73]='ok'
  374. tests[74]='package dummy;
  375. my $invoked_as_script = !caller();
  376. __PACKAGE__->script(@ARGV) if $invoked_as_script;
  377. sub script {my($package,@args)=@_;print "ok"}'
  378. result[74]='ok'
  379. # issue 71_2+3: cop_warnings issue76 and const destruction issue71 fixed
  380. # ok with "utf-8-strict"
  381. tests[75]='use Encode;
  382. my $x = "abc";
  383. print "ok" if "abc" eq Encode::decode("UTF-8", $x);'
  384. result[75]='ok'
  385. tests[76]='use warnings;
  386. { no warnings q(void); # issue76 lexwarn
  387. length "ok";
  388. print "ok"
  389. };'
  390. result[76]='ok'
  391. tests[81]='sub int::check {1} #create int package for types
  392. sub x(int,int) { @_ } #cvproto
  393. my $o = prototype \&x;
  394. if ($o eq "int,int") {print "o"}else{print $o};
  395. sub y($) { @_ } #cvproto
  396. my $p = prototype \&y;
  397. if ($p eq q($)) {print "k"}else{print $p};
  398. require bytes;
  399. sub my::length ($) { # possible prototype mismatch vs _
  400. if ( bytes->can(q(length)) ) {
  401. *length = *bytes::length;
  402. goto &bytes::length;
  403. }
  404. return CORE::length( $_[0] );
  405. }
  406. print my::length($p);'
  407. result[81]='ok1'
  408. tests[90]='my $s = q(test string);
  409. $s =~ s/(?<first>test) (?<second>string)/\2 \1/g;
  410. print q(o) if $s eq q(string test);
  411. q(test string) =~ /(?<first>\w+) (?<second>\w+)/;
  412. print q(k) if $+{first} eq q(test);'
  413. result[90]='ok'
  414. tests[901]='my %errs = %!; # t/op/magic.t Errno compiled in
  415. print q(ok) if defined ${"!"}{ENOENT};'
  416. result[901]='ok'
  417. tests[902]='my %errs = %{"!"}; # t/op/magic.t Errno to be loaded at run-time
  418. print q(ok) if defined ${"!"}{ENOENT};'
  419. result[902]='ok'
  420. # issue #199
  421. tests[903]='"abc" =~ /(.)./; print "ok" if "21" eq join"",@+;'
  422. result[903]='ok'
  423. # issue #220
  424. tests[904]='my $content = "ok\n";
  425. while ( $content =~ m{\w}g ) {
  426. $_ .= "$-[0]$+[0]";
  427. }
  428. print "ok" if $_ eq "0112";'
  429. result[904]='ok'
  430. # IO handles
  431. tests[91]='# issue59
  432. use strict;
  433. use warnings;
  434. use IO::Socket;
  435. my $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "perl.org", PeerPort => "80" );
  436. print $remote "GET / HTTP/1.0" . "\r\n\r\n";
  437. my $result = <$remote>;
  438. $result =~ m|HTTP/1.1 200 OK| ? print "ok" : print $result;
  439. close $remote;'
  440. result[91]='ok'
  441. tests[93]='#SKIP
  442. my ($pid, $out, $in);
  443. BEGIN {
  444. local(*FPID);
  445. $pid = open(FPID, "echo <<EOF |"); # DIE
  446. open($out, ">&STDOUT"); # EASY
  447. open(my $tmp, ">", "pcc.tmp"); # HARD to get filename, WARN
  448. print $tmp "test\n";
  449. close $tmp; # OK closed
  450. open($in, "<", "pcc.tmp"); # HARD to get filename, WARN
  451. }
  452. # === run-time ===
  453. print $out "o";
  454. kill 0, $pid; # BAD! warn? die?
  455. print "k" if "test" eq read $in, my $x, 4;
  456. unlink "pcc.tmp";
  457. '
  458. result[93]='o'
  459. tests[931]='my $f;BEGIN{open($f,"<README");}read $f,my $in, 2; print "ok"'
  460. result[931]='ok'
  461. tests[932]='my $f;BEGIN{open($f,">&STDOUT");}print $f "ok"'
  462. result[932]='ok'
  463. tests[95]='use IO::Socket::SSL();
  464. my IO::Handle $handle = IO::Socket::SSL->new(SSL_verify_mode =>0);
  465. $handle->blocking(0);
  466. print "ok";'
  467. result[95]='ok'
  468. tests[96]='defined(&B::OP::name) || print q(ok)'
  469. result[96]='ok'
  470. tests[97]='use v5.12; print q(ok);'
  471. result[97]='ok'
  472. # from here on we test CC specifics only
  473. # CC types and arith
  474. tests[101]='my ($r_i,$i_i,$d_d)=(0,2,3.0); $r_i=$i_i*$i_i; $r_i*=$d_d; print $r_i;'
  475. result[101]='12'
  476. # CC cond_expr, stub, scope
  477. tests[102]='if ($x eq "2"){}else{print "ok"}'
  478. result[102]='ok'
  479. # CC stringify, srefgen. TODO: use B; fails
  480. tests[103]='require B; my $x=1e1; my $s="$x"; print ref B::svref_2object(\$s)'
  481. result[103]='B::PV'
  482. # CC reset
  483. tests[104]='@a=(1..4);while($a=shift@a){print $a;}continue{$a=~/2/ and reset q(a);}'
  484. result[104]='12'
  485. # CC -ftype-attr
  486. #tests[105]='$int::dummy=0;$double::dummy=0;my int $r;my $i:int=2;our double $d=3.0; $r=$i*$i; $r*=$d; print $r;'
  487. tests[105]='%int::;%double::;my int $r;my int $i=2;our double $d=3.0; $r=$i*$i; $r*=$d; print $r;'
  488. result[105]='12'
  489. # issue 296
  490. tests[106]='my $s=q{ok};END{print $s}END{$x = 0}'
  491. result[106]='ok'
  492. # issue31
  493. tests[131]='package Ccode31i;my $regex = qr/\w+/;sub test {print ("word" =~ m/^$regex$/o ? "ok\n" : "not ok\n");}
  494. package main; &Ccode31i::test();'
  495. result[131]='ok'
  496. # issue35
  497. tests[110]='sub new{}sub test{{my $x=1;my $y=$x+1;}my $x=2;if($x!=3){4;}}'
  498. result[110]=''
  499. # issue36
  500. tests[111]='sub f{shift==2}sub test{while(1){last if f(2);}while(1){last if f(2);}}'
  501. result[111]=''
  502. # issue37
  503. tests[112]='my $x;$x||=1;print "ok" if $x;'
  504. result[112]='ok'
  505. # issue38
  506. tests[113]='my $x=2;$x=$x||3;print "ok" if $x==2;'
  507. result[113]='ok'
  508. # issue39
  509. tests[114]='sub f1{0}sub f2{my $x;if(f1()){}if($x){}else{[$x]}}my @a=f2();print "ok";'
  510. result[114]='ok'
  511. # issue42
  512. tests[115]='sub f1{1}f1();print do{7;2},"\n";'
  513. result[115]='2'
  514. # issue44
  515. tests[116]='my @a=(1,2);print $a[0],"\n";'
  516. result[116]='1'
  517. # issue45
  518. tests[117]='my $x;$x//=1;print "ok" if $x;'
  519. result[117]='ok'
  520. # issue46
  521. tests[118]='my $pattern="x";"foo"=~/$pattern/o;print "ok";'
  522. result[118]='ok'
  523. # issue47
  524. tests[119]='my $f=sub{while(1){return(1);}};print $f->(),"\n";'
  525. result[119]='1'
  526. # issue48
  527. tests[120]='sub f{()}print((my ($v)=f())?1:2,"\n");'
  528. result[120]='2'
  529. # issue49
  530. tests[121]='while(1){while(1){last;}last;}print "ok"'
  531. result[121]='ok'
  532. # issue51
  533. tests[122]='my ($p1,$p2)=(80,80);if($p1<=23&&23<=$p2){print "telnet\n";}elsif ($p1 <= 80 && 80 <= $p2){print "http\n";}else{print "fail\n"}'
  534. result[122]='http'
  535. # issue52
  536. tests[123]='my $x;my $y = 1;$x and $y == 2;print $y == 1 ? "ok\n" : "fail\n";'
  537. result[123]='ok'
  538. # issue125 DynaLoader::bootstrap_inherit [perl #119577]
  539. tests[125]='use Net::LibIDN; print q(ok);'
  540. result[125]='ok'
  541. # saving recursive functions sometimes recurses in the compiler. this not, but Moose stucks in Pod::Simple
  542. tests[99]='package my;sub recurse{my $i=shift;recurse(++$i)unless $i>5000;print"ok";exit};package main;my::recurse(1)'
  543. result[99]='ok'
  544. if [[ $v518 -gt 0 ]]; then
  545. tests[130]='no warnings "experimental::lexical_subs";use feature "lexical_subs";my sub p{q(ok)}; my $a=\&p;print p;'
  546. result[130]='ok'
  547. fi
  548. tests[138]='print map { chr $_ } qw/97 98 99/;'
  549. result[138]='abc'
  550. tests[140]='my %a;print "ok" if !%a;'
  551. result[140]='ok'
  552. #tests[141]='print "ok" if "1" > 0'
  553. tests[141]='@x=(0..1);print "ok" if $#x == "1"'
  554. result[141]='ok'
  555. tests[142]='$_ = "abc\x{1234}";chop;print "ok" if $_ eq "abc"'
  556. result[142]='ok'
  557. tests[143]='BEGIN {
  558. package Net::IDN::Encode;
  559. our $DOT = qr/[\.]/; #works with my!
  560. my $RE = qr/xx/;
  561. sub domain_to_ascii {
  562. my $x = shift || "";
  563. $x =~ m/$RE/o;
  564. return split( qr/($DOT)/o, $x);
  565. }
  566. }
  567. package main;
  568. Net::IDN::Encode::domain_to_ascii(42);
  569. print "ok\n";'
  570. result[143]='ok'
  571. tests[1431]='BEGIN{package Foo;our $DOT=qr/[.]/;};package main;print "ok\n" if "dot.dot" =~ m/($Foo::DOT)/'
  572. result[1431]='ok'
  573. tests[1432]='BEGIN{$DOT=qr/[.]/}print "ok\n" if "dot.dot" =~ m/($DOT)/'
  574. result[1432]='ok'
  575. tests[144]='print index("long message\0xx","\0")'
  576. result[144]='12'
  577. tests[145]='my $bits = 0; for (my $i = ~0; $i; $i >>= 1) { ++$bits; }; print $bits'
  578. result[145]=`$PERL -MConfig -e'print 8*$Config{ivsize}'`
  579. tests[146]='my $a = v120.300; my $b = v200.400; $a ^= $b; print sprintf("%vd", $a);'
  580. result[146]='176.188'
  581. tests[148]='open(FH, ">", "ccode148i.tmp"); print FH "1\n"; close FH; print -s "ccode148i.tmp"'
  582. result[148]='2'
  583. tests[150]='print NONEXISTENT "foo"; print "ok" if $! == 9'
  584. result[150]='ok'
  585. tests[1501]='$! = 0; print NONEXISTENT "foo"; print "ok" if $! == 9'
  586. result[1501]='ok'
  587. tests[152]='print "ok" if find PerlIO::Layer "perlio"'
  588. result[152]='ok'
  589. tests[154]='$SIG{__WARN__} = sub { die "warning: $_[0]" }; opendir(DIR, ".");closedir(DIR);print q(ok)'
  590. result[154]='ok'
  591. tests[156]='use warnings;
  592. no warnings qw(portable);
  593. use XSLoader;
  594. XSLoader::load() if $ENV{force_xsloader}; # trick for perlcc to force xloader to be compiled
  595. {
  596. my $q = 12345678901;
  597. my $x = sprintf("%llx", $q);
  598. print "ok\n" if hex $x == 0x2dfdc1c35;
  599. exit;
  600. }'
  601. result[156]='ok'
  602. tests[157]='$q = 18446744073709551615;print scalar($q)."\n";print scalar(18446744073709551615)."\n";'
  603. result[157]='18446744073709551615
  604. 18446744073709551615'
  605. tests[1571]='my $a = 9223372036854775807; print "ok\n" if ++$a == 9223372036854775808;'
  606. result[1571]='ok'
  607. # duplicate of 148
  608. 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";'
  609. result[158]='0'
  610. tests[159]='@X::ISA = "Y"; sub Y::z {"Y::z"} print "ok\n" if X->z eq "Y::z"; delete $X::{z}; exit'
  611. result[159]='ok'
  612. # see 188
  613. tests[160]='sub foo { (shift =~ m?foo?) ? 1 : 0 }
  614. print "ok\n";'
  615. result[160]='ok'
  616. tests[161]='sub PVBM () { foo } { my $dummy = index foo, PVBM } print PVBM'
  617. result[161]='foo'
  618. # duplicate of 142
  619. tests[162]='$x = "\x{1234}"; print "ok\n" if ord($x) == 0x1234;'
  620. result[162]='ok'
  621. tests[163]='# WontFix
  622. my $destroyed = 0;
  623. sub X::DESTROY { $destroyed = 1 }
  624. {
  625. my $x;
  626. BEGIN {$x = sub { } }
  627. $x = bless {}, 'X';
  628. }
  629. print qq{ok\n} if $destroyed == 1;'
  630. result[163]='ok'
  631. # duplicate of 148
  632. tests[164]='open(DUPOUT,">&STDOUT");close(STDOUT);open(F,">&DUPOUT");print F "ok\n";'
  633. result[164]='ok'
  634. tests[165]='use warnings;
  635. sub recurse1 {
  636. unshift @_, "x";
  637. no warnings "recursion";
  638. goto &recurse2;
  639. }
  640. sub recurse2 {
  641. my $x = shift;
  642. $_[0] ? +1 + recurse1($_[0] - 1) : 0
  643. }
  644. print "ok\n" if recurse1(500) == 500;'
  645. result[165]='ok'
  646. tests[166]='my $ok = 1;
  647. foreach my $chr (60, 200, 600, 6000, 60000) {
  648. my ($key, $value) = (chr ($chr) . "\x{ABCD}", "$chr\x{ABCD}");
  649. chop($key, $value);
  650. my %utf8c = ( $key => $value );
  651. my $tempval = sprintf q($utf8c{"\x{%x}"}), $chr;
  652. my $ev = eval $tempval;
  653. $ok = 0 if !$ev or $ev ne $value;
  654. } print "ok" if $ok'
  655. result[166]='ok'
  656. tests[167]='$a = "a\xFF\x{100}";
  657. eval {$b = crypt($a, "cd")};
  658. print $@;'
  659. result[167]='Wide character in crypt at ccode167.pl line 2.'
  660. tests[168]='my $start_time = time;
  661. eval {
  662. local $SIG{ALRM} = sub { die "ALARM !\n" };
  663. alarm 1;
  664. # perlfunc recommends against using sleep in combination with alarm.
  665. 1 while (time - $start_time < 3);
  666. };
  667. alarm 0;
  668. print $@;
  669. print "ok\n" if $@ eq "ALARM !\n";'
  670. result[168]='ALARM !
  671. ok'
  672. tests[169]='# TODO
  673. package MyTest;
  674. use Attribute::Handlers;
  675. sub Check :ATTR {
  676. print "called\n";
  677. print "ok\n" if ref $_[4] eq "ARRAY" && join(",", @{$_[4]}) eq join(",", qw/a b c/);
  678. }
  679. sub a_sub :Check(qw/a b c/) {
  680. return 42;
  681. }
  682. print a_sub()."\n";'
  683. result[169]='called
  684. ok
  685. 42'
  686. tests[170]='eval "sub xyz (\$) : bad ;"; print "~~~~\n$@~~~~\n"'
  687. result[170]='~~~~
  688. Invalid CODE attribute: bad at (eval 1) line 1.
  689. BEGIN failed--compilation aborted at (eval 1) line 1.
  690. ~~~~'
  691. tests[172]='package Foo;
  692. use overload q("") => sub { "Foo" };
  693. package main;
  694. my $foo = bless {}, "Foo";
  695. print "ok " if "$foo" eq "Foo";
  696. print "$foo\n";'
  697. result[172]='ok Foo'
  698. tests[173]='# WontFix
  699. use constant BEGIN => 42; print "ok 1\n" if BEGIN == 42;
  700. use constant INIT => 42; print "ok 2\n" if INIT == 42;
  701. use constant CHECK => 42; print "ok 3\n" if CHECK == 42;'
  702. result[173]='Prototype mismatch: sub main::BEGIN () vs none at ./ccode173.pl line 2.
  703. Constant subroutine BEGIN redefined at ./ccode173.pl line 2.
  704. ok 1
  705. ok 2
  706. ok 3'
  707. tests[174]='
  708. my $str = "\x{10000}\x{800}";
  709. no warnings "utf8";
  710. { use bytes; $str =~ s/\C\C\z//; }
  711. my $ref = "\x{10000}\0";
  712. print "ok 1\n" if ~~$str eq $ref;
  713. $str = "\x{10000}\x{800}";
  714. { use bytes; $str =~ s/\C\C\z/\0\0\0/; }
  715. my $ref = "\x{10000}\0\0\0\0";
  716. print "ok 2\n" if ~~$str eq $ref;'
  717. result[174]='ok 1
  718. ok 2'
  719. tests[175]='{
  720. # note that moving the use in an eval block solve the problem
  721. use warnings NONFATAL => all;
  722. $SIG{__WARN__} = sub { "ok - expected warning\n" };
  723. my $x = pack( "I,A", 4, "X" );
  724. print "ok\n";
  725. }'
  726. result[175]='ok - expected warning
  727. ok'
  728. tests[176]='use Math::BigInt; print Math::BigInt::->new(5000000000);'
  729. result[176]='5000000000'
  730. tests[177]='use version; print "ok\n" if version::is_strict("4.2");'
  731. result[177]='ok'
  732. tests[178]='BEGIN { $hash = { pi => 3.14, e => 2.72, i => -1 } ;} print scalar keys $hash;'
  733. result[178]='3'
  734. tests[179]='#TODO smartmatch subrefs
  735. {
  736. package Foo;
  737. sub new { bless {} }
  738. }
  739. package main;
  740. our $foo = Foo->new;
  741. our $bar = $foor; # required to generate the wrong behavior
  742. my $match = eval q($foo ~~ undef) ? 1 : 0;
  743. print "match ? $match\n";'
  744. result[179]='match ? 0'
  745. tests[180]='use feature "switch"; use integer; given(3.14159265) { when(3) { print "ok\n"; } }'
  746. result[180]='ok'
  747. tests[181]='sub End::DESTROY { $_[0]->() };
  748. my $inx = "OOOO";
  749. $SIG{__WARN__} = sub { print$_[0] . "\n" };
  750. {
  751. $@ = "XXXX";
  752. my $e = bless( sub { die $inx }, "End")
  753. }'
  754. result[181]=''
  755. tests[182]='#TODO stash-magic delete renames to ANON
  756. my @c; sub foo { @c = caller(0); print $c[3] } my $fooref = delete $::{foo}; $fooref -> ();'
  757. result[182]='main::__ANON__'
  758. tests[183]='main->import()'
  759. result[183]=''
  760. tests[184]='use warnings;
  761. sub xyz { no warnings "redefine"; *xyz = sub { $a <=> $b }; &xyz }
  762. eval { @b = sort xyz 4,1,3,2 };
  763. print defined $b[0] && $b[0] == 1 && $b[1] == 2 && $b[2] == 3 && $b[3] == 4 ? "ok\n" : "fail\n";
  764. exit;
  765. {
  766. package Foo;
  767. use overload (qw("" foo));
  768. }
  769. {
  770. package Bar;
  771. no warnings "once";
  772. sub foo { $ENV{fake} }
  773. }
  774. '
  775. result[184]='ok'
  776. # usage: t/testc.sh -O3 -Dp,-UCarp 185
  777. tests[185]='my $a=pack("U",0xFF);use bytes;print "not " unless $a eq "\xc3\xbf" && bytes::length($a) == 2; print "ok\n";'
  778. result[185]='ok'
  779. tests[186]='eval q/require B/; my $sub = do { package one; \&{"one"}; }; delete $one::{one}; my $x = "boom"; print "ok\n";'
  780. result[186]='ok'
  781. # duplicate of 182
  782. tests[187]='my $glob = \*Phoo::glob; undef %Phoo::; print ( ( "$$glob" eq "*__ANON__::glob" ) ? "ok\n" : "fail with $$glob\n" );'
  783. result[187]='ok'
  784. tests[188]='package aiieee;sub zlopp {(shift =~ m?zlopp?) ? 1 : 0;} sub reset_zlopp {reset;}
  785. package main; print aiieee::zlopp(""), aiieee::zlopp("zlopp"), aiieee::zlopp(""), aiieee::zlopp("zlopp");
  786. aiieee::reset_zlopp(); print aiieee::zlopp("zlopp")'
  787. result[188]='01001'
  788. #tests[189]=''
  789. #result[189]=''
  790. #tests[190]=''
  791. #result[190]=''
  792. tests[191]='# WontFix
  793. BEGIN{sub plan{42}} {package Foo::Bar;} print((exists $Foo::{"Bar::"} && $Foo::{"Bar::"} eq "*Foo::Bar::") ? "ok\n":"bad\n"); plan(fake=>0);'
  794. result[191]='ok'
  795. tests[192]='use warnings;
  796. {
  797. no warnings qw "once void";
  798. my %h; # We pass a key of this hash to the subroutine to get a PVLV.
  799. sub { for(shift) {
  800. # Set up our glob-as-PVLV
  801. $_ = *hon;
  802. # Assigning undef to the glob should not overwrite it...
  803. {
  804. my $w;
  805. local $SIG{__WARN__} = sub { $w = shift };
  806. *$_ = undef;
  807. print ( $w =~ m/Undefined value assigned to typeglob/ ? "ok" : "not ok");
  808. }
  809. }}->($h{k});
  810. }'
  811. result[192]='ok'
  812. 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;'
  813. result[193]='ok'
  814. tests[194]='$0 = q{ccdave}; #print "pid: $$\n";
  815. $s=`ps auxw | grep "$$" | grep "ccdave"|grep -v grep`;
  816. print q(ok) if $s =~ /ccdave/'
  817. result[194]='ok'
  818. # duplicate of 152
  819. tests[195]='use PerlIO; eval { require PerlIO::scalar }; find PerlIO::Layer "scalar"'
  820. result[195]=''
  821. tests[196]='package Foo;
  822. sub new { bless {}, shift }
  823. DESTROY { $_[0] = "foo" }
  824. package main;
  825. eval q{\\($x, $y, $z) = (1, 2, 3);};
  826. my $m;
  827. $SIG{__DIE__} = sub { $m = shift };
  828. { my $f = Foo->new }
  829. print "m: $m\n";'
  830. result[196]='m: Modification of a read-only value attempted at ccode196.pl line 3.'
  831. tests[197]='package FINALE;
  832. {
  833. $ref3 = bless ["ok - package destruction"];
  834. my $ref2 = bless ["ok - lexical destruction\n"];
  835. local $ref1 = bless ["ok - dynamic destruction\n"];
  836. 1;
  837. }
  838. DESTROY {
  839. print $_[0][0];
  840. }'
  841. result[197]='ok - dynamic destruction
  842. ok - lexical destruction
  843. ok - package destruction'
  844. # duplicate of 150
  845. tests[198]='{
  846. open(my $NIL, qq{|/bin/echo 23}) or die "fork failed: $!";
  847. $! = 1;
  848. close $NIL;
  849. if($! == 5) { print}
  850. }'
  851. result[198]='23'
  852. # duplicate of 90
  853. tests[199]='"abc" =~ /(.)./; print @+; print "end\n"'
  854. result[199]='21end'
  855. tests[200]='%u=("\x{123}"=>"fo"); print "ok" if $u{"\x{123}"} eq "fo"'
  856. result[200]='ok'
  857. tests[2001]='BEGIN{%u=("\x{123}"=>"fo");} print "ok" if $u{"\x{123}"} eq "fo";'
  858. result[2001]='ok'
  859. tests[201]='use Storable;*Storable::CAN_FLOCK=sub{1};print qq{ok\n}'
  860. result[201]='ok'
  861. tests[2011]='sub can {require Config; import Config;return $Config{d_flock}}
  862. use IO::File;
  863. can();
  864. print "ok\n";'
  865. result[2011]='ok'
  866. tests[203]='#TODO perlio layers
  867. use open(IN => ":crlf", OUT => ":encoding(cp1252)");
  868. open F, "<", "/dev/null";
  869. my %l = map {$_=>1} PerlIO::get_layers(F, input => 1);
  870. print $l{crlf} ? q(ok) : keys(%l);'
  871. result[203]='ok'
  872. # issue 29
  873. tests[2900]='use open qw(:std :utf8);
  874. BEGIN{ `echo ö > xx.bak`; }
  875. open X, "xx.bak";
  876. $_ = <X>;
  877. print unpack("U*", $_), " ";
  878. print $_ if /\w/;'
  879. result[2900]='24610 ö'
  880. tests[207]='use warnings;
  881. sub asub { }
  882. asub(tests => 48);
  883. my $str = q{0};
  884. $str =~ /^[ET1]/i;
  885. {
  886. no warnings qw<io deprecated>;
  887. print "ok 1\n" if opendir(H, "t");
  888. print "ok 2" if open(H, "<", "TESTS");
  889. }'
  890. result[207]='ok 1
  891. ok 2'
  892. tests[208]='#TODO 208 our refcount
  893. sub MyKooh::DESTROY { print "${^GLOBAL_PHASE} MyKooh " } my $my =bless {}, MyKooh;
  894. sub OurKooh::DESTROY { print "${^GLOBAL_PHASE} OurKooh" }our $our=bless {}, OurKooh;'
  895. if [[ `$PERL -e'print (($] < 5.014)?0:1)'` -gt 0 ]]; then
  896. result[208]='RUN MyKooh DESTRUCT OurKooh'
  897. else
  898. result[208]=' MyKooh OurKooh'
  899. fi
  900. tests[210]='$a = 123;
  901. package xyz;
  902. sub xsub {bless [];}
  903. $x1 = 1; $x2 = 2;
  904. $s = join(":", sort(keys %xyz::));
  905. package abc;
  906. my $foo;
  907. print $xyz::s'
  908. result[210]='s:x1:x2:xsub'
  909. tests[212]='$blurfl = 123;
  910. {
  911. package abc;
  912. $blurfl = 5;
  913. }
  914. $abc = join(":", sort(keys %abc::));
  915. package abc;
  916. print "variable: $blurfl\n";
  917. print "eval: ". eval q/"$blurfl\n"/;
  918. package main;
  919. sub ok { 1 }'
  920. result[212]='variable: 5
  921. eval: 5'
  922. tests[214]='
  923. my $expected = "foo";
  924. sub check(_) { print( (shift eq $expected) ? "ok\n" : "not ok\n" ) }
  925. $_ = $expected;
  926. check;
  927. undef $expected;
  928. &check; # $_ not passed'
  929. result[214]='ok
  930. ok'
  931. tests[215]='eval { $@ = "t1\n"; do { die "t3\n" }; 1; }; print ":$@:\n";'
  932. result[215]=':t3
  933. :'
  934. tests[216]='eval { $::{q{@}}=42; }; print qq{ok\n}'
  935. result[216]='ok'
  936. # also at 904
  937. tests[220]='#TODO @-
  938. my $content = "ok\n";
  939. while ( $content =~ m{\w}g ) {
  940. $_ .= "$-[0]$+[0]";
  941. }
  942. print "ok" if $_ eq "0112";'
  943. result[220]='ok'
  944. tests[223]='use strict; eval q({ $x = sub }); print $@'
  945. result[223]='Illegal declaration of anonymous subroutine at (eval 1) line 1.'
  946. 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" );'
  947. result[224]='ok'
  948. tests[225]='$_ = $dx = "\x{10f2}"; s/($dx)/$dx$1/; $ok = 1 if $_ eq "$dx$dx"; $_ = $dx = "\x{10f2}"; print qq{end\n};'
  949. result[225]='end'
  950. tests[226]='# WontFix
  951. @INC = (); dbmopen(%H, $file, 0666)'
  952. result[226]='No dbm on this machine at -e line 1.'
  953. tests[227]='open IN, "/dev/null" or die $!; *ARGV = *IN; foreach my $x (<>) { print $x; } close IN; print qq{ok\n}'
  954. result[227]='ok'
  955. tests[229]='sub yyy () { "yyy" } print "ok\n" if( eval q{yyy} eq "yyy");'
  956. result[229]='ok'
  957. #issue 30
  958. tests[230]='sub f1 { my($self) = @_; $self->f2;} sub f2 {} sub new {} print "@ARGV\n";'
  959. result[230]=''
  960. tests[232]='use Carp (); exit unless Carp::longmess(); print qq{ok\n}'
  961. result[232]='ok'
  962. tests[234]='$c = 0; for ("-3" .. "0") { $c++ } ; print "$c"'
  963. result[234]='4'
  964. # t/testc.sh -O3 -Dp,-UCarp,-v 235
  965. tests[235]='BEGIN{$INC{"Carp.pm"}="/dev/null"} $d = pack("U*", 0xe3, 0x81, 0xAF); { use bytes; $ol = bytes::length($d) } print $ol'
  966. result[235]='6'
  967. # -O3
  968. tests[236]='sub t { if ($_[0] == $_[1]) { print "ok\n"; } else { print "not ok - $_[0] == $_[1]\n"; } } t(-1.2, " -1.2");'
  969. result[236]='ok'
  970. tests[237]='print "\000\000\000\000_"'
  971. result[237]='_'
  972. tests[238]='sub f ($);
  973. sub f ($) {
  974. my $test = $_[0];
  975. write;
  976. format STDOUT =
  977. ok @<<<<<<<
  978. $test
  979. .
  980. }
  981. f("");
  982. '
  983. result[238]='ok'
  984. tests[239]='#TODO
  985. my $x="1";
  986. format STDOUT =
  987. ok @<<<<<<<
  988. $x
  989. .
  990. write;print "\n";'
  991. result[239]='ok 1'
  992. tests[240]='my $a = "\x{100}\x{101}Aa";
  993. print "ok\n" if "\U$a" eq "\x{100}\x{100}AA";
  994. my $b = "\U\x{149}cD"; # no pb without that line'
  995. result[240]='ok'
  996. tests[241]='package Pickup; use UNIVERSAL qw( can ); if (can( "Pickup", "can" ) != \&UNIVERSAL::can) { print "not " } print "ok\n";'
  997. result[241]='ok'
  998. tests[242]='$xyz = ucfirst("\x{3C2}");
  999. $a = "\x{3c3}foo.bar";
  1000. ($c = $a) =~ s/(\p{IsWord}+)/ucfirst($1)/ge;
  1001. print "ok\n" if $c eq "\x{3a3}foo.Bar";'
  1002. result[242]='ok'
  1003. tests[243]='use warnings "deprecated"; print hex(${^WARNINGS}) . " "; print hex(${^H})'
  1004. result[243]='0 598'
  1005. tests[244]='print "($_)\n" for q{-2}..undef;'
  1006. result[244]='(-2)
  1007. (-1)
  1008. (0)'
  1009. tests[245]='sub foo {
  1010. my ( $a, $b ) = @_;
  1011. print "a: ".ord($a)." ; b: ".ord($b)." [ from foo ]\n";
  1012. }
  1013. print "a: ". ord(lc("\x{1E9E}"))." ; ";
  1014. print "b: ". ord("\x{df}")."\n";
  1015. foo(lc("\x{1E9E}"), "\x{df}");'
  1016. result[245]='a: 223 ; b: 223
  1017. a: 223 ; b: 223 [ from foo ]'
  1018. # see t/issue235.t test 2
  1019. tests[246]='sub foo($\@); eval q/foo "s"/; print $@'
  1020. result[246]='Not enough arguments for main::foo at (eval 1) line 2, at EOF'
  1021. tests[247]='# WontFix
  1022. no warnings; $[ = 1; $big = "N\xabN\xab"; print qq{ok\n} if rindex($big, "N", 3) == 3'
  1023. result[247]='ok'
  1024. tests[248]='#TODO
  1025. {my $s="toto";my $_="titi";{$s =~ /to(?{ print "-$_-$s-\n";})to/;}}'
  1026. result[248]='-titi-toto-'
  1027. tests[249]='#TODO
  1028. use version; print version::is_strict(q{01}) ? 1 : 0'
  1029. result[249]='0'
  1030. tests[250]='#TODO
  1031. use warnings qw/syntax/; use version; $withversion::VERSION = undef; eval q/package withversion 1.1_;/; print $@;'
  1032. result[250]='Misplaced _ in number at (eval 1) line 1.
  1033. Invalid version format (no underscores) at (eval 1) line 1, near "package withversion "
  1034. syntax error at (eval 1) line 1, near "package withversion 1.1_"'
  1035. tests[251]='sub f;print "ok" if exists &f'
  1036. result[251]='ok'
  1037. tests[2511]='#TODO 5.18
  1038. sub f :lvalue;print "ok" if exists &f'
  1039. result[2511]='ok'
  1040. tests[2512]='sub f ();print "ok" if exists &f'
  1041. result[2512]='ok'
  1042. tests[2513]='sub f ($);print "ok" if exists &f'
  1043. result[2513]='ok'
  1044. tests[2514]='sub f;print "ok" if exists &f'
  1045. result[2514]='ok'
  1046. # duplicate of 234
  1047. tests[252]='my $i = 0; for ("-3".."0") { ++$i } print $i'
  1048. result[252]='4'
  1049. tests[253]='INIT{require "t/test.pl"}plan(tests=>2);is("\x{2665}", v9829);is(v9829,"\x{2665}");'
  1050. result[253]='1..2
  1051. ok 1
  1052. ok 2'
  1053. tests[254]='#TODO destroy upgraded lexvar
  1054. my $flag = 0;
  1055. sub X::DESTROY { $flag = 1 }
  1056. {
  1057. my $x; # x only exists in that scope
  1058. BEGIN { $x = 42 } # pre-initialized as IV
  1059. $x = bless {}, "X"; # run-time upgrade and bless to call DESTROY
  1060. # undef($x); # value should be free when exiting scope
  1061. }
  1062. print "ok\n" if $flag;'
  1063. result[254]='ok'
  1064. # duplicate of 185, bytes_heavy
  1065. tests[255]='$a = chr(300);
  1066. my $l = length($a);
  1067. my $lb;
  1068. { use bytes; $lb = length($a); }
  1069. print( ( $l == 1 && $lb == 2 ) ? "ok\n" : "l -> $l ; lb -> $lb\n" );'
  1070. result[255]='ok'
  1071. tests[256]='BEGIN{ $| = 1; } print "ok\n" if $| == 1'
  1072. result[256]='ok'
  1073. tests[259]='use JSON::XS; print encode_json([\0])'
  1074. result[259]='[false]'
  1075. tests[260]='sub FETCH_SCALAR_ATTRIBUTES {''} sub MODIFY_SCALAR_ATTRIBUTES {''}; my $a :x=1; print $a'
  1076. result[260]='1'
  1077. tests[261]='q(12-feb-2015) =~ m#(\d\d?)([\-\./])(feb|jan)(?:\2(\d\d+))?#; print $4'
  1078. result[261]='2015'
  1079. tests[262]='use POSIX'
  1080. result[262]=''
  1081. tests[263]='use JSON::XS; print encode_json []'
  1082. result[263]='[]'
  1083. tests[264]='no warnings; warn "$a.\n"'
  1084. result[264]='.'
  1085. tests[272]='$d{""} = qq{ok\n}; print $d{""};'
  1086. result[272]='ok'
  1087. tests[2721]='BEGIN{$d{""} = qq{ok\n};} print $d{""};'
  1088. result[2721]='ok'
  1089. 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"'
  1090. result[273]='11'
  1091. tests[274]='package Foo;
  1092. sub match { shift =~ m?xyz? ? 1 : 0; }
  1093. sub match_reset { reset; }
  1094. package Bar;
  1095. sub match { shift =~ m?xyz? ? 1 : 0; }
  1096. sub match_reset { reset; }
  1097. package main;
  1098. print "1..5\n";
  1099. print "ok 1\n" if Bar::match("xyz");
  1100. print "ok 2\n" unless Bar::match("xyz");
  1101. print "ok 3\n" if Foo::match("xyz");
  1102. print "ok 4\n" unless Foo::match("xyz");
  1103. Foo::match_reset();
  1104. print "ok 5\n" if Foo::match("xyz");'
  1105. result[274]='1..5
  1106. ok 1
  1107. ok 2
  1108. ok 3
  1109. ok 4
  1110. ok 5'
  1111. tests[277]='format OUT =
  1112. bar ~~
  1113. .
  1114. open(OUT, ">/dev/null"); write(OUT); close OUT;'
  1115. result[277]=''
  1116. tests[280]='package M; $| = 1; sub DESTROY {eval {print "Farewell ",ref($_[0])};} package main; bless \$A::B, q{M}; *A:: = \*B::;'
  1117. result[280]='Farewell M'
  1118. tests[281]='#TODO @-
  1119. "I like pie" =~ /(I) (like) (pie)/; "@-" eq "0 0 2 7" and print "ok\n"; print "\@- = @-\n\@+ = @+\n"'
  1120. result[281]='ok
  1121. @- = 0 0 2 7
  1122. @+ = 10 1 6 10'
  1123. 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";'
  1124. result[282]='ok'
  1125. tests[283]='#238 Undefined format "STDOUT"
  1126. format =
  1127. ok
  1128. .
  1129. write'
  1130. result[283]='ok'
  1131. tests[284]='#-O3 only
  1132. my $x="123456789";
  1133. format OUT =
  1134. ^<<~~
  1135. $x
  1136. .
  1137. open OUT, ">ccode.tmp";
  1138. write(OUT);
  1139. close(OUT);
  1140. print `cat "ccode.tmp"`'
  1141. result[284]='123
  1142. 456
  1143. 789'
  1144. tests[289]='no warnings; sub z_zwap (&); print qq{ok\n} if eval q{sub z_zwap {return @_}; 1;}'
  1145. result[289]='ok'
  1146. tests[295]='#TODO @-
  1147. "zzaaabbb" =~ m/(a+)(b+)/ and print "@- : @+\n"'
  1148. result[295]='2 2 5 : 8 5 8'
  1149. tests[299]='#TODO
  1150. package Pickup; use UNIVERSAL qw( VERSION ); print qq{ok\n} if VERSION "UNIVERSAL";'
  1151. result[299]='ok'
  1152. tests[300]='use mro;print @{mro::get_linear_isa("mro")};'
  1153. result[300]='mro'
  1154. init
  1155. #
  1156. # getopts for -q -k -E -Du,-q -v -O2, -a -c -fro-inc
  1157. while getopts "haAckoED:B:O:f:q" opt
  1158. do
  1159. if [ "$opt" = "q" ]; then
  1160. QUIET=1
  1161. CCMD="$CCMD -q"
  1162. fi
  1163. if [ "$opt" = "o" ]; then Mblib=" "; init; fi
  1164. if [ "$opt" = "c" ]; then CONT=1; fi
  1165. if [ "$opt" = "k" ]; then KEEP=1; fi
  1166. if [ "$opt" = "E" ]; then CPP=1; fi
  1167. if [ "$opt" = "h" ]; then help; exit; fi
  1168. # -D options: u,-q for quiet, no -D for verbose, -D- for no gcc warnings
  1169. if [ "$opt" = "D" ]; then
  1170. OCMD="$PERL $Mblib -MO=C,-D${OPTARG},"
  1171. if [ $BASE = "testcc.sh" ]; then
  1172. OCMD="$PERL $Mblib -MO=CC,-D${OPTARG},"
  1173. fi
  1174. if [ -z "${OPTARG/-/}" ]; then
  1175. CCMD="$CCMD -d"
  1176. fi
  1177. fi
  1178. # -B dynamic or -B static
  1179. if [ "$opt" = "B" ]; then
  1180. CCMD="$CCMD -B${OPTARG}"
  1181. fi
  1182. if [ "$opt" = "O" ]; then OPTIM="$OPTARG"; fi
  1183. if [ "$opt" = "f" ]; then
  1184. OCMD="$(echo $OCMD|sed -e "s/C,/C,-f$OPTARG,/")"
  1185. fi
  1186. if [ "$opt" = "a" ]; then # replace -Du, by -Do
  1187. OCMD="$(echo $OCMD|sed -r -e 's/(-D.*)u,/\1o,/')"
  1188. fi
  1189. if [ "$opt" = "A" ]; then
  1190. CCMD="$CCMD -DALLOW_PERL_OPTIONS"
  1191. fi
  1192. done
  1193. if [ "$(perl -V:gccversion)" != "gccversion='';" ]; then
  1194. if [ "$(uname)" = "Darwin" ]; then
  1195. CCMD="$CCMD -g -fno-openmp -fno-var-tracking"
  1196. else
  1197. CCMD="$CCMD -g3"
  1198. fi
  1199. fi
  1200. if [ -z $OPTIM ]; then OPTIM=-1; fi # all
  1201. if [ -z "$QUIET" ]; then
  1202. make
  1203. else
  1204. # O from 5.6 does not support -qq
  1205. qq="`$PERL -e'print (($] < 5.007) ? q() : q(-qq,))'`"
  1206. # replace -D*,-v by -q
  1207. OCMD="$(echo $OCMD |sed -e 's/-D.*,//' -e 's/,-v,/,/' -e s/-MO=/-MO=$qq/)"
  1208. OCMDO1="$(echo $OCMDO1|sed -e 's/-D.*,//' -e 's/,-v,/,/' -e s/-MO=/-MO=$qq/)"
  1209. OCMDO2="$(echo $OCMDO2|sed -e 's/-D.*,//' -e 's/,-v,/,/' -e s/-MO=/-MO=$qq/)"
  1210. OCMDO3="$(echo $OCMDO3|sed -e 's/-D.*,//' -e 's/,-v,/,/' -e s/-MO=/-MO=$qq/)"
  1211. OCMDO4="$(echo $OCMDO4|sed -e 's/-D.*,//' -e 's/,-v,/,/' -e s/-MO=/-MO=$qq/)"
  1212. # gnu make?
  1213. make -s >/dev/null || make 2&>1 >/dev/null
  1214. fi
  1215. # need to shift the options
  1216. while [ -n "$1" -a "${1:0:1}" = "-" ]; do shift; done
  1217. if [ -n "$1" ]; then
  1218. while [ -n "$1" ]; do
  1219. ctest $1
  1220. shift
  1221. done
  1222. else
  1223. for b in $(seq $ntests); do
  1224. ctest $b
  1225. done
  1226. if [ $BASE = "testcc.sh" ]; then
  1227. for b in $(seq 101 $(($ncctests+100))); do
  1228. ctest $b
  1229. done
  1230. fi
  1231. fi
  1232. # 562 c: 15,25,27
  1233. # 58 c: 27,29_i
  1234. # 58 cc: 15,18,21,25,26_o,27,29
  1235. # 510 c: 15
  1236. # 510 cc: 11,15,29
  1237. # 511 c: 11,15,16,29
  1238. # http://www.nntp.perl.org/group/perl.perl5.porters/2005/07/msg103315.html
  1239. # FAIL for B::CC should be covered by test 18