[shell changes from patch from perl5.003_16 to perl5.003_17]
[p5sagit/p5-mst-13.2.git] / t / op / misc.t
CommitLineData
a0d0e21e 1#!./perl
2
3chdir 't' if -d 't';
4@INC = "../lib";
5$ENV{PERL5LIB} = "../lib";
6
7$|=1;
8
9undef $/;
10@prgs = split "\n########\n", <DATA>;
11print "1..", scalar @prgs, "\n";
12
13$tmpfile = "misctmp000";
141 while -f ++$tmpfile;
15END { unlink $tmpfile if $tmpfile; }
16
17for (@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__
36477c24 40$cusp = ~0 ^ (~0 >> 1);
41$, = " ";
42print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, ($cusp + 1) % 8, "!\n";
43EXPECT
447 0 0 1 !
45########
a0d0e21e 46$foo=undef; $foo->go;
47EXPECT
48Can't call method "go" without a package or object reference at - line 1.
49########
50BEGIN
51 {
52 "foo";
53 }
54########
a0d0e21e 55$array[128]=1
56########
57$x=0x0eabcd; print $x->ref;
58EXPECT
59Can't call method "ref" without a package or object reference at - line 1.
60########
61chop ($str .= <STDIN>);
62########
63close ($banana);
64########
65$x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
66EXPECT
6725
68########
69eval {sub bar {print "In bar";}}
70########
71system "./perl -ne 'print if eof' /dev/null"
72########
73chop($file = <>);
74########
75package N;
76sub new {my ($obj,$n)=@_; bless \$n}
77$aa=new N 1;
78$aa=12345;
79print $aa;
80EXPECT
8112345
82########
83%@x=0;
84EXPECT
85Can't coerce HASH to string in repeat at - line 1.
86########
87$_="foo";
88printf(STDOUT "%s\n", $_);
89EXPECT
90foo
91########
92push(@a, 1, 2, 3,)
93########
94quotemeta ""
95########
96for ("ABCDE") {
97 &sub;
98s/./&sub($&)/eg;
99print;}
100sub sub {local($_) = @_;
101$_ x 4;}
102EXPECT
103Modification of a read-only value attempted at - line 3.
104########
105package FOO;sub new {bless {FOO => BAR}};
106package main;
107use strict vars;
108my $self = new FOO;
109print $$self{FOO};
110EXPECT
111BAR
112########
113$_="foo";
114s/.{1}//s;
115print;
116EXPECT
117oo
118########
119print scalar ("foo","bar")
120EXPECT
121bar
122########
123sub by_number { $a <=> $b; };# inline function for sort below
124$as_ary{0}="a0";
125@ordered_array=sort by_number keys(%as_ary);
126########
127sub NewShell
128{
129 local($Host) = @_;
130 my($m2) = $#Shells++;
131 $Shells[$m2]{HOST} = $Host;
132 return $m2;
133}
134
135sub ShowShell
136{
137 local($i) = @_;
138}
139
140&ShowShell(&NewShell(beach,Work,"+0+0"));
141&ShowShell(&NewShell(beach,Work,"+0+0"));
142&ShowShell(&NewShell(beach,Work,"+0+0"));
143########
144 {
145 package FAKEARRAY;
146
147 sub TIEARRAY
148 { print "TIEARRAY @_\n";
149 die "bomb out\n" unless $count ++ ;
150 bless ['foo']
151 }
152 sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
153 sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
154 sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
155 }
156
157eval 'tie @h, FAKEARRAY, fred' ;
158tie @h, FAKEARRAY, fred ;
159EXPECT
160TIEARRAY FAKEARRAY fred
161TIEARRAY FAKEARRAY fred
162DESTROY
163########
164BEGIN { die "phooey\n" }
165EXPECT
166phooey
167BEGIN failed--compilation aborted at - line 1.
168########
169BEGIN { 1/$zero }
170EXPECT
171Illegal division by zero at - line 1.
172BEGIN failed--compilation aborted at - line 1.
173########
174BEGIN { undef = 0 }
175EXPECT
176Modification of a read-only value attempted at - line 1.
177BEGIN failed--compilation aborted at - line 1.
a7adf1f0 178########
179{
180 package foo;
181 sub PRINT {
182 shift;
183 print join(' ', reverse @_)."\n";
184 }
185 sub TIEHANDLE {
186 bless {}, shift;
187 }
58f51617 188 sub READLINE {
189 "Out of inspiration";
190 }
a7adf1f0 191 sub DESTROY {
192 print "and destroyed as well\n";
193 }
194}
195{
196 local(*FOO);
197 tie(*FOO,'foo');
198 print FOO "sentence.", "reversed", "a", "is", "This";
58f51617 199 print "-- ", <FOO>, " --\n";
a7adf1f0 200}
201EXPECT
202This is a reversed sentence.
58f51617 203-- Out of inspiration --
a7adf1f0 204and destroyed as well