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(+ - . | ^ && ||);
23 $integer{$_} = 0 foreach qw(* / % + -);
25 sub TIESCALAR { my $x; bless \$x }
26 sub FETCH { ${$_[0]} }
27 sub STORE { ${$_[0]} = $_[1] }
30 my ($tie, $int, $op_seq, $warn) = @_;
32 $code .= "use integer;" if $int;
34 $code .= "tie \$x, 'main';\n" if $tie;
35 $code .= "$op_seq;\n}\n";
38 is($@, '', "Can eval code for $op_seq");
40 warning_like($sub, qr/^Use of uninitialized value/,
41 "$op_seq$tie$int warns");
43 warning_is($sub, undef, "$op_seq$tie$int does not warn");
47 # go through all tests once normally and once with tied $x
48 for my $tie ("", ", tied") {
49 foreach my $integer ('', ', int') {
50 test_op($tie, $integer, $_, 0) foreach qw($x++ $x-- ++$x --$x);
53 foreach (keys %should_warn, keys %should_not) {
54 test_op($tie, '', "\$x $_= 1", $should_warn{$_});
55 next unless exists $integer{$_};
56 test_op($tie, ', int', "\$x $_= 1", $should_warn{$_});
60 test_op($tie, '', "\$x $_= 'x'", $should_warn{$_});