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