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 destruction 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 # do not use B:: namespace
106 sub BB::TIESCALAR {bless [11], 'BB'}
107 sub BB::FETCH { -(shift->[0]) }
108 sub BB::STORE { $sc++; my $o = shift; $o->[0] = 17 + shift }
114 is( $sc, 1, 'STORE called when assigning scalar to tied variable' );
119 is( $sc, 2, 'and again' );
120 is( $m, -117, 'checking the tied variable result' );
124 is( $sc, 3, 'called on self-increment' );
125 is( $m, 89, 'checking the tied variable result' );
128 ($op, undef, $comment) = /^([^\#]+)(\#\s+(.*))?/;
129 $comment = $op unless defined $comment;
130 next if ($op =~ /^'\?\?\?'/ or $comment =~ /skip\(.*\Q$^O\E.*\)/i);
134 local $SIG{__WARN__} = \&wrn;
136 is $sc, $@ ? 0 : 1, "STORE count for $comment";
140 for (@simple_input) {
141 ($op, undef, $comment) = /^([^\#]+)(\#\s+(.*))?/;
142 $comment = $op unless defined $comment;
144 ($operator, $variable) = /^\s*(\w+)\s*\$(\w+)/ or warn "misprocessed '$_'\n";
146 local \$SIG{__WARN__} = \\&wrn;
147 my \$$variable = "Ac# Ca\\nxxx";
148 \$$variable = $operator \$$variable;
149 \$toself = \$$variable;
150 \$direct = $operator "Ac# Ca\\nxxx";
151 is(\$toself, \$direct);
156 if ($@ =~ /(?:is un|not )implemented/) {
161 } elsif ($@ =~ /Can't (modify|take log of 0)/) {
163 skip $warning . ' ' . $comment . ' syntax not good for selfassign', 1;
167 ##Something bad happened
168 fail($_ . ' ' . $warning);
173 # [perl #123790] Assigning to a typeglob
174 # These used to die or crash.
175 # Once the bug is fixed for all ops, we can combine this with the tests
176 # above that use <DATA>.
179 { use integer; $glob = $y <=> $z; }
186 # XXX This test does not really belong here, as it has nothing to do with
187 # OPpTARGET_MY optimisation. But where should it go?
189 sub PVBM () { 'foo' }
194 my $pvlv = \substr $str, 0, 1;
199 is($@, '', 'ex-PVBM assert'.$@);
202 # Check that stringification and assignment to itself doesn't break
203 # anything. This is unlikely to actually fail the tests; its more something
204 # for valgrind to spot. It will also only fail if SvGROW or its caller
205 # decides to over-allocate (otherwise copying the string will skip the
206 # sv_grow(), as the new size is the same as the current size).
210 for my $len (1..40) {
214 ok($s eq $t, "RT 127855: len=$len");
218 # time() can't be tested using the standard framework since two successive
219 # calls may return differing values.
226 cmp_ok($diff, '>=', 0, "time is monotically increasing");
227 cmp_ok($diff, '<', 2, "time delta is small");
230 # GH #20132 and parts of GH ##20114
231 # During development of OP_PADSV_STORE, interactions with OP_PADRANGE
232 # caused BBC failures not picked up by any pre-existing core tests.
233 # (Problems only arose in list context, the void/scalar tests have been
234 # included for completeness.)
240 is($@, '', 'keys %{$y = $x}');
244 my $foo = keys %{$y = $x};
247 is($@, '', 'my $foo = keys %{$y = $x}');
251 my @foo = keys %{$y = $x};
254 is($@, '', 'my @foo = keys %{$y = $x}');
256 fresh_perl_is('my ($x, $y); (($y = $x))', '', {}, '(($y = $x))');
257 fresh_perl_is('my ($x, $y); my $z= (($y = $x))', '', {}, 'my $z= (($y = $x))');
258 fresh_perl_is('my ($x, $y); my @z= (($y = $x))', '', {}, 'my @z= (($y = $x))');
264 ref $cstr # ref nonref
265 `$runme -e "print qq[1\\n]"` # backtick skip(MSWin32)
266 `$undefed` # backtick undef skip(MSWin32)
267 '???' # glob (not currently OA_TARGLEX)
270 (@z = (1 .. 3)) # aassign
271 (chop (@x=@chopar)) # chop
273 (chomp (@x=@chopar)) # chomp
274 chomp $chopit # schomp
276 pos $chopit # pos returns undef
294 $n . $a=='2fake' # concat with self
295 "3$a"=='3fake' # concat with self in stringify
297 $n << $n # left_shift
298 $n >> $n # right_shift
307 -$a=="-fake" # i_negate with string
320 length $posstr # length
321 substr $posstr, 2, 2 # substr
323 index $posstr, 2 # index
324 rindex $posstr, 2 # rindex
325 sprintf "%i%i", $n, $n # sprintf
328 chr ${\256} # chr $wide
330 ucfirst ($cstr . "a") # ucfirst padtmp
331 ucfirst $cstr # ucfirst
332 lcfirst $cstr # lcfirst
335 quotemeta $cstr # quotemeta
337 @$undefed # rv2av undef
338 (each %h) % 2 == 1 # each
342 pack "C2", $n,$n # pack
343 split /a/, "abad" # split
346 unshift @aaa # unshift
348 reverse $cstr # reverse - scal
349 grep $_, 1,0,2,0,3 # grepwhile
350 map "x$_", 1,0,2,0,3 # mapwhile
353 warn "ignore this\n" # warn
355 open BLAH, "<non-existent" # open
356 fileno STDERR # fileno
358 select STDOUT # sselect
359 select undef,undef,undef,0 # select
376 chdir 'non-existent' # chdir
379 unlink 'non-existent' # unlink
380 chmod 'non-existent' # chmod
381 utime 'non-existent' # utime
382 rename 'non-existent', 'non-existent1' # rename
383 link 'non-existent', 'non-existent1' # link
385 readlink 'non-existent', 'non-existent1' # readlink
392 system "$runme -e 0" # system skip(VMS)
398 getpriority $$, $$ # getpriority
401 localtime $^T # localtime
403 '???' # sleep: can randomly fail