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
1 #!./perl
2
3 # $RCSfile: sprintf.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:27 $
4
5 BEGIN {
6     chdir 't' if -d 't';
7     unshift @INC, '../lib';
8 }   
9 use warnings;
10
11 print "1..4\n";
12
13 $SIG{__WARN__} = sub {
14     if ($_[0] =~ /^Invalid conversion/) {
15         $w++;
16     } else {
17         warn @_;
18     }
19 };
20
21 $w = 0;
22 $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);
23 if ($x eq ' hi 123 %foo   456 0A3.1 1011 ab AB 0b1011 0xab 0XAB' && $w == 0) {
24     print "ok 1\n";
25 } else {
26     print "not ok 1 '$x'\n";
27 }
28
29 for $i (2 .. 4) {
30     $f = ('%6 .6s', '%6. 6s', '%6.6 s')[$i - 2];
31     $w = 0;
32     $x = sprintf($f, '');
33     if ($x eq $f && $w == 1) {
34         print "ok $i\n";
35     } else {
36         print "not ok $i '$x' '$f' '$w'\n";
37     }
38 }