This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
allow Configure -S to run non-interactively (spotted by Greg Hudson
[perl5.git] / t / op / assignwarn.t
index e69de29..b95cec5 100755 (executable)
@@ -0,0 +1,61 @@
+#!./perl
+
+#
+# Verify which OP= operators warn if their targets are undefined.
+# Based on redef.t, contributed by Graham Barr <Graham.Barr@tiuk.ti.com>
+#      -- Robin Barker <rmb@cise.npl.co.uk>
+#
+
+BEGIN {
+    chdir 't' if -d 't';
+    unshift @INC, '../lib';
+}
+
+use strict;
+use warnings;
+
+my $warn = "";
+$SIG{q(__WARN__)} = sub { print $warn; $warn .= join("",@_) };
+
+sub ok { print $_[1] ? "ok " : "not ok ", $_[0], "\n"; }
+
+sub uninitialized { $warn =~ s/Use of uninitialized value[^\n]+\n//s; }
+    
+print "1..23\n";
+
+{ my $x; $x ++;     ok  1, ! uninitialized; }
+{ my $x; $x --;     ok  2, ! uninitialized; }
+{ my $x; ++ $x;     ok  3, ! uninitialized; }
+{ my $x; -- $x;            ok  4, ! uninitialized; }
+
+{ my $x; $x **= 1;  ok  5,  uninitialized; }
+
+{ my $x; $x += 1;   ok  6, ! uninitialized; }
+{ my $x; $x -= 1;   ok  7, ! uninitialized; }
+
+{ my $x; $x .= 1;   ok  8, ! uninitialized; }
+
+{ my $x; $x *= 1;   ok  9,  uninitialized; }
+{ my $x; $x /= 1;   ok 10,  uninitialized; }
+{ my $x; $x %= 1;   ok 11,  uninitialized; }
+
+{ my $x; $x x= 1;   ok 12,  uninitialized; }
+
+{ my $x; $x &= 1;   ok 13,  uninitialized; }
+{ my $x; $x |= 1;   ok 14, ! uninitialized; }
+{ my $x; $x ^= 1;   ok 15, ! uninitialized; }
+
+{ my $x; $x &&= 1;  ok 16, ! uninitialized; }
+{ my $x; $x ||= 1;  ok 17, ! uninitialized; }
+
+{ my $x; $x <<= 1;  ok 18,  uninitialized; }
+{ my $x; $x >>= 1;  ok 19,  uninitialized; }
+
+{ my $x; $x &= "x"; ok 20,  uninitialized; }
+{ my $x; $x |= "x"; ok 21, ! uninitialized; }
+{ my $x; $x ^= "x"; ok 22, ! uninitialized; }
+
+ok 23, $warn eq '';
+
+# If we got any errors that we were not expecting, then print them
+print map "#$_\n", split /\n/, $warn if length $warn;