Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bin/cat
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
43 changes: 43 additions & 0 deletions t/cat.t
Original file line number Diff line number Diff line change
@@ -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<https://opensource.org/licenses/Artistic-2.0>, or at your option any later
version of the Artistic License from TPF ( L<https://www.perlfoundation.org/> )
.
1 change: 1 addition & 0 deletions t/data/cat/cat-n-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%d