4 # Verify which OP= operators warn if their targets are undefined.
5 # Based on redef.t, contributed by Graham Barr <Graham.Barr@tiuk.ti.com>
8 # Now almost completely rewritten.
18 my (%should_warn, %should_not);
19 ++$should_warn{$_} foreach qw(* / x & ** << >>);
20 ++$should_not{$_} foreach qw(+ - . | ^ && ||);
22 my %todo_as_tie = reverse (add => '+', subtract => '-',
23 bit_or => '|', bit_xor => '^');
25 my %integer = reverse (i_add => '+', i_subtract => '-');
26 $integer{$_} = 0 foreach qw(* / %);
28 sub TIESCALAR { my $x; bless \$x }
29 sub FETCH { ${$_[0]} }
30 sub STORE { ${$_[0]} = $_[1] }
33 my ($tie, $int, $op_seq, $warn, $todo) = @_;
35 $code .= "use integer;" if $int;
37 $code .= "tie \$x, 'main';\n" if $tie;
38 $code .= "$op_seq;\n}\n";
41 is($@, '', "Can eval code for $op_seq");
43 $::TODO = "[perl #17809] pp_$todo" if $todo;
45 warning_like($sub, qr/^Use of uninitialized value/,
46 "$op_seq$tie$int warns");
48 warning_is($sub, undef, "$op_seq$tie$int does not warn");
52 # go through all tests once normally and once with tied $x
53 for my $tie ("", ", tied") {
54 foreach my $integer ('', ', int') {
55 test_op($tie, $integer, $_, 0) foreach qw($x++ $x-- ++$x --$x);
58 foreach (keys %should_warn, keys %should_not) {
59 test_op($tie, '', "\$x $_= 1", $should_warn{$_}, $tie && $todo_as_tie{$_});
60 next unless exists $integer{$_};
61 test_op($tie, ', int', "\$x $_= 1", $should_warn{$_}, $tie && $integer{$_});
65 test_op($tie, '', "\$x $_= 'x'", $should_warn{$_}, $tie && $todo_as_tie{$_});