TESTS 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. print 'hi'
  2. >>>>
  3. hi
  4. ######################### ^ 1 ################################
  5. for (1,2,3) { print if /\d/ }
  6. >>>>
  7. 123
  8. ######################### 2 ################################
  9. $_ = "xyxyx"; %j=(1,2); s/x/$j{print("z")}/ge; print $_
  10. >>>>
  11. zzz2y2y2
  12. ######################### 3 ################################
  13. $_ = "xyxyx"; %j=(1,2); s/x/$j{print("z")}/g; print $_
  14. >>>>
  15. z2y2y2
  16. ######################### 4 ################################
  17. print split /a/,"bananarama"
  18. >>>>
  19. bnnrm
  20. ######################### 5 ################################
  21. { package P; sub x { print 'ya' } x }
  22. >>>>
  23. ya
  24. ######################### 6 ################################
  25. @z = split /:/,"b:r:n:f:g"; print @z
  26. >>>>
  27. brnfg
  28. ######################### 7 ################################
  29. sub AUTOLOAD { print 1 } &{"a"}()
  30. >>>>
  31. 1
  32. ######################### 8 ################################
  33. my $l_i = 3; $x = sub { print $l_i }; &$x
  34. >>>>
  35. 3
  36. ######################### 9 ################################
  37. my $i_i = 1;
  38. my $foo = sub {$i_i = shift if @_};
  39. print $i_i;
  40. print &$foo(3),$i_i;
  41. >>>>
  42. 133
  43. ######################### 10 ################################
  44. $x="Cannot use"; print index $x, "Can"
  45. >>>>
  46. 0
  47. ######################### 11 ################################
  48. my $i_i=6; eval "print \$i_i\n"
  49. >>>>
  50. 6
  51. ######################### 12 ################################
  52. BEGIN { %h=(1=>2,3=>4) } print $h{3}
  53. >>>>
  54. 4
  55. ######################### 13 ################################
  56. open our $T,"a"; print 'ok';
  57. >>>>
  58. ok
  59. ######################### 14 ################################
  60. print <DATA>
  61. __DATA__
  62. a
  63. b
  64. >>>>
  65. a
  66. b
  67. ######################### 15 __DATA__ TODO ##################
  68. BEGIN { tie @a, __PACKAGE__; sub TIEARRAY { bless{} } sub FETCH{1} }
  69. print $a[1]
  70. >>>>
  71. 1
  72. ######################### 16 ################################
  73. my $i_ir=3; print 1 .. $i_ir
  74. >>>>
  75. 123
  76. ######################### 17 custom sortcv ##################
  77. my $h = { a=>3, b=>1 }; print sort {$h->{$a} <=> $h->{$b}} keys %$h
  78. >>>>
  79. ba
  80. ######################### 18 ################################
  81. print sort { my $p; $b <=> $a } 1,4,3
  82. >>>>
  83. 431
  84. ######################### 19 ################################
  85. $a="abcd123";my $r=qr/\d/;print $a=~$r;
  86. >>>>
  87. 1
  88. ######################### 20 ################################
  89. sub skip_on_odd{next NUMBER if $_[0]% 2}NUMBER:for($i=0;$i<5;$i++){skip_on_odd($i);print $i;}
  90. >>>>
  91. 024
  92. ######################### 21 ################################
  93. my $fh; BEGIN { open($fh,"<","/dev/null"); } print "ok";
  94. >>>>
  95. ok
  96. ######################### 22 ################################
  97. package MyMod; our $VERSION = 1.3; print "ok"
  98. >>>>
  99. ok
  100. ######################### 23 ################################
  101. sub level1 {return (level2()?"fail":"ok")} sub level2{0} print level1();
  102. >>>>
  103. ok
  104. ######################### 24 ################################
  105. print sort { print $i++," "; $b <=> $a } 1..4
  106. >>>>
  107. 0 1 2 3 .*4321
  108. ######################### 25 ################################
  109. sub a:lvalue{my $a=26; ${\(bless \$a)}}sub b:lvalue{${\shift}}; print ${a(b)};
  110. >>>>
  111. 26
  112. ######################### 26 ################################
  113. # newlib: 0x200, glibc: 0x100
  114. use Fcntl (); print "ok" if ( Fcntl::O_CREAT() >= 64 && &Fcntl::O_CREAT >= 64 );
  115. >>>>
  116. ok
  117. ######################### 27 ################################
  118. 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;unlink($fname);print $x;
  119. >>>>
  120. ok
  121. ######################### 28 ################################
  122. use IO;print "ok";
  123. >>>>
  124. ok
  125. ######################### 29 ################################
  126. @a=(4,6,1,0,0,1);sub range{(shift @a)..(shift @a)}print range();while(@a){print scalar(range())}
  127. >>>>
  128. 456123E0
  129. ######################### 30 ################################
  130. package MockShell;sub AUTOLOAD{my $p=$AUTOLOAD;$p=~s/.*:://;print(join(" ",$p,@_),";");}
  131. package main; MockShell::date();MockShell::who("am","i");MockShell::ls("-l");
  132. >>>>
  133. date;who am i;ls -l;
  134. ######################### 31 ################################
  135. eval{print "1"};eval{die 1};print "2";
  136. >>>>
  137. 12
  138. ######################### 32 CC entertry/jmpenv_jump/leavetry ####
  139. BEGIN{unshift @INC,("t");} use qr_loaded_module; print "ok";
  140. >>>>
  141. ok
  142. ######################### 33 the real qr bug from 5.6.2, see 20 #####
  143. # init of magic hashes. %ENV has e magic since 5.8.9
  144. my $x=$ENV{TMPDIR};print "ok"
  145. >>>>
  146. ok
  147. ######################### 34 does init of magic hashes work in 5.10? #####
  148. 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")
  149. >>>>
  150. 01234
  151. ######################### 35 method calls #####
  152. my ($rv,%hv);%hv=(key=>\$rv);$rv=\%hv;print "ok";
  153. >>>>
  154. ok
  155. ######################### 36 HV self-refs ###################
  156. my ($rv, @av); @av = ( \$rv ); $rv = \@av; print "ok";
  157. >>>>
  158. ok
  159. ######################### 37 AV self-refs ###################
  160. 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";}
  161. >>>>
  162. ok
  163. ############## 38 constant autoload loop crash test #########
  164. {$a=qr/x/;print($] < 5.010 ? 1 : re::is_regexp($a))}
  165. >>>>
  166. 1
  167. ############## 39 non-regexps being upgraded to SVt_REGEXP #####
  168. my $var="this string has a null \\000 byte in it";print "ok";
  169. >>>>
  170. ok
  171. #### 40 used to generate broken .c on 5.6.2 with static pvs ####
  172. # Shared scalar, n magic. => Don't know how to handle magic of type \156.
  173. # ;threads->create(sub{$s="ok"})->join;
  174. # not yet testing n, only P
  175. use threads::shared;{my $s="ok";share($s);print $s}
  176. >>>
  177. ok
  178. #### 41 n-magic ####
  179. # Shared aggregate, P magic
  180. use threads::shared;my %h : shared; print "ok"
  181. >>>
  182. ok
  183. #### 42 P-magic ####
  184. # Aggregate element, n + p magic
  185. use threads::shared;my @a : shared; $a[0]="ok"; print $a[0]
  186. >>>
  187. ok
  188. #### 43 n+p magic ####
  189. # perl #72922 (5.11.4 fails with magic_killbackrefs)
  190. use Scalar::Util "weaken";my $re1=qr/foo/;my $re2=$re1;weaken($re2);print "ok" if $re3=qr/$re1/;
  191. >>>
  192. ok
  193. #### 44 weaken not imported ####
  194. use Data::Dumper ();Data::Dumper::Dumpxs({});print "ok";
  195. >>>
  196. ok
  197. #### 45 test dynamic loading ####
  198. use Exporter; print q(ok) if %main::Exporter::
  199. >>>
  200. ok
  201. #### 46 Exporter:: store stashes only with -fstash. issue 79. ####
  202. @ISA=(q(ok));print $ISA[0];
  203. >>>
  204. ok
  205. #### 47 non-tied av->MAGICAL ####
  206. my $s=q{ok};END{print $s}
  207. >>>>
  208. ok
  209. #### 48 END block destruction ####
  210. print q(ok) if "test" =~ /es/i;
  211. >>>>
  212. ok
  213. #### 49 no-fold ####
  214. package Top;
  215. sub top{q(ok)};
  216. package Next;
  217. our @ISA=qw(Top);
  218. package main;
  219. print Next->top();
  220. >>>>
  221. ok
  222. #### 50 @ISA issue 64 #####