Test !0 and !1 immutability and singletonness
authorFather Chrysostomos <sprout@cpan.org>
Sun, 16 Jun 2013 02:42:35 +0000 (19:42 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 26 Jul 2013 06:47:58 +0000 (23:47 -0700)
The latter (for bug #114838) is a to-do test under ithreads.

t/op/not.t

index 8df5774..e82f627 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan tests => 19;
+plan tests => 23;
 
 # not() tests
 pass("logical negation of empty list") if not();
@@ -76,3 +76,18 @@ SKIP:
     my $c = Scalar::Util::dualvar(0,"1");
     is not($c), "", 'not(dualvar) ignores false int when string is true';
 }
+
+# not’s return value should be read-only, as it is the same global scalar
+# each time (and test that it is, too).
+*yes = \not 0;
+*no  = \not 1;
+for (!0) { eval { $_ = 43 } }
+like $@, qr/^Modification of a read-only value attempted at /,
+   'not 0 is read-only';
+for (!1) { eval { $_ = 43 } }
+like $@, qr/^Modification of a read-only value attempted at /,
+   'not 1 is read-only';
+require Config;
+$::TODO = 'not fixed yet' if $Config::Config{useithreads};;
+is \!0, \$yes, '!0 returns the same value each time [perl #114838]';
+is \!1, \$no,  '!1 returns the same value each time [perl #114838]';