home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / utilities / cli / perl / !Perl / t / op / misc < prev    next >
Encoding:
Text File  |  1994-10-18  |  3.2 KB  |  175 lines

  1. #!./perl
  2.  
  3. chdir 't' if -d 't';
  4. @INC = "../lib";
  5. $ENV{PERL5LIB} = "../lib";
  6.  
  7. $|=1;
  8.  
  9. undef $/;
  10. @prgs = split "\n########\n", <DATA>;
  11. print "1..", scalar @prgs, "\n";
  12.  
  13. $tmpfile = "misctmp000";
  14. 1 while -f ++$tmpfile;
  15. END { unlink $tmpfile if $tmpfile; }
  16.  
  17. for (@prgs){
  18.     my $switch;
  19.     if (s/^\s*-\w+//){
  20.     $switch = $&;
  21.     }
  22.     my($prog,$expected) = split(/\nEXPECT\n/, $_);
  23.     open TEST, "| sh -c './perl $switch' >$tmpfile 2>&1";
  24.     print TEST $prog, "\n";
  25.     close TEST;
  26.     $status = $?;
  27.     $results = `cat $tmpfile`;
  28.     $results =~ s/\n+$//;
  29.     $expected =~ s/\n+$//;
  30.     if ( $results ne $expected){
  31.     print STDERR "PROG: $switch\n$prog\n";
  32.     print STDERR "EXPECTED:\n$expected\n";
  33.     print STDERR "GOT:\n$results\n";
  34.     print "not ";
  35.     }
  36.     print "ok ", ++$i, "\n";
  37. }
  38.  
  39. __END__
  40. $foo=undef; $foo->go;
  41. EXPECT
  42. Can't call method "go" without a package or object reference at - line 1.
  43. ########
  44. BEGIN
  45.         {
  46.         "foo";
  47.         }
  48. ########
  49. -P 
  50. use POSIX;
  51. ########
  52. $array[128]=1
  53. ########
  54. $x=0x0eabcd; print $x->ref;
  55. EXPECT
  56. Can't call method "ref" without a package or object reference at - line 1.
  57. ########
  58. chop ($str .= <STDIN>);
  59. ########
  60. close ($banana);
  61. ########
  62. $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
  63. EXPECT
  64. 25
  65. ########
  66. eval {sub bar {print "In bar";}}
  67. ########
  68. system "./perl -ne 'print if eof' /dev/null"
  69. ########
  70. chop($file = <>);
  71. ########
  72. package N;
  73. sub new {my ($obj,$n)=@_; bless \$n}  
  74. $aa=new N 1;
  75. $aa=12345;
  76. print $aa;
  77. EXPECT
  78. 12345
  79. ########
  80. %@x=0;
  81. EXPECT
  82. Can't coerce HASH to string in repeat at - line 1.
  83. ########
  84. $_="foo";
  85. printf(STDOUT "%s\n", $_);
  86. EXPECT
  87. foo
  88. ########
  89. push(@a, 1, 2, 3,)
  90. ########
  91. quotemeta ""
  92. ########
  93. for ("ABCDE") {
  94.  ⊂
  95. s/./&sub($&)/eg;
  96. print;}
  97. sub sub {local($_) = @_;
  98. $_ x 4;}
  99. EXPECT
  100. Modification of a read-only value attempted at - line 3.
  101. ########
  102. package FOO;sub new {bless {FOO => BAR}};
  103. package main;
  104. use strict vars;   
  105. my $self = new FOO;
  106. print $$self{FOO};
  107. EXPECT
  108. BAR
  109. ########
  110. $_="foo";
  111. s/.{1}//s;
  112. print;
  113. EXPECT
  114. oo
  115. ########
  116. print scalar ("foo","bar")
  117. EXPECT
  118. bar
  119. ########
  120. sub by_number { $a <=> $b; };# inline function for sort below
  121. $as_ary{0}="a0";
  122. @ordered_array=sort by_number keys(%as_ary);
  123. ########
  124. sub NewShell
  125. {
  126.   local($Host) = @_;
  127.   my($m2) = $#Shells++;
  128.   $Shells[$m2]{HOST} = $Host;
  129.   return $m2;
  130. }
  131.  
  132. sub ShowShell
  133. {
  134.   local($i) = @_;
  135. }
  136.  
  137. &ShowShell(&NewShell(beach,Work,"+0+0"));
  138. &ShowShell(&NewShell(beach,Work,"+0+0"));
  139. &ShowShell(&NewShell(beach,Work,"+0+0"));
  140. ########
  141.    {
  142.        package FAKEARRAY;
  143.    
  144.        sub TIEARRAY
  145.        { print "TIEARRAY @_\n"; 
  146.          die "bomb out\n" unless $count ++ ;
  147.          bless ['foo'] 
  148.        }
  149.        sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
  150.        sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
  151.        sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
  152.    }
  153.    
  154. eval 'tie @h, FAKEARRAY, fred' ;
  155. tie @h, FAKEARRAY, fred ;
  156. EXPECT
  157. TIEARRAY FAKEARRAY fred
  158. TIEARRAY FAKEARRAY fred
  159. DESTROY 
  160. ########
  161. BEGIN { die "phooey\n" }
  162. EXPECT
  163. phooey
  164. BEGIN failed--compilation aborted at - line 1.
  165. ########
  166. BEGIN { 1/$zero }
  167. EXPECT
  168. Illegal division by zero at - line 1.
  169. BEGIN failed--compilation aborted at - line 1.
  170. ########
  171. BEGIN { undef = 0 }
  172. EXPECT
  173. Modification of a read-only value attempted at - line 1.
  174. BEGIN failed--compilation aborted at - line 1.
  175.