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 / sprintf.t
index 8e1ef69..4d54d2c 100755 (executable)
@@ -2,7 +2,37 @@
 
 # $RCSfile: sprintf.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:27 $
 
-print "1..1\n";
+BEGIN {
+    chdir 't' if -d 't';
+    unshift @INC, '../lib';
+}   
+use warnings;
 
-$x = sprintf("%3s %-4s%%foo %5d%c%3.1f","hi",123,456,65,3.0999);
-if ($x eq ' hi 123 %foo   456A3.1') {print "ok 1\n";} else {print "not ok 1 '$x'\n";}
+print "1..4\n";
+
+$SIG{__WARN__} = sub {
+    if ($_[0] =~ /^Invalid conversion/) {
+       $w++;
+    } else {
+       warn @_;
+    }
+};
+
+$w = 0;
+$x = sprintf("%3s %-4s%%foo %.0d%5d %#x%c%3.1f %b %x %X %#b %#x %#X","hi",123,0,456,0,ord('A'),3.0999,11,171,171,11,171,171);
+if ($x eq ' hi 123 %foo   456 0A3.1 1011 ab AB 0b1011 0xab 0XAB' && $w == 0) {
+    print "ok 1\n";
+} else {
+    print "not ok 1 '$x'\n";
+}
+
+for $i (2 .. 4) {
+    $f = ('%6 .6s', '%6. 6s', '%6.6 s')[$i - 2];
+    $w = 0;
+    $x = sprintf($f, '');
+    if ($x eq $f && $w == 1) {
+       print "ok $i\n";
+    } else {
+       print "not ok $i '$x' '$f' '$w'\n";
+    }
+}