This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
RT #94988 - Support for %u in diagnostics.pm's printf()-format parser
authorMatthew Horsfall (alh) <wolfsage@gmail.com>
Mon, 1 Aug 2011 02:42:22 +0000 (22:42 -0400)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 2 Aug 2011 21:32:10 +0000 (14:32 -0700)
lib/diagnostics.pm
lib/diagnostics.t

index f2d5429..60c96ea 100644 (file)
@@ -410,22 +410,22 @@ my %msg;
        # Since we strip "\.\n" when we search a warning, strip it here as well
        $header =~ s/\.?$//;
 
-        my @toks = split( /(%l?[dx]|%c|%(?:\.\d+)?[fs])/, $header );
+        my @toks = split( /(%l?[dx]|%u|%c|%(?:\.\d+)?[fs])/, $header );
        if (@toks > 1) {
             my $conlen = 0;
             for my $i (0..$#toks){
                 if( $i % 2 ){
                     if(      $toks[$i] eq '%c' ){
                         $toks[$i] = '.';
-                    } elsif( $toks[$i] eq '%d' ){
+                    } elsif( $toks[$i] =~ /^%(?:d|u)$/ ){
                         $toks[$i] = '\d+';
                     } elsif( $toks[$i] =~ '^%(?:s|.*f)$' ){
                         $toks[$i] = $i == $#toks ? '.*' : '.*?';
                     } elsif( $toks[$i] =~ '%.(\d+)s' ){
                         $toks[$i] = ".{$1}";
-                     } elsif( $toks[$i] =~ '^%l*x$' ){
+                    } elsif( $toks[$i] =~ '^%l*x$' ){
                         $toks[$i] = '[\da-f]+';
-                   }
+                    }
                 } elsif( length( $toks[$i] ) ){
                     $toks[$i] = quotemeta $toks[$i];
                     $conlen += length( $toks[$i] );
index b5db34d..31a5802 100644 (file)
@@ -5,7 +5,7 @@ BEGIN {
     @INC = 'lib';
 }
 
-use Test::More tests => 8;
+use Test::More tests => 9;
 
 BEGIN {
     my $w;
@@ -54,3 +54,10 @@ seek STDERR, 0,0;
 $warning = '';
 warn "Execution of -e aborted due to compilation errors.\n";
 like $warning, qr/The final summary message/, 'Periods at end of line';
+
+
+# Test for %d/%u
+seek STDERR, 0,0;
+$warning = '';
+warn "Bad arg length for us, is 4, should be 42";
+like $warning, qr/In C parlance/, '%u works';