more complete File::Spec support for Mac and VMS, tests (from
[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;
69b47968 27print "1..", (9 + @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
317982ac 99for (@INPUT) {
100 $ord++;
101 ($op, undef, $comment) = /^([^\#]+)(\#\s+(.*))?/;
102 $comment = $op unless defined $comment;
103 $op = "$op==$op" unless $op =~ /==/;
104 ($op, $expectop) = $op =~ /(.*)==(.*)/;
105
0f4592ef 106 $skip = ($op =~ /^'\?\?\?'/ or $comment =~ /skip\(.*\Q$^O\E.*\)/i)
107 ? "skip" : "not";
317982ac 108 $integer = ($comment =~ /^i_/) ? "use integer" : '' ;
109 (print "#skipping $comment:\nok $ord\n"), next if $skip eq 'skip';
110
111 eval <<EOE;
112 local \$SIG{__WARN__} = \\&wrn;
113 my \$a = 'fake';
114 $integer;
115 \$a = $op;
116 \$b = $expectop;
117 if (\$a ne \$b) {
118 print "# \$comment: got `\$a', expected `\$b'\n";
119 print "\$skip " if \$a ne \$b or \$skip eq 'skip';
120 }
121 print "ok \$ord\\n";
122EOE
123 if ($@) {
124 if ($@ =~ /is unimplemented/) {
125 print "# skipping $comment: unimplemented:\nok $ord\n";
126 } else {
127 warn $@;
128 print "not ok $ord\n";
129 }
130 }
131}
3dbf192b 132
133for (@simple_input) {
134 $ord++;
135 ($op, undef, $comment) = /^([^\#]+)(\#\s+(.*))?/;
136 $comment = $op unless defined $comment;
137 ($operator, $variable) = /^\s*(\w+)\s*\$(\w+)/ or warn "misprocessed '$_'\n";
138 eval <<EOE;
139 local \$SIG{__WARN__} = \\&wrn;
140 my \$$variable = "Ac# Ca\\nxxx";
141 \$$variable = $operator \$$variable;
142 \$toself = \$$variable;
143 \$direct = $operator "Ac# Ca\\nxxx";
144 print "# \\\$$variable = $operator \\\$$variable\\nnot "
145 unless \$toself eq \$direct;
146 print "ok \$ord\\n";
147EOE
148 if ($@) {
149 if ($@ =~ /is unimplemented/) {
150 print "# skipping $comment: unimplemented:\nok $ord\n";
151 } elsif ($@ =~ /Can't (modify|take log of 0)/) {
152 print "# skipping $comment: syntax not good for selfassign:\nok $ord\n";
153 } else {
154 warn $@;
155 print "not ok $ord\n";
156 }
157 }
158}
317982ac 159__END__
160ref $xref # ref
161ref $cstr # ref nonref
562a7b0c 162`$runme -e "print qq[1\n]"` # backtick skip(MSWin32)
0f4592ef 163`$undefed` # backtick undef skip(MSWin32)
317982ac 164<*> # glob
165<OP> # readline
166'faked' # rcatline
167(@z = (1 .. 3)) # aassign
168chop $chopit # chop
169(chop (@x=@chopar)) # schop
170chomp $chopit # chomp
171(chop (@x=@chopar)) # schomp
172pos $posstr # pos
173pos $chopit # pos returns undef
174$nn++==2 # postinc
175$nn++==3 # i_postinc
176$nn--==4 # postdec
177$nn--==3 # i_postdec
178$n ** $n # pow
179$n * $n # multiply
180$n * $n # i_multiply
181$n / $n # divide
182$n / $n # i_divide
183$n % $n # modulo
184$n % $n # i_modulo
185$n x $n # repeat
186$n + $n # add
187$n + $n # i_add
188$n - $n # subtract
189$n - $n # i_subtract
190$n . $n # concat
191$n . $a=='2fake' # concat with self
192"3$a"=='3fake' # concat with self in stringify
193"$n" # stringify
194$n << $n # left_shift
195$n >> $n # right_shift
196$n <=> $n # ncmp
197$n <=> $n # i_ncmp
198$n cmp $n # scmp
199$n & $n # bit_and
200$n ^ $n # bit_xor
201$n | $n # bit_or
202-$n # negate
203-$n # i_negate
204~$n # complement
205atan2 $n,$n # atan2
206sin $n # sin
207cos $n # cos
208'???' # rand
209exp $n # exp
210log $n # log
211sqrt $n # sqrt
212int $n # int
213hex $n # hex
214oct $n # oct
215abs $n # abs
216length $posstr # length
217substr $posstr, 2, 2 # substr
218vec("abc",2,8) # vec
219index $posstr, 2 # index
220rindex $posstr, 2 # rindex
221sprintf "%i%i", $n, $n # sprintf
222ord $n # ord
223chr $n # chr
224crypt $n, $n # crypt
225ucfirst ($cstr . "a") # ucfirst padtmp
226ucfirst $cstr # ucfirst
227lcfirst $cstr # lcfirst
228uc $cstr # uc
229lc $cstr # lc
230quotemeta $cstr # quotemeta
231@$aref # rv2av
232@$undefed # rv2av undef
233each %h==1 # each
234values %h # values
235keys %h # keys
236%$href # rv2hv
237pack "C2", $n,$n # pack
238split /a/, "abad" # split
239join "a"; @a # join
240push @a,3==6 # push
241unshift @aaa # unshift
242reverse @a # reverse
243reverse $cstr # reverse - scal
244grep $_, 1,0,2,0,3 # grepwhile
245map "x$_", 1,0,2,0,3 # mapwhile
246subb() # entersub
247caller # caller
248warn "ignore this\n" # warn
249'faked' # die
250open BLAH, "<non-existent" # open
251fileno STDERR # fileno
252umask 0 # umask
253select STDOUT # sselect
254select "","","",0 # select
255getc OP # getc
256'???' # read
257'???' # sysread
258'???' # syswrite
259'???' # send
260'???' # recv
261'???' # tell
262'???' # fcntl
263'???' # ioctl
264'???' # flock
265'???' # accept
266'???' # shutdown
267'???' # ftsize
268'???' # ftmtime
269'???' # ftatime
270'???' # ftctime
271chdir 'non-existent' # chdir
272'???' # chown
273'???' # chroot
274unlink 'non-existent' # unlink
275chmod 'non-existent' # chmod
276utime 'non-existent' # utime
277rename 'non-existent', 'non-existent1' # rename
278link 'non-existent', 'non-existent1' # link
ecece5d6 279'???' # symlink
317982ac 280readlink 'non-existent', 'non-existent1' # readlink
281'???' # mkdir
282'???' # rmdir
283'???' # telldir
284'???' # fork
285'???' # wait
286'???' # waitpid
562a7b0c 287system "$runme -e 0" # system skip(VMS)
317982ac 288'???' # exec
0f4592ef 289'???' # kill
317982ac 290getppid # getppid
291getpgrp # getpgrp
292'???' # setpgrp
293getpriority $$, $$ # getpriority
294'???' # setpriority
295time # time
7e3cfbc1 296localtime $^T # localtime
297gmtime $^T # gmtime
317982ac 298sleep 1 # sleep
299'???' # alarm
300'???' # shmget
301'???' # shmctl
302'???' # shmread
303'???' # shmwrite
304'???' # msgget
305'???' # msgctl
306'???' # msgsnd
307'???' # msgrcv
308'???' # semget
309'???' # semctl
310'???' # semop
311'???' # getlogin
312'???' # syscall