summaryrefslogtreecommitdiff
path: root/t/op/sprintf2.t
diff options
context:
space:
mode:
authorDave Mitchell <davem@fdisolutions.com>2005-12-01 16:40:29 +0000
committerDave Mitchell <davem@fdisolutions.com>2005-12-01 16:40:29 +0000
commit863811b26c8593d84b9f78cd2addb031ca7b315e (patch)
treee22b3225d9a04ffd8a57ca33e5933f4d6a667f07 /t/op/sprintf2.t
parente271e56d5700d8b78a1a9d5ecb4471f81deffa6c (diff)
downloadperl-863811b26c8593d84b9f78cd2addb031ca7b315e.tar.gz
sprintf %NNN$ check for large values wrapping to negative
p4raw-id: //depot/perl@26240
Diffstat (limited to 't/op/sprintf2.t')
-rw-r--r--t/op/sprintf2.t24
1 files changed, 22 insertions, 2 deletions
diff --git a/t/op/sprintf2.t b/t/op/sprintf2.t
index 079df9314b..d668e60fbf 100644
--- a/t/op/sprintf2.t
+++ b/t/op/sprintf2.t
@@ -6,7 +6,7 @@ BEGIN {
require './test.pl';
}
-plan tests => 4;
+plan tests => 7;
is(
sprintf("%.40g ",0.01),
@@ -33,4 +33,24 @@ fresh_perl_is(
'Modification of a read-only value attempted at - line 1.',
{ switches => [ '-w' ] },
q(%n should not be able to modify read-only constants),
-)
+);
+
+# check %NNN$ for range bounds, especially negative 2's complement
+
+{
+ my ($warn, $bad) = (0,0);
+ local $SIG{__WARN__} = sub {
+ if ($_[0] =~ /uninitialized/) {
+ $warn++
+ }
+ else {
+ $bad++
+ }
+ };
+ my $result = sprintf join('', map("%$_\$s%" . ~$_ . '$s', 1..20)),
+ qw(a b c d);
+ is($result, "abcd", "only four valid values");
+ is($warn, 36, "expected warnings");
+ is($bad, 0, "unexpected warnings");
+}
+