testc.sh 38 KB

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