1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
package t::App::PRT::Command::ListFiles;
use t::test;
use Capture::Tiny 'capture';
use File::pushd;
sub _require : Test(startup => 2) {
my ($self) = @_;
use_ok 'App::PRT::Command::ListFiles';
use_ok 'App::PRT::CLI';
# ListFiles can only be meaningfully tested through the CLI,
# since all it does is report values the CLI provides.
}
sub instantiate : Tests {
isa_ok App::PRT::Command::ListFiles->new, 'App::PRT::Command::ListFiles';
}
sub execute_NL : Tests { # Output ending with \n
my $directory = t::test::prepare_test_code('list_files');
my ($stdout, $stderr, @result);
do { # Modified from script/prt
my $guard = pushd($directory);
my $cli = App::PRT::CLI->new;
$cli->set_io(*STDIN, *STDOUT);
$cli->parse(qw(list_files));
($stdout, $stderr, @result) = capture { $cli->run; };
};
ok !$stderr, 'No error output from list_files';
like $stdout, qr/\n/, 'Output contains a newline';
unlike $stdout, qr/\0/, 'Output contains no nulls';
my @result_lines = sort split("\n", $stdout);
cmp_ok @result_lines, '==', 2, 'Found the right number of files';
my $expected = file($directory, qw(bin amazing.pl));
like $result_lines[0], qr/\Q$expected\E$/, 'First result matches';
$expected = file($directory, qw(lib My Class.pm));
like $result_lines[1], qr/\Q$expected\E$/, 'Second result matches';
}
sub execute_0 : Tests { # Output ending with \0
my $directory = t::test::prepare_test_code('list_files');
my ($stdout, $stderr, @result);
do { # Modified from script/prt
my $guard = pushd($directory);
my $cli = App::PRT::CLI->new;
$cli->set_io(*STDIN, *STDOUT);
$cli->parse(qw(list_files -0));
($stdout, $stderr, @result) = capture { $cli->run; };
};
ok !$stderr, 'No error output from list_files';
unlike $stdout, qr/\n/, 'Output contains no newlines';
like $stdout, qr/\0/, 'Output contains a null';
my @result_lines = sort split("\0", $stdout);
cmp_ok @result_lines, '==', 2, 'Found the right number of files';
my $expected = file($directory, qw(bin amazing.pl));
like $result_lines[0], qr/\Q$expected\E$/, 'First result matches';
$expected = file($directory, qw(lib My Class.pm));
like $result_lines[1], qr/\Q$expected\E$/, 'Second result matches';
}
|