Fix [RT#66098] -- stricter checking on SvIVX exposed a lack of SvIOK check
[p5sagit/p5-mst-13.2.git] / t / op / sprintf2.t
index c92ab89..2e225c8 100644 (file)
@@ -6,7 +6,10 @@ BEGIN {
     require './test.pl';
 }   
 
-plan tests => 1292;
+plan tests => 1319;
+
+use strict;
+use Config;
 
 is(
     sprintf("%.40g ",0.01),
@@ -134,3 +137,31 @@ for my $num (0, -1, 1) {
     }
 }
 
+# test that %f doesn't panic with +Inf, -Inf, NaN [perl #45383]
+foreach my $n (2**1e100, -2**1e100, 2**1e100/2**1e100) { # +Inf, -Inf, NaN
+    eval { my $f = sprintf("%f", $n); };
+    is $@, "", "sprintf(\"%f\", $n)";
+}
+
+# test %ll formats with and without HAS_QUAD
+eval { my $q = pack "q", 0 };
+my $Q = $@ eq '';
+
+my @tests = (
+  [ '%lld' => [qw( 4294967296 -100000000000000 )] ],
+  [ '%lli' => [qw( 4294967296 -100000000000000 )] ],
+  [ '%llu' => [qw( 4294967296  100000000000000 )] ],
+  [ '%Ld'  => [qw( 4294967296 -100000000000000 )] ],
+  [ '%Li'  => [qw( 4294967296 -100000000000000 )] ],
+  [ '%Lu'  => [qw( 4294967296  100000000000000 )] ],
+);
+
+for my $t (@tests) {
+  my($fmt, $nums) = @$t;
+  for my $num (@$nums) {
+    my $w; local $SIG{__WARN__} = sub { $w = shift };
+    is(sprintf($fmt, $num), $Q ? $num : $fmt, "quad: $fmt -> $num");
+    like($w, $Q ? '' : qr/Invalid conversion in sprintf: "$fmt"/, "warning: $fmt");
+  }
+}
+