testc.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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. function init {
  25. BASE=`basename $0`
  26. # if $] < 5.9 you may want to remove -Mblib for testing the core lib. -o
  27. #Mblib="`$PERL -e'print (($] < 5.009005) ? q() : q(-Mblib))'`"
  28. Mblib=${Mblib:--Iblib/arch -Iblib/lib} # B::C is now fully 5.6+5.8 backwards compatible
  29. v513="`$PERL -e'print (($] < 5.013005) ? q() : q(-fno-fold,-fno-warnings,))'`"
  30. # OCMD=${OCMD}${v513}
  31. if [ -z "$Mblib" ]; then
  32. VERS="${VERS}_global";
  33. OCMD="$PERL $Mblib -MO=C,${v513}-Dcsp,"
  34. if [ $BASE = "testcc.sh" ]; then # DrOsplt
  35. OCMD="$PERL $Mblib -MO=CC,${v513}-DOsplt,"
  36. fi
  37. else
  38. OCMD="$PERL $Mblib -MO=C,${v513}-DspF,-v,"
  39. if [ $BASE = "testcc.sh" ]; then # DoOscprSql
  40. OCMD="$PERL $Mblib -MO=CC,${v513}-DOscpSql,-v,"
  41. fi
  42. fi
  43. CONT=
  44. # 5.6: rather use -B static
  45. #CCMD="$PERL script/cc_harness -g3"
  46. # rest. -DALLOW_PERL_OPTIONS for -Dtlv
  47. #CCMD="$PERL $Mblib script/cc_harness -g3 -DALLOW_PERL_OPTIONS"
  48. CCMD="$PERL $Mblib script/cc_harness"
  49. LCMD=
  50. # On some perls I also had to add $archlib/DynaLoader/DynaLoader.a to libs in Config.pm
  51. }
  52. function vcmd {
  53. test -n "$QUIET" || echo $*
  54. $*
  55. }
  56. function pass {
  57. echo -e -n "\033[1;32mPASS \033[0;0m"
  58. echo $*
  59. }
  60. function fail {
  61. echo -e -n "\033[1;31mFAIL \033[0;0m"
  62. echo $*
  63. }
  64. function runopt {
  65. o=$1
  66. optim=$2
  67. OCMDO1="$(echo $OCMD|sed -e s/C,/C,-O$optim,/)"
  68. suff="_o${optim}"
  69. if [ "$optim" == "0" ]; then suff=""; fi
  70. rm ${o}${suff} ${o}${suff}.c 2> /dev/null
  71. if [ $optim -lt 5 ]; then CMD=$OCMDO1
  72. else CMD=$OCMD
  73. fi
  74. if [ "$o" = "ccode46" -o "$o" = "cccode46" ]; then
  75. CMD="$CMD-fstash,"
  76. fi
  77. if [ -z $qq ]; then
  78. vcmd ${CMD}-o${o}${suff}.c $o.pl 2>&1 | grep -v "$o.pl syntax OK"
  79. else
  80. vcmd ${CMD}-o${o}${suff}.c $o.pl
  81. fi
  82. test -z $CPP || vcmd $CCMD ${o}${suff}.c -c -E -o ${o}${suff}_E.c
  83. vcmd $CCMD ${o}${suff}.c $LCMD -o ${o}${suff}
  84. test -x ${o}${suff} || (test -z $CONT && exit)
  85. if [ -z "$QUIET" ]; then echo "./${o}${suff}"
  86. else echo -n "./${o}${suff} "
  87. fi
  88. mem=$(ulimit -m 2>/dev/null)
  89. err=$?
  90. test -z $err && ulimit -S -m 50000
  91. res=$(./${o}${suff}) || fail "./${o}${suff}" "errcode $?"
  92. test -z $err && ulimit -S -m $mem
  93. if [ "X$res" = "X${result[$n]}" ]; then
  94. test "X$res" = "X${result[$n]}" && pass "./${o}${suff}" "=> '$res'"
  95. if [ -z $KEEP ]; then rm ${o}${suff}_E.c ${o}${suff}.c ${o}${suff} 2>/dev/null; fi
  96. true
  97. else
  98. fail "./${o}${suff}" "=> '$str' => '$res'. Expected: '${result[$n]}'"
  99. false
  100. fi
  101. }
  102. function ctest {
  103. n=$1
  104. str=$2
  105. if [ $BASE = "testcc.sh" ]; then
  106. o="cccode$n"
  107. else
  108. o="ccode$n"
  109. fi
  110. if [ -z "$str" ]; then
  111. if [ "$n" = "08" ]; then n=8; fi
  112. if [ "$n" = "09" ]; then n=9; fi
  113. echo "${tests[${n}]}" > ${o}.pl
  114. str="${tests[${n}]}"
  115. else
  116. echo "$str" > ${o}.pl
  117. fi
  118. if [ -z "$str" ]; then
  119. true
  120. else
  121. if [ $OPTIM -ge 0 ]; then
  122. runopt "$o" "$OPTIM"
  123. else # -1
  124. rm $o.c $o ${o}_o.c ${o}_o 2> /dev/null
  125. vcmd ${OCMD}-o$o.c $o.pl
  126. test -s $o.c || (echo "empty $o.c"; test -z $CONT && exit 2)
  127. test -z $CPP || vcmd $CCMD $o.c -c -E -o ${o}_E.c
  128. vcmd $CCMD $o.c $LCMD -o $o
  129. test -x $o || (test -z $CONT && exit)
  130. if [ -z "$QUIET" ]; then echo "./$o"
  131. else echo -n "./$o "
  132. fi
  133. res=$(./$o) || (fail "./${o}${suff}" "'$?' = $?"; test -z $CONT && exit 1)
  134. if [ "X$res" = "X${result[$n]}" ]; then
  135. pass "./$o" "'$str' => '$res'"
  136. if [ -z $KEEP ]; then rm ${o}_E.c ${o}.c ${o} 2>/dev/null; fi
  137. if [ $BASE = "testcc.sh" ]; then
  138. runopt $o 1 && \
  139. runopt $o 2
  140. else
  141. runopt $o 1 && \
  142. runopt $o 2 && \
  143. runopt $o 3 && \
  144. runopt $o 4
  145. fi
  146. true
  147. else
  148. fail "./$o" "'$str' => '$res' Expected: '${result[$n]}'"
  149. test -z $CONT && exit 3
  150. fi
  151. fi
  152. fi
  153. }
  154. ntests=50
  155. declare -a tests[$ntests]
  156. declare -a result[$ntests]
  157. ncctests=23
  158. declare -a cctests[$((100+$ncctests))]
  159. declare -a ccresult[$((100+$ncctests))]
  160. tests[1]='print "hi"'
  161. result[1]='hi';
  162. tests[2]='for (1,2,3) { print if /\d/ }'
  163. result[2]='123';
  164. tests[3]='$_ = "xyxyx"; %j=(1,2); s/x/$j{print("z")}/ge; print $_'
  165. result[3]='zzz2y2y2';
  166. tests[4]='$_ = "xyxyx"; %j=(1,2); s/x/$j{print("z")}/g; print $_'
  167. result[4]='z2y2y2';
  168. tests[5]='print split /a/,"bananarama"'
  169. result[5]='bnnrm';
  170. tests[6]="{package P; sub x {print 'ya'} x}"
  171. result[6]='ya';
  172. tests[7]='@z = split /:/,"b:r:n:f:g"; print @z'
  173. result[7]='brnfg';
  174. tests[8]='sub AUTOLOAD { print 1 } &{"a"}()'
  175. result[8]='1';
  176. tests[9]='my $l_i = 3; $x = sub { print $l_i }; &$x'
  177. result[9]='3';
  178. tests[10]='my $i_i = 1;
  179. my $foo = sub {
  180. $i_i = shift if @_
  181. }; print $i_i;
  182. print &$foo(3),$i_i;'
  183. result[10]='133';
  184. # index: do fbm_compile or not
  185. tests[11]='$x="Cannot use"; print index $x, "Can"'
  186. result[11]='0';
  187. tests[12]='my $i_i=6; eval "print \$i_i\n"; print ""'
  188. result[12]='6';
  189. tests[13]='BEGIN { %h=(1=>2,3=>4) } print $h{3}'
  190. result[13]='4';
  191. tests[14]='open our $T,"a"; print "ok";'
  192. result[14]='ok';
  193. # __DATA__ handles still broken non-threaded 5.10
  194. tests[15]='print <DATA>
  195. __DATA__
  196. a
  197. b'
  198. result[15]='a
  199. b';
  200. tests[16]='BEGIN{tie @a, __PACKAGE__;sub TIEARRAY {bless{}} sub FETCH{1}}; print $a[1]'
  201. result[16]='1';
  202. tests[17]='my $i_ir=3; print 1 .. $i_ir'
  203. result[17]='123';
  204. # custom key sort
  205. tests[18]='my $h = { a=>3, b=>1 }; print sort {$h->{$a} <=> $h->{$b}} keys %$h'
  206. result[18]='ba';
  207. # fool the sort optimizer by my $p, pp_sort works ok on CC
  208. tests[19]='print sort { my $p; $b <=> $a } 1,4,3'
  209. result[19]='431';
  210. # not repro: something like this is broken in original 5.6 (Net::DNS::ZoneFile::Fast)
  211. # see new test 33
  212. tests[20]='$a="abcd123";my $r=qr/\d/;print $a =~ $r;'
  213. result[20]='1';
  214. # broken on early alpha and 5.10: run-time labels.
  215. tests[21]='sub skip_on_odd{next NUMBER if $_[0]% 2}NUMBER:for($i=0;$i<5;$i++){skip_on_odd($i);print $i;}'
  216. result[21]='024';
  217. # broken in original perl 5.6
  218. tests[22]='my $fh; BEGIN { open($fh,"<","/dev/null"); } print "ok";';
  219. result[22]='ok';
  220. # broken in perl 5.8
  221. tests[23]='package MyMod; our $VERSION = 1.3; print "ok";'
  222. result[23]='ok'
  223. # works in original perl 5.6, broken with latest B::C in 5.6, 5.8
  224. tests[24]='sub level1{return(level2()?"fail":"ok")} sub level2{0} print level1();'
  225. result[24]='ok'
  226. # enforce custom ncmp sort and count it. fails as CC in all. How to enforce icmp?
  227. # <=5.6 qsort needs two more passes here than >=5.8 merge_sort
  228. # 5.12 got it backwards and added 4 more passes.
  229. tests[25]='print sort { $i++; $b <=> $a } 1..4'
  230. result[25]="4321";
  231. # lvalue sub
  232. tests[26]='sub a:lvalue{my $a=26; ${\(bless \$a)}}sub b:lvalue{${\shift}}; print ${a(b)}';
  233. result[26]="26";
  234. # xsub constants (constant folded). newlib: 0x200, glibc: 0x100
  235. tests[27]='use Fcntl ();my $a=Fcntl::O_CREAT(); print "ok" if ( $a >= 64 && &Fcntl::O_CREAT >= 64 );'
  236. result[27]='ok'
  237. # require $fname
  238. 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;'
  239. result[28]='ok'
  240. # special old IO handling
  241. tests[29]='use IO;print "ok"'
  242. result[29]='ok'
  243. # run-time context of .., fails in CC
  244. tests[30]='@a=(4,6,1,0,0,1);sub range{(shift @a)..(shift @a)}print range();while(@a){print scalar(range())}'
  245. result[30]='456123E0'
  246. # AUTOLOAD w/o goto xsub
  247. 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");'
  248. result[31]='date;who am i;ls -l;'
  249. # CC entertry/jmpenv_jump/leavetry
  250. tests[32]='eval{print "1"};eval{die 1};print "2";'
  251. result[32]='12'
  252. # C qr test was broken in 5.6 -- needs to load an actual file to test. See test 20.
  253. # 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.
  254. # fails with new constant only. still not repro (r-magic probably)
  255. tests[33]='BEGIN{unshift @INC,("t");} use qr_loaded_module; print "ok" if qr_loaded_module::qr_called_in_sub("name1")'
  256. result[33]='ok'
  257. # init of magic hashes. %ENV has e magic since a0714e2c perl.c
  258. # (Steven Schubiger 2006-02-03 17:24:49 +0100 3967) i.e. 5.8.9 but not 5.8.8
  259. tests[34]='my $x=$ENV{TMPDIR};print "ok"'
  260. result[34]='ok'
  261. # static method_named. fixed with 1.16
  262. 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")'
  263. result[35]='01234'
  264. # HV self-ref
  265. tests[36]='my ($rv, %hv); %hv = ( key => \$rv ); $rv = \%hv; print "ok";'
  266. result[36]='ok'
  267. # AV self-ref
  268. tests[37]='my ($rv, @av); @av = ( \$rv ); $rv = \@av; print "ok";'
  269. result[37]='ok'
  270. # constant autoload loop crash test
  271. 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"; }'
  272. result[38]='ok'
  273. # check re::is_regexp, and on 5.12 if being upgraded to SVt_REGEXP
  274. # => Undefined subroutine &re::is_regexp with B-C-1.19, even with -ure
  275. tests[39]='{$a=qr/x/;print($]<5.010?1:re::is_regexp($a))}'
  276. result[39]='1'
  277. # String with a null byte -- used to generate broken .c on 5.6.2 with static pvs
  278. tests[40]='my $var="this string has a null \\000 byte in it";print "ok";'
  279. result[40]='ok'
  280. # Shared scalar, n magic. => Don't know how to handle magic of type \156.
  281. usethreads=""
  282. #usethreads="`$PERL -MConfig -e'print ($Config{useithreads} ? q(use threads;) : q())'`"
  283. #usethreads='BEGIN{use Config; unless ($Config{useithreads}) {print "ok"; exit}} '
  284. #;threads->create(sub{$s="ok"})->join;
  285. # not yet testing n, only P
  286. tests[41]=$usethreads'use threads::shared;{my $s="ok";share($s);print $s}'
  287. result[41]='ok'
  288. # Shared aggregate, P magic
  289. tests[42]=$usethreads'use threads::shared;my %h : shared; print "ok"'
  290. result[42]='ok'
  291. # Aggregate element, n + p magic
  292. tests[43]=$usethreads'use threads::shared;my @a : shared; $a[0]="ok"; print $a[0]'
  293. result[43]='ok'
  294. # perl #72922 (5.11.4 fails with magic_killbackrefs)
  295. tests[44]='use Scalar::Util "weaken";my $re1=qr/foo/;my $re2=$re1;weaken($re2);print "ok" if $re3=qr/$re1/;'
  296. result[44]='ok'
  297. # test dynamic loading
  298. tests[45]='use Data::Dumper ();Data::Dumper::Dumpxs({});print "ok";'
  299. result[45]='ok'
  300. # issue 79: Exporter:: stash missing in main::
  301. #tests[46]='use Exporter; if (exists $main::{"Exporter::"}) { print "ok"; }'
  302. tests[46]='use Exporter; print "ok" if %main::Exporter::'
  303. #tests[46]='use Exporter; print "ok" if scalar(keys(%main::Exporter::)) > 2'
  304. result[46]='ok'
  305. # non-tied av->MAGICAL
  306. tests[47]='@ISA=(q(ok));print $ISA[0];'
  307. result[47]='ok'
  308. # END block del_backref with bytecode only
  309. tests[48]='my $s=q{ok};END{print $s}'
  310. result[48]='ok'
  311. # even this failed until r1000 (AvFILL 3 of END)
  312. #tests[48]='print q{ok};END{}'
  313. #result[48]='ok'
  314. # no-fold
  315. tests[49]='print q(ok) if "test" =~ /es/i;'
  316. result[49]='ok'
  317. # @ISA issue 64
  318. tests[50]='package Top;sub top{q(ok)};package Next;our @ISA=qw(Top);package main;print Next->top();'
  319. result[50]='ok'
  320. # XXX TODO sigwarn $w = B::NULL without -v
  321. tests[51]='$SIG{__WARN__}=sub{print "ok"};warn 1;'
  322. result[51]='ok'
  323. # check if general signals work
  324. tests[511]='BEGIN{$SIG{USR1}=sub{$w++;};} kill USR1 => $$; print q(ok) if $w';
  325. result[511]='ok'
  326. #-------------
  327. # issue27
  328. tests[227]='require LWP::UserAgent;print q(ok);'
  329. result[227]='ok'
  330. #issue 24
  331. tests[224]='dbmopen(%H,q(f),0644);print q(ok);'
  332. result[224]='ok'
  333. tests[68]='package A;
  334. sub test {
  335. use Data::Dumper ();
  336. /^(.*?)\d+$/;
  337. "Some::Package"->new();
  338. }
  339. print "ok"'
  340. result[68]='ok'
  341. # issue71
  342. tests[71]='
  343. package my;
  344. our @a;
  345. sub f {
  346. my($alias,$name)=@_;
  347. unshift(@a, $alias => $name);
  348. my $find = "ok";
  349. my $val = $a[1];
  350. if ( ref($alias) eq "Regexp" && $find =~ $alias ) {
  351. eval $val;
  352. }
  353. $find
  354. }
  355. package main;
  356. *f=*my::f;
  357. print "ok" if f(qr/^(.*)$/ => q("\L$1"));'
  358. result[71]="ok"
  359. # object call: method_named with args.
  360. tests[72]='package dummy;sub meth{print "ok"};package main;my dummy $o = bless {},"dummy"; $o->meth("const")'
  361. result[72]='ok'
  362. # object call: dynamic method_named with args.
  363. tests[73]='package dummy;sub meth{print "ok"};package main;my $meth="meth";my $o = bless {},"dummy"; $o->$meth("const")'
  364. result[73]='ok'
  365. tests[74]='package dummy;
  366. my $invoked_as_script = !caller();
  367. __PACKAGE__->script(@ARGV) if $invoked_as_script;
  368. sub script {my($package,@args)=@_;print "ok"}'
  369. result[74]='ok'
  370. # issue 71_2+3: cop_warnings issue76 and const destruction issue71 fixed
  371. # ok with "utf-8-strict"
  372. tests[75]='#TODO
  373. use Encode;
  374. my $x = "abc";
  375. print "ok" if "abc" eq Encode::decode("UTF-8", $x);'
  376. result[75]='ok'
  377. tests[76]='use warnings;
  378. { no warnings q(void); # issue76 lexwarn
  379. length "ok";
  380. print "ok"
  381. };'
  382. result[76]='ok'
  383. tests[81]='sub int::check {1} #create int package for types
  384. sub x(int,int) { @_ } #cvproto
  385. my $o = prototype \&x;
  386. if ($o eq "int,int") {print "o"}else{print $o};
  387. sub y($) { @_ } #cvproto
  388. my $p = prototype \&y;
  389. if ($p eq q($)) {print "k"}else{print $p};
  390. require bytes;
  391. sub my::length ($) { # possible prototype mismatch vs _
  392. if ( bytes->can(q(length)) ) {
  393. *length = *bytes::length;
  394. goto &bytes::length;
  395. }
  396. return CORE::length( $_[0] );
  397. }
  398. print my::length($p);'
  399. result[81]='ok1'
  400. tests[90]='my $s = q(test string);
  401. $s =~ s/(?<first>test) (?<second>string)/\2 \1/g;
  402. print q(o) if $s eq q(string test);
  403. q(test string) =~ /(?<first>\w+) (?<second>\w+)/;
  404. print q(k) if $+{first} eq q(test);'
  405. result[90]='ok'
  406. tests[901]='my %errs = %!; # t/op/magic.t Errno compiled in
  407. print q(ok) if defined ${"!"}{ENOENT};'
  408. result[901]='ok'
  409. tests[902]='my %errs = %{"!"}; # t/op/magic.t Errno to be loaded at run-time
  410. print q(ok) if defined ${"!"}{ENOENT};'
  411. result[902]='ok'
  412. # IO handles
  413. tests[91]='# issue59 TODO
  414. use strict;
  415. use warnings;
  416. use IO::Socket;
  417. my $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "perl.org", PeerPort => "80" );
  418. print $remote "GET / HTTP/1.0" . "\r\n\r\n";
  419. my $result = <$remote>;
  420. $result =~ m|HTTP/1.1 200 OK| ? print "ok" : print $result;
  421. close $remote;'
  422. result[91]='ok'
  423. tests[93]='#SKIP
  424. my ($pid, $out, $in);
  425. BEGIN {
  426. local(*FPID);
  427. $pid = open(FPID, "echo <<EOF |"); # DIE
  428. open($out, ">&STDOUT"); # EASY
  429. open(my $tmp, ">", "pcc.tmp"); # HARD to get filename, WARN
  430. print $tmp "test\n";
  431. close $tmp; # OK closed
  432. open($in, "<", "pcc.tmp"); # HARD to get filename, WARN
  433. }
  434. # === run-time ===
  435. print $out "o";
  436. kill 0, $pid; # BAD! warn? die?
  437. print "k" if "test" eq read $in, my $x, 4;
  438. unlink "pcc.tmp";
  439. '
  440. result[93]='ok'
  441. tests[931]='my $f;BEGIN{open($f,"<README");}read $f,my $in, 2; print "ok"'
  442. result[931]='ok'
  443. tests[932]='my $f;BEGIN{open($f,">&STDOUT");}print $f "ok"'
  444. result[932]='ok'
  445. tests[95]='#TODO IO::Socket::SSL::DESTROY
  446. use IO::Socket::SSL();
  447. my IO::Handle $handle = IO::Socket::SSL->new(SSL_verify_mode =>0);
  448. $handle->blocking(0);
  449. print "ok";'
  450. result[95]='ok'
  451. tests[97]='use v5.12; print q(ok);'
  452. result[97]='ok'
  453. # from here on we test CC specifics only
  454. # CC types and arith
  455. 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;'
  456. result[101]='12'
  457. # CC cond_expr, stub, scope
  458. tests[102]='if ($x eq "2"){}else{print "ok"}'
  459. result[102]='ok'
  460. # CC stringify, srefgen. TODO: use B; fails
  461. tests[103]='require B; my $x=1e1; my $s="$x"; print ref B::svref_2object(\$s)'
  462. result[103]='B::PV'
  463. # CC reset
  464. tests[104]='@a=(1..4);while($a=shift@a){print $a;}continue{$a=~/2/ and reset q(a);}'
  465. result[104]='12'
  466. # CC -ftype-attr
  467. #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;'
  468. tests[105]='%int::;%double::;my int $r;my $i_i=2;our double $d=3.0; $r=$i*$i; $r*=$d; print $r;'
  469. result[105]='12'
  470. # issue35
  471. tests[110]='sub new{}sub test{{my $x=1;my $y=$x+1;}my $x=2;if($x!=3){4;}}'
  472. result[110]=''
  473. # issue36
  474. tests[111]='sub f{shift==2}sub test{while(1){last if f(2);}while(1){last if f(2);}}'
  475. result[111]=''
  476. # issue37
  477. tests[112]='my $x;$x||=1;print "ok" if $x;'
  478. result[112]='ok'
  479. # issue38
  480. tests[113]='my $x=2;$x=$x||3;print "ok" if $x==2;'
  481. result[113]='ok'
  482. # issue39
  483. tests[114]='sub f1{0}sub f2{my $x;if(f1()){}if($x){}else{[$x]}}my @a=f2();print "ok";'
  484. result[114]='ok'
  485. # issue42
  486. tests[115]='sub f1{1}f1();print do{7;2},"\n";'
  487. result[115]='2'
  488. # issue44
  489. tests[116]='my @a=(1,2);print $a[0],"\n";'
  490. result[116]='1'
  491. # issue45
  492. tests[117]='my $x;$x//=1;print "ok" if $x;'
  493. result[117]='ok'
  494. # issue46
  495. tests[118]='my $pattern="x";"foo"=~/$pattern/o;print "ok";'
  496. result[118]='ok'
  497. # issue47
  498. tests[119]='my $f=sub{while(1){return(1);}};print $f->(),"\n";'
  499. result[119]='1'
  500. # issue48
  501. tests[120]='sub f{()}print((my ($v)=f())?1:2,"\n");'
  502. result[120]='2'
  503. # issue49
  504. tests[121]='while(1){while(1){last;}last;}print "ok"'
  505. result[121]='ok'
  506. # issue51
  507. 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"}'
  508. result[122]='http'
  509. # issue52
  510. tests[123]='my $x;my $y = 1;$x and $y == 2;print $y == 1 ? "ok\n" : "fail\n";'
  511. result[123]='ok'
  512. # saving recursive functions sometimes recurses in the compiler. this not, but Moose stucks in Pod::Simple
  513. tests[99]='package my;sub recurse{my $i=shift;recurse(++$i)unless $i>5000;print"ok";exit};package main;my::recurse(1)'
  514. result[99]='ok'
  515. init
  516. #
  517. # getopts for -q -k -E -Du,-q -v -O2, -a -c -fro-inc
  518. while getopts "hackoED:B:O:f:q" opt
  519. do
  520. if [ "$opt" = "q" ]; then
  521. QUIET=1
  522. CCMD="$CCMD -q"
  523. fi
  524. if [ "$opt" = "o" ]; then Mblib=" "; init; fi
  525. if [ "$opt" = "c" ]; then CONT=1; fi
  526. if [ "$opt" = "k" ]; then KEEP=1; fi
  527. if [ "$opt" = "E" ]; then CPP=1; fi
  528. if [ "$opt" = "h" ]; then help; exit; fi
  529. # -D options: u,-q for quiet, no -D for verbose, -D- for no gcc warnings
  530. if [ "$opt" = "D" ]; then
  531. OCMD="$PERL $Mblib -MO=C,-D${OPTARG},"
  532. if [ $BASE = "testcc.sh" ]; then
  533. OCMD="$PERL $Mblib -MO=CC,-D${OPTARG},"
  534. fi
  535. if [ -z "${OPTARG/-/}" ]; then
  536. CCMD="$CCMD -d"
  537. fi
  538. fi
  539. # -B dynamic or -B static
  540. if [ "$opt" = "B" ]; then
  541. CCMD="$CCMD -B${OPTARG}"
  542. fi
  543. if [ "$opt" = "O" ]; then OPTIM="$OPTARG"; fi
  544. if [ "$opt" = "f" ]; then
  545. OCMD="$(echo $OCMD|sed -e "s/C,/C,-f$OPTARG,/")"
  546. fi
  547. if [ "$opt" = "a" ]; then # replace -Du, by -Do
  548. OCMD="$(echo $OCMD|sed -r -e 's/(-D.*)u,/\1o,/')"
  549. fi
  550. done
  551. if [ "$(perl -V:gccversion)" != "gccversion='';" ]; then
  552. if [ "$(uname)" = "Darwin" ]; then
  553. CCMD="$CCMD -g -fno-openmp -fno-var-tracking"
  554. else
  555. CCMD="$CCMD -g3"
  556. fi
  557. fi
  558. if [ -z $OPTIM ]; then OPTIM=-1; fi # all
  559. if [ -z "$QUIET" ]; then
  560. make
  561. else
  562. # O from 5.6 does not support -qq
  563. qq="`$PERL -e'print (($] < 5.007) ? q() : q(-qq,))'`"
  564. # replace -D*,-v by -q
  565. OCMD="$(echo $OCMD |sed -e 's/-D.*,//' -e 's/,-v,/,/' -e s/-MO=/-MO=$qq/)"
  566. OCMDO1="$(echo $OCMDO1|sed -e 's/-D.*,//' -e 's/,-v,/,/' -e s/-MO=/-MO=$qq/)"
  567. OCMDO2="$(echo $OCMDO2|sed -e 's/-D.*,//' -e 's/,-v,/,/' -e s/-MO=/-MO=$qq/)"
  568. OCMDO3="$(echo $OCMDO3|sed -e 's/-D.*,//' -e 's/,-v,/,/' -e s/-MO=/-MO=$qq/)"
  569. OCMDO4="$(echo $OCMDO4|sed -e 's/-D.*,//' -e 's/,-v,/,/' -e s/-MO=/-MO=$qq/)"
  570. # gnu make?
  571. make -s >/dev/null || make 2&>1 >/dev/null
  572. fi
  573. # need to shift the options
  574. while [ -n "$1" -a "${1:0:1}" = "-" ]; do shift; done
  575. if [ -n "$1" ]; then
  576. while [ -n "$1" ]; do
  577. ctest $1
  578. shift
  579. done
  580. else
  581. for b in $(seq $ntests); do
  582. ctest $b
  583. done
  584. if [ $BASE = "testcc.sh" ]; then
  585. for b in $(seq 101 $(($ncctests+100))); do
  586. ctest $b
  587. done
  588. fi
  589. fi
  590. # 562 c: 15,25,27
  591. # 58 c: 27,29_i
  592. # 58 cc: 15,18,21,25,26_o,27,29
  593. # 510 c: 15
  594. # 510 cc: 11,15,29
  595. # 511 c: 11,15,16,29
  596. # http://www.nntp.perl.org/group/perl.perl5.porters/2005/07/msg103315.html
  597. # FAIL for B::CC should be covered by test 18