Quick pre-release fixes: clean up results in File::Spec::VMS and
[p5sagit/p5-mst-13.2.git] / t / op / lex_assign.t
CommitLineData
317982ac 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
93430cb4 5 unshift @INC, '../lib';
317982ac 6}
98f7afd0 7$ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
317982ac 8
9umask 0;
10$xref = \ "";
562a7b0c 11$runme = ($^O eq 'VMS' ? 'MCR ' : '') . $^X;
317982ac 12@a = (1..5);
13%h = (1..6);
14$aref = \@a;
15$href = \%h;
562a7b0c 16open OP, qq{$runme -le "print 'aaa Ok ok' for 1..100"|};
317982ac 17$chopit = 'aaaaaa';
18@chopar = (113 .. 119);
19$posstr = '123456';
20$cstr = 'aBcD.eF';
21pos $posstr = 3;
22$nn = $n = 2;
23sub subb {"in s"}
24
25@INPUT = <DATA>;
3dbf192b 26@simple_input = grep /^\s*\w+\s*\$\w+\s*[#\n]/, @INPUT;
6b66af17 27print "1..", (10 + @INPUT + @simple_input), "\n";
317982ac 28$ord = 0;
29
30sub wrn {"@_"}
31
ed7ab888 32# Check correct optimization of ucfirst etc
33$ord++;
34my $a = "AB";
35my $b = "\u\L$a";
36print "not " unless $b eq 'Ab';
37print "ok $ord\n";
38
39# Check correct destruction of objects:
40my $dc = 0;
41sub A::DESTROY {$dc += 1}
42$a=8;
43my $b;
44{ my $c = 6; $b = bless \$c, "A"}
45
46$ord++;
47print "not " unless $dc == 0;
48print "ok $ord\n";
49
50$b = $a+5;
51
52$ord++;
53print "not " unless $dc == 1;
54print "ok $ord\n";
55
69b47968 56$ord++;
57my $xxx = 'b';
58$xxx = 'c' . ($xxx || 'e');
59print "not " unless $xxx eq 'cb';
60print "ok $ord\n";
61
ed7ab888 62{ # Check calling STORE
63 my $sc = 0;
64 sub B::TIESCALAR {bless [11], 'B'}
65 sub B::FETCH { -(shift->[0]) }
66 sub B::STORE { $sc++; my $o = shift; $o->[0] = 17 + shift }
67
68 my $m;
69 tie $m, 'B';
70 $m = 100;
71
72 $ord++;
73 print "not " unless $sc == 1;
74 print "ok $ord\n";
75
76 my $t = 11;
77 $m = $t + 89;
78
79 $ord++;
80 print "not " unless $sc == 2;
81 print "ok $ord\n";
82
83 $ord++;
84 print "# $m\nnot " unless $m == -117;
85 print "ok $ord\n";
86
87 $m += $t;
88
89 $ord++;
90 print "not " unless $sc == 3;
91 print "ok $ord\n";
92
93 $ord++;
94 print "# $m\nnot " unless $m == 89;
95 print "ok $ord\n";
96
97}
98
6b66af17 99# Chains of assignments
100
101my ($l1, $l2, $l3, $l4);
102my $zzzz = 12;
103$zzz1 = $l1 = $l2 = $zzz2 = $l3 = $l4 = 1 + $zzzz;
104
105$ord++;
106print "# $zzz1 = $l1 = $l2 = $zzz2 = $l3 = $l4 = 13\nnot "
107 unless $zzz1 == 13 and $zzz2 == 13 and $l1 == 13
108 and $l2 == 13 and $l3 == 13 and $l4 == 13;
109print "ok $ord\n";
110
317982ac 111for (@INPUT) {
112 $ord++;
113 ($op, undef, $comment) = /^([^\#]+)(\#\s+(.*))?/;
114 $comment = $op unless defined $comment;
115 $op = "$op==$op" unless $op =~ /==/;
116 ($op, $expectop) = $op =~ /(.*)==(.*)/;
117
0f4592ef 118 $skip = ($op =~ /^'\?\?\?'/ or $comment =~ /skip\(.*\Q$^O\E.*\)/i)
119 ? "skip" : "not";
317982ac 120 $integer = ($comment =~ /^i_/) ? "use integer" : '' ;
121 (print "#skipping $comment:\nok $ord\n"), next if $skip eq 'skip';
122
123 eval <<EOE;
124 local \$SIG{__WARN__} = \\&wrn;
125 my \$a = 'fake';
126 $integer;
127 \$a = $op;
128 \$b = $expectop;
129 if (\$a ne \$b) {
130 print "# \$comment: got `\$a', expected `\$b'\n";
131 print "\$skip " if \$a ne \$b or \$skip eq 'skip';
132 }
133 print "ok \$ord\\n";
134EOE
135 if ($@) {
136 if ($@ =~ /is unimplemented/) {
137 print "# skipping $comment: unimplemented:\nok $ord\n";
138 } else {
139 warn $@;
140 print "not ok $ord\n";
141 }
142 }
143}
3dbf192b 144
145for (@simple_input) {
146 $ord++;
147 ($op, undef, $comment) = /^([^\#]+)(\#\s+(.*))?/;
148 $comment = $op unless defined $comment;
149 ($operator, $variable) = /^\s*(\w+)\s*\$(\w+)/ or warn "misprocessed '$_'\n";
150 eval <<EOE;
151 local \$SIG{__WARN__} = \\&wrn;
152 my \$$variable = "Ac# Ca\\nxxx";
153 \$$variable = $operator \$$variable;
154 \$toself = \$$variable;
155 \$direct = $operator "Ac# Ca\\nxxx";
156 print "# \\\$$variable = $operator \\\$$variable\\nnot "
157 unless \$toself eq \$direct;
158 print "ok \$ord\\n";
159EOE
160 if ($@) {
161 if ($@ =~ /is unimplemented/) {
162 print "# skipping $comment: unimplemented:\nok $ord\n";
163 } elsif ($@ =~ /Can't (modify|take log of 0)/) {
164 print "# skipping $comment: syntax not good for selfassign:\nok $ord\n";
165 } else {
166 warn $@;
167 print "not ok $ord\n";
168 }
169 }
170}
317982ac 171__END__
172ref $xref # ref
173ref $cstr # ref nonref
562a7b0c 174`$runme -e "print qq[1\n]"` # backtick skip(MSWin32)
0f4592ef 175`$undefed` # backtick undef skip(MSWin32)
317982ac 176<*> # glob
177<OP> # readline
178'faked' # rcatline
179(@z = (1 .. 3)) # aassign
180chop $chopit # chop
181(chop (@x=@chopar)) # schop
182chomp $chopit # chomp
183(chop (@x=@chopar)) # schomp
184pos $posstr # pos
185pos $chopit # pos returns undef
186$nn++==2 # postinc
187$nn++==3 # i_postinc
188$nn--==4 # postdec
189$nn--==3 # i_postdec
190$n ** $n # pow
191$n * $n # multiply
192$n * $n # i_multiply
193$n / $n # divide
194$n / $n # i_divide
195$n % $n # modulo
196$n % $n # i_modulo
197$n x $n # repeat
198$n + $n # add
199$n + $n # i_add
200$n - $n # subtract
201$n - $n # i_subtract
202$n . $n # concat
203$n . $a=='2fake' # concat with self
204"3$a"=='3fake' # concat with self in stringify
205"$n" # stringify
206$n << $n # left_shift
207$n >> $n # right_shift
208$n <=> $n # ncmp
209$n <=> $n # i_ncmp
210$n cmp $n # scmp
211$n & $n # bit_and
212$n ^ $n # bit_xor
213$n | $n # bit_or
214-$n # negate
215-$n # i_negate
216~$n # complement
217atan2 $n,$n # atan2
218sin $n # sin
219cos $n # cos
220'???' # rand
221exp $n # exp
222log $n # log
223sqrt $n # sqrt
224int $n # int
225hex $n # hex
226oct $n # oct
227abs $n # abs
228length $posstr # length
229substr $posstr, 2, 2 # substr
230vec("abc",2,8) # vec
231index $posstr, 2 # index
232rindex $posstr, 2 # rindex
233sprintf "%i%i", $n, $n # sprintf
234ord $n # ord
235chr $n # chr
236crypt $n, $n # crypt
237ucfirst ($cstr . "a") # ucfirst padtmp
238ucfirst $cstr # ucfirst
239lcfirst $cstr # lcfirst
240uc $cstr # uc
241lc $cstr # lc
242quotemeta $cstr # quotemeta
243@$aref # rv2av
244@$undefed # rv2av undef
245each %h==1 # each
246values %h # values
247keys %h # keys
248%$href # rv2hv
249pack "C2", $n,$n # pack
250split /a/, "abad" # split
251join "a"; @a # join
252push @a,3==6 # push
253unshift @aaa # unshift
254reverse @a # reverse
255reverse $cstr # reverse - scal
256grep $_, 1,0,2,0,3 # grepwhile
257map "x$_", 1,0,2,0,3 # mapwhile
258subb() # entersub
259caller # caller
260warn "ignore this\n" # warn
261'faked' # die
262open BLAH, "<non-existent" # open
263fileno STDERR # fileno
264umask 0 # umask
265select STDOUT # sselect
266select "","","",0 # select
267getc OP # getc
268'???' # read
269'???' # sysread
270'???' # syswrite
271'???' # send
272'???' # recv
273'???' # tell
274'???' # fcntl
275'???' # ioctl
276'???' # flock
277'???' # accept
278'???' # shutdown
279'???' # ftsize
280'???' # ftmtime
281'???' # ftatime
282'???' # ftctime
283chdir 'non-existent' # chdir
284'???' # chown
285'???' # chroot
286unlink 'non-existent' # unlink
287chmod 'non-existent' # chmod
288utime 'non-existent' # utime
289rename 'non-existent', 'non-existent1' # rename
290link 'non-existent', 'non-existent1' # link
ecece5d6 291'???' # symlink
317982ac 292readlink 'non-existent', 'non-existent1' # readlink
293'???' # mkdir
294'???' # rmdir
295'???' # telldir
296'???' # fork
297'???' # wait
298'???' # waitpid
562a7b0c 299system "$runme -e 0" # system skip(VMS)
317982ac 300'???' # exec
0f4592ef 301'???' # kill
317982ac 302getppid # getppid
303getpgrp # getpgrp
304'???' # setpgrp
305getpriority $$, $$ # getpriority
306'???' # setpriority
307time # time
7e3cfbc1 308localtime $^T # localtime
309gmtime $^T # gmtime
317982ac 310sleep 1 # sleep
311'???' # alarm
312'???' # shmget
313'???' # shmctl
314'???' # shmread
315'???' # shmwrite
316'???' # msgget
317'???' # msgctl
318'???' # msgsnd
319'???' # msgrcv
320'???' # semget
321'???' # semctl
322'???' # semop
323'???' # getlogin
324'???' # syscall