diff --git a/MANIFEST b/MANIFEST index eeb734aa..7fb5d310 100644 --- a/MANIFEST +++ b/MANIFEST @@ -127,8 +127,10 @@ MANIFEST.SKIP META.yml README.pod t/compile.t +t/data/cat/cat-n-1.txt t/data/sort/ints1.txt t/data/sort/letters1.txt +t/cat.t t/echo.t t/factor.t t/false.t diff --git a/bin/cat b/bin/cat index 23b6b37a..e4174285 100644 --- a/bin/cat +++ b/bin/cat @@ -63,8 +63,8 @@ while (<>) { $was_empty = $is_empty; } - $_ = sprintf "%6d $_", ++ $count if $number_lines || - $number_non_blanks && /\S/; + $_ = sprintf "%6d %s", ++ $count, $_ if $number_lines || + $number_non_blanks && /\S/; $_ =~ s/$/\$/ if $ends; if ($nonprinting) { diff --git a/t/cat.t b/t/cat.t new file mode 100644 index 00000000..53fcdd85 --- /dev/null +++ b/t/cat.t @@ -0,0 +1,43 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 1; + +sub _lines2re +{ + return join( qq#\r?\n#, @_ ) . qq#\r?\n?#; +} + +sub test_cat +{ + local $Test::Builder::Level = $Test::Builder::Level + 1; + my ($args) = @_; + + my $re = _lines2re( @{ $args->{lines} } ); + return like( + scalar(`$^X -Ilib bin/cat @{$args->{flags}} @{$args->{files}}`), + qr#\A$re\z#ms, $args->{blurb} ); +} + +# TEST +test_cat( + { + blurb => "format string expansion in cat -n", + files => [qw( t/data/cat/cat-n-1.txt )], + flags => [qw( -n )], + lines => [" 1 %d"], + } +); + +__END__ + +=head1 COPYRIGHT & LICENSE + +Copyright 2018 by Shlomi Fish + +This code is licensed under the Artistic License 2.0 +L, or at your option any later +version of the Artistic License from TPF ( L ) +. diff --git a/t/data/cat/cat-n-1.txt b/t/data/cat/cat-n-1.txt new file mode 100644 index 00000000..98cb9782 --- /dev/null +++ b/t/data/cat/cat-n-1.txt @@ -0,0 +1 @@ +%d