This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.000
[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########
49-P
50use POSIX;
51########
52$array[128]=1
53########
54$x=0x0eabcd; print $x->ref;
55EXPECT
56Can't call method "ref" without a package or object reference at - line 1.
57########
58chop ($str .= <STDIN>);
59########
60close ($banana);
61########
62$x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
63EXPECT
6425
65########
66eval {sub bar {print "In bar";}}
67########
68system "./perl -ne 'print if eof' /dev/null"
69########
70chop($file = <>);
71########
72package N;
73sub new {my ($obj,$n)=@_; bless \$n}
74$aa=new N 1;
75$aa=12345;
76print $aa;
77EXPECT
7812345
79########
80%@x=0;
81EXPECT
82Can't coerce HASH to string in repeat at - line 1.
83########
84$_="foo";
85printf(STDOUT "%s\n", $_);
86EXPECT
87foo
88########
89push(@a, 1, 2, 3,)
90########
91quotemeta ""
92########
93for ("ABCDE") {
94 &sub;
95s/./&sub($&)/eg;
96print;}
97sub sub {local($_) = @_;
98$_ x 4;}
99EXPECT
100Modification of a read-only value attempted at - line 3.
101########
102package FOO;sub new {bless {FOO => BAR}};
103package main;
104use strict vars;
105my $self = new FOO;
106print $$self{FOO};
107EXPECT
108BAR
109########
110$_="foo";
111s/.{1}//s;
112print;
113EXPECT
114oo
115########
116print scalar ("foo","bar")
117EXPECT
118bar
119########
120sub by_number { $a <=> $b; };# inline function for sort below
121$as_ary{0}="a0";
122@ordered_array=sort by_number keys(%as_ary);
123########
124sub NewShell
125{
126 local($Host) = @_;
127 my($m2) = $#Shells++;
128 $Shells[$m2]{HOST} = $Host;
129 return $m2;
130}
131
132sub 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
154eval 'tie @h, FAKEARRAY, fred' ;
155tie @h, FAKEARRAY, fred ;
156EXPECT
157TIEARRAY FAKEARRAY fred
158TIEARRAY FAKEARRAY fred
159DESTROY
160########
161BEGIN { die "phooey\n" }
162EXPECT
163phooey
164BEGIN failed--compilation aborted at - line 1.
165########
166BEGIN { 1/$zero }
167EXPECT
168Illegal division by zero at - line 1.
169BEGIN failed--compilation aborted at - line 1.
170########
171BEGIN { undef = 0 }
172EXPECT
173Modification of a read-only value attempted at - line 1.
174BEGIN failed--compilation aborted at - line 1.