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