3 # Test that $lexical = <some op> optimises the assignment away correctly
4 # and causes no ill side-effects.
20 open OP, qq{$runme -le "print 'aaa Ok ok' for 1..100"|};
22 @chopar = (113 .. 119);
30 @simple_input = grep /^\s*\w+\s*\$\w+\s*[#\n]/, @INPUT;
34 # Check correct optimization of ucfirst etc
37 is( $b, 'Ab', 'Check correct optimization of ucfirst, etc');
39 # Check correct destruction of objects:
41 sub A::DESTROY {$dc += 1}
44 { my $c = 6; $b = bless \$c, "A"}
46 is($dc, 0, 'No destruction yet');
50 is($dc, 1, 'object descruction via reassignment to variable');
53 $xxx = 'c' . ($xxx || 'e');
54 is( $xxx, 'cb', 'variables can be read before being overwritten');
56 # Chains of assignments
58 my ($l1, $l2, $l3, $l4);
60 $zzz1 = $l1 = $l2 = $zzz2 = $l3 = $l4 = 1 + $zzzz;
62 is($zzz1, 13, 'chain assignment, part1');
63 is($zzz2, 13, 'chain assignment, part2');
64 is($l1, 13, 'chain assignment, part3');
65 is($l2, 13, 'chain assignment, part4');
66 is($l3, 13, 'chain assignment, part5');
67 is($l4, 13, 'chain assignment, part6');
70 ($op, undef, $comment) = /^([^\#]+)(\#\s+(.*))?/;
71 $comment = $op unless defined $comment;
73 $op = "$op==$op" unless $op =~ /==/;
74 ($op, $expectop) = $op =~ /(.*)==(.*)/;
76 $skip = ($op =~ /^'\?\?\?'/ or $comment =~ /skip\(.*\Q$^O\E.*\)/i);
77 $integer = ($comment =~ /^i_/) ? "use integer" : '' ;
86 local \$SIG{__WARN__} = \\&wrn;
91 is (\$a, \$b, \$comment);
96 if ($@ !~ /(?:is un|not )implemented/) {
97 fail($_ . ' ' . $warning);
102 { # Check calling STORE
103 note('Tied variables, calling STORE');
105 sub B::TIESCALAR {bless [11], 'B'}
106 sub B::FETCH { -(shift->[0]) }
107 sub B::STORE { $sc++; my $o = shift; $o->[0] = 17 + shift }
113 is( $sc, 1, 'STORE called when assigning scalar to tied variable' );
118 is( $sc, 2, 'and again' );
119 is( $m, -117, 'checking the tied variable result' );
123 is( $sc, 3, 'called on self-increment' );
124 is( $m, 89, 'checking the tied variable result' );
127 ($op, undef, $comment) = /^([^\#]+)(\#\s+(.*))?/;
128 $comment = $op unless defined $comment;
129 next if ($op =~ /^'\?\?\?'/ or $comment =~ /skip\(.*\Q$^O\E.*\)/i);
133 local $SIG{__WARN__} = \&wrn;
135 is $sc, $@ ? 0 : 1, "STORE count for $comment";
139 for (@simple_input) {
140 ($op, undef, $comment) = /^([^\#]+)(\#\s+(.*))?/;
141 $comment = $op unless defined $comment;
143 ($operator, $variable) = /^\s*(\w+)\s*\$(\w+)/ or warn "misprocessed '$_'\n";
145 local \$SIG{__WARN__} = \\&wrn;
146 my \$$variable = "Ac# Ca\\nxxx";
147 \$$variable = $operator \$$variable;
148 \$toself = \$$variable;
149 \$direct = $operator "Ac# Ca\\nxxx";
150 is(\$toself, \$direct);
155 if ($@ =~ /(?:is un|not )implemented/) {
160 } elsif ($@ =~ /Can't (modify|take log of 0)/) {
162 skip $warning . ' ' . $comment . ' syntax not good for selfassign', 1;
166 ##Something bad happened
167 fail($_ . ' ' . $warning);
172 # XXX This test does not really belong here, as it has nothing to do with
173 # OPpTARGET_MY optimisation. But where should it go?
175 sub PVBM () { 'foo' }
180 my $pvlv = \substr $str, 0, 1;
185 is($@, '', 'ex-PVBM assert'.$@);
191 ref $cstr # ref nonref
192 `$runme -e "print qq[1\\n]"` # backtick skip(MSWin32)
193 `$undefed` # backtick undef skip(MSWin32)
197 (@z = (1 .. 3)) # aassign
199 (chop (@x=@chopar)) # schop
200 chomp $chopit # chomp
201 (chop (@x=@chopar)) # schomp
203 pos $chopit # pos returns undef
221 $n . $a=='2fake' # concat with self
222 "3$a"=='3fake' # concat with self in stringify
224 $n << $n # left_shift
225 $n >> $n # right_shift
234 -$a=="-fake" # i_negate with string
247 length $posstr # length
248 substr $posstr, 2, 2 # substr
250 index $posstr, 2 # index
251 rindex $posstr, 2 # rindex
252 sprintf "%i%i", $n, $n # sprintf
255 chr ${\256} # chr $wide
257 ucfirst ($cstr . "a") # ucfirst padtmp
258 ucfirst $cstr # ucfirst
259 lcfirst $cstr # lcfirst
262 quotemeta $cstr # quotemeta
264 @$undefed # rv2av undef
265 (each %h) % 2 == 1 # each
269 pack "C2", $n,$n # pack
270 split /a/, "abad" # split
273 unshift @aaa # unshift
275 reverse $cstr # reverse - scal
276 grep $_, 1,0,2,0,3 # grepwhile
277 map "x$_", 1,0,2,0,3 # mapwhile
280 warn "ignore this\n" # warn
282 open BLAH, "<non-existent" # open
283 fileno STDERR # fileno
285 select STDOUT # sselect
286 select undef,undef,undef,0 # select
303 chdir 'non-existent' # chdir
306 unlink 'non-existent' # unlink
307 chmod 'non-existent' # chmod
308 utime 'non-existent' # utime
309 rename 'non-existent', 'non-existent1' # rename
310 link 'non-existent', 'non-existent1' # link
312 readlink 'non-existent', 'non-existent1' # readlink
319 system "$runme -e 0" # system skip(VMS)
325 getpriority $$, $$ # getpriority
328 localtime $^T # localtime
330 '???' # sleep: can randomly fail