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